feat(admin): implement symptoms management in admin panel product form
This commit is contained in:
1 parent
717a61a225
commit
8345410376
2 files changed
+80
-12
No files matched your search
@@ -101,7 +101,7 @@ export class AdminService {
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.product.findMany({
|
||||
where, skip, take: limit, orderBy: { createdAt: 'desc' },
|
||||
include: { category: true }
|
||||
include: { category: true, symptoms: true }
|
||||
}),
|
||||
this.prisma.product.count({ where })
|
||||
]);
|
||||
@@ -114,7 +114,7 @@ export class AdminService {
|
||||
}
|
||||
|
||||
async createProduct(data: any) {
|
||||
return this.prisma.product.create({
|
||||
const product = await this.prisma.product.create({
|
||||
data: {
|
||||
artNo: data.artNo,
|
||||
nameFa: data.nameFa,
|
||||
@@ -138,10 +138,21 @@ export class AdminService {
|
||||
slug: data.slug || data.artNo,
|
||||
}
|
||||
});
|
||||
|
||||
if (data.symptoms && Array.isArray(data.symptoms)) {
|
||||
await this.prisma.productSymptom.createMany({
|
||||
data: data.symptoms.map((s: string) => ({
|
||||
productId: product.id,
|
||||
symptom: s.trim()
|
||||
})).filter((s: any) => s.symptom.length > 0)
|
||||
});
|
||||
}
|
||||
|
||||
return product;
|
||||
}
|
||||
|
||||
async updateProduct(id: string, data: any) {
|
||||
return this.prisma.product.update({
|
||||
const product = await this.prisma.product.update({
|
||||
where: { id },
|
||||
data: {
|
||||
artNo: data.artNo,
|
||||
@@ -166,6 +177,20 @@ export class AdminService {
|
||||
slug: data.slug || data.artNo,
|
||||
}
|
||||
});
|
||||
|
||||
if (data.symptoms !== undefined && Array.isArray(data.symptoms)) {
|
||||
await this.prisma.productSymptom.deleteMany({ where: { productId: id } });
|
||||
if (data.symptoms.length > 0) {
|
||||
await this.prisma.productSymptom.createMany({
|
||||
data: data.symptoms.map((s: string) => ({
|
||||
productId: id,
|
||||
symptom: s.trim()
|
||||
})).filter((s: any) => s.symptom.length > 0)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return product;
|
||||
}
|
||||
|
||||
async deleteProduct(id: string) {
|
||||
|
||||
Reference in new issue
Block a user