fix(store): persist package imageUrls on audit approve
Ensure multi-image packages are written on approval and always returned as arrays from store detail. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -69,7 +69,7 @@ export class StorePackageService {
|
||||
usableTime,
|
||||
otherNotes,
|
||||
imageUrl: imageUrls[0] ?? null,
|
||||
imageUrls: imageUrls.length ? imageUrls : null,
|
||||
imageUrls,
|
||||
sortOrder: Number.isFinite(sortOrder) ? sortOrder : index,
|
||||
};
|
||||
}
|
||||
@@ -97,7 +97,7 @@ export class StorePackageService {
|
||||
usableTime: row.usableTime,
|
||||
otherNotes: row.otherNotes,
|
||||
imageUrl: imageUrls[0] ?? null,
|
||||
imageUrls: imageUrls.length ? imageUrls : null,
|
||||
imageUrls,
|
||||
sortOrder: row.sortOrder,
|
||||
};
|
||||
}
|
||||
@@ -229,6 +229,19 @@ export class StorePackageService {
|
||||
return serializeBigInt({ live });
|
||||
}
|
||||
|
||||
private packageImageWrite(pkg: {
|
||||
imageUrl?: string | null;
|
||||
imageUrls?: string[] | null;
|
||||
}) {
|
||||
const imageUrls = normalizeStorePackageImageUrls(pkg);
|
||||
return {
|
||||
imageUrl: imageUrls[0] ?? null,
|
||||
imageUrls: imageUrls.length
|
||||
? (imageUrls as Prisma.InputJsonValue)
|
||||
: Prisma.JsonNull,
|
||||
};
|
||||
}
|
||||
|
||||
private async replaceLivePackages(storeId: bigint, packages: StorePackageItemDto[]) {
|
||||
await this.prisma.$transaction([
|
||||
this.prisma.storePackage.deleteMany({ where: { storeId } }),
|
||||
@@ -241,10 +254,7 @@ export class StorePackageService {
|
||||
dishes: pkg.dishes,
|
||||
usableTime: pkg.usableTime ?? null,
|
||||
otherNotes: pkg.otherNotes ?? null,
|
||||
imageUrl: pkg.imageUrl ?? null,
|
||||
imageUrls: pkg.imageUrls?.length
|
||||
? (pkg.imageUrls as Prisma.InputJsonValue)
|
||||
: Prisma.JsonNull,
|
||||
...this.packageImageWrite(pkg),
|
||||
sortOrder: pkg.sortOrder ?? index,
|
||||
},
|
||||
}),
|
||||
@@ -336,7 +346,7 @@ export class StorePackageService {
|
||||
});
|
||||
return serializeBigInt({ id: updated.id.toString(), status: updated.status });
|
||||
}
|
||||
const packages = req.packagesJson as unknown as StorePackageItemDto[];
|
||||
const packages = this.normalizePackages(req.packagesJson);
|
||||
await this.prisma.$transaction(async (tx) => {
|
||||
await tx.storePackage.deleteMany({ where: { storeId: req.storeId } });
|
||||
for (let i = 0; i < packages.length; i++) {
|
||||
@@ -349,6 +359,7 @@ export class StorePackageService {
|
||||
dishes: pkg.dishes,
|
||||
usableTime: pkg.usableTime ?? null,
|
||||
otherNotes: pkg.otherNotes ?? null,
|
||||
...this.packageImageWrite(pkg),
|
||||
sortOrder: pkg.sortOrder ?? i,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -247,7 +247,8 @@ export class StoreService {
|
||||
usableTime: p.usableTime,
|
||||
otherNotes: p.otherNotes,
|
||||
imageUrl: imageUrls[0] ?? null,
|
||||
imageUrls: imageUrls.length ? imageUrls : null,
|
||||
/** C 端始终返回数组,便于多图轮播 */
|
||||
imageUrls,
|
||||
sortOrder: p.sortOrder,
|
||||
};
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user