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; } }