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,27 @@
import { Controller, Get, Param } from '@nestjs/common';
import { CustomersService } from './customers.service';
@Controller('customers')
export class CustomersController {
constructor(private readonly customers: CustomersService) {}
@Get()
list() {
return this.customers.list();
}
@Get(':id')
get(@Param('id') id: string) {
return this.customers.getOrThrow(id);
}
@Get(':id/orders')
getOrders(@Param('id') id: string) {
return this.customers.getOrders(id);
}
@Get(':id/ledger-entries')
getLedgerEntries(@Param('id') id: string) {
return this.customers.getLedgerEntries(id);
}
}
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { CustomersService } from './customers.service';
import { CustomersController } from './customers.controller';
@Module({
controllers: [CustomersController],
providers: [CustomersService],
exports: [CustomersService],
})
export class CustomersModule {}
@@ -0,0 +1,59 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { PrismaService } from '../../prisma/prisma.service';
// passwordHash must never leave the API — every customer read goes through this.
const PUBLIC_CUSTOMER_SELECT = {
id: true,
fullName: true,
mobile: true,
nationalCode: true,
cityId: true,
referredByAgentId: true,
goldCreditLimitGrams: true,
goldDebtGrams: true,
fiatDebtRial: true,
verificationStep: true,
nationalIdImageUrl: true,
businessLicenseUrl: true,
shopImageUrl: true,
isActive: true,
createdAt: true,
updatedAt: true,
} satisfies Prisma.CustomerSelect;
@Injectable()
export class CustomersService {
constructor(private readonly prisma: PrismaService) {}
async getOrThrow(customerId: string) {
const customer = await this.prisma.customer.findUnique({
where: { id: customerId },
select: PUBLIC_CUSTOMER_SELECT,
});
if (!customer) throw new NotFoundException(`Customer ${customerId} not found`);
return customer;
}
list() {
return this.prisma.customer.findMany({
select: PUBLIC_CUSTOMER_SELECT,
orderBy: { createdAt: 'desc' },
});
}
getOrders(customerId: string) {
return this.prisma.order.findMany({
where: { customerId },
include: { items: true },
orderBy: { createdAt: 'desc' },
});
}
getLedgerEntries(customerId: string) {
return this.prisma.ledgerEntry.findMany({
where: { customerId },
orderBy: { createdAt: 'desc' },
});
}
}