Files
hedena_gold/apps/api/src/modules/pricing/pricing.service.ts
T
2026-09-09 06:46:27 +03:30

24 lines
800 B
TypeScript

import { Injectable, NotFoundException } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { PrismaService } from '../../prisma/prisma.service';
@Injectable()
export class PricingService {
constructor(private readonly prisma: PrismaService) {}
async recordQuote(karatPerMille: number, pricePerGramRial: Prisma.Decimal.Value, source: string) {
return this.prisma.goldPriceQuote.create({
data: { karatPerMille, pricePerGramRial, source },
});
}
async getLatestQuote(karatPerMille: number) {
const quote = await this.prisma.goldPriceQuote.findFirst({
where: { karatPerMille },
orderBy: { quotedAt: 'desc' },
});
if (!quote) throw new NotFoundException(`No gold price quote recorded for ${karatPerMille}‰`);
return quote;
}
}