feat: initial commit

This commit is contained in:
s.esmaeili
2026-09-09 06:46:27 +03:30
commit 0ed6bed028
214 changed files with 20177 additions and 0 deletions
@@ -0,0 +1,12 @@
import { Controller, Get, Query } from '@nestjs/common';
import { PricingService } from './pricing.service';
@Controller('pricing')
export class PricingController {
constructor(private readonly pricing: PricingService) {}
@Get('latest')
getLatest(@Query('karatPerMille') karatPerMille: string) {
return this.pricing.getLatestQuote(Number(karatPerMille) || 750);
}
}
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { PricingService } from './pricing.service';
import { PricingController } from './pricing.controller';
@Module({
controllers: [PricingController],
providers: [PricingService],
exports: [PricingService],
})
export class PricingModule {}
@@ -0,0 +1,23 @@
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;
}
}