This commit is contained in:
2026-09-30 09:53:05 +03:30
parent 5a2c4cabfd
commit 38cabb0957
19 changed files with 397 additions and 72 deletions
+60
View File
@@ -5,6 +5,27 @@ import { PrismaService } from '../prisma/prisma.service';
export class StockNotifyService {
constructor(private readonly prisma: PrismaService) {}
async listForCustomer(customerId: string) {
const rows = await this.prisma.stockNotifyRequest.findMany({
where: { customerId },
orderBy: { createdAt: 'desc' },
include: {
product: {
select: {
id: true,
name: true,
code: true,
color: true,
stock: true,
imageUrlsJson: true,
catalog: { select: { code: true } },
},
},
},
});
return rows.map((r) => this.mapCustomer(r));
}
async listAdmin(activeOnly = true) {
const rows = await this.prisma.stockNotifyRequest.findMany({
where: activeOnly ? { active: true } : undefined,
@@ -68,6 +89,45 @@ export class StockNotifyService {
return this.map(row);
}
private productThumb(imageUrlsJson: unknown): string {
if (!Array.isArray(imageUrlsJson)) return '';
const url = imageUrlsJson.find(
(item): item is string => typeof item === 'string' && item.trim().length > 0,
);
return url?.trim() ?? '';
}
private mapCustomer(r: {
id: string;
productId: string;
active: boolean;
createdAt: Date;
notifiedAt: Date | null;
product: {
id: string;
name: string;
code: string;
color: string;
stock: number | null;
imageUrlsJson: unknown;
catalog: { code: string };
};
}) {
return {
id: r.id,
productId: r.productId,
productName: r.product.name,
productCode: r.product.code,
catalogCode: r.product.catalog.code,
color: r.product.color,
stock: r.product.stock,
imageUrl: this.productThumb(r.product.imageUrlsJson),
active: r.active,
createdAt: r.createdAt.toISOString(),
notifiedAt: r.notifiedAt?.toISOString() ?? null,
};
}
private map(r: {
id: string;
customerId: string;