feat(product-family): replace legacy good merge with family mechanism in config view and public detail
This commit is contained in:
@@ -13,6 +13,7 @@ export interface GoodRelations {
|
||||
goodName: string | null;
|
||||
goodImage: string | null;
|
||||
goodPrice: unknown;
|
||||
family?: { id: bigint; familyCode: string | null; familyName: string } | null;
|
||||
detail?: {
|
||||
productCode: string | null;
|
||||
syncedAt: Date;
|
||||
@@ -127,6 +128,7 @@ export class GoodDto {
|
||||
sizeRowCount: number;
|
||||
packageRowCount: number;
|
||||
productCode: string | null;
|
||||
family?: { familyId: string; familyCode: string | null; familyName: string } | null;
|
||||
} | null;
|
||||
|
||||
static from(
|
||||
@@ -215,6 +217,13 @@ export class GoodDto {
|
||||
sizeRowCount: GoodDto.jsonRows(rel.originGood.detail?.sizeChart),
|
||||
packageRowCount: GoodDto.jsonRows(rel.originGood.detail?.packageSpecs),
|
||||
productCode: rel.originGood.detail?.productCode ?? null,
|
||||
family: rel.originGood.family
|
||||
? {
|
||||
familyId: rel.originGood.family.id.toString(),
|
||||
familyCode: rel.originGood.family.familyCode,
|
||||
familyName: rel.originGood.family.familyName,
|
||||
}
|
||||
: null,
|
||||
}
|
||||
: null,
|
||||
};
|
||||
|
||||
@@ -61,4 +61,15 @@ export class UpdateGoodDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
goodImage?: string | null;
|
||||
|
||||
@ApiProperty({
|
||||
required: false,
|
||||
nullable: true,
|
||||
type: Number,
|
||||
description: '所属产品族 id(null = 脱离族)',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
familyId?: number | null;
|
||||
}
|
||||
@@ -31,6 +31,7 @@ const GOOD_INCLUDE = {
|
||||
detail: true,
|
||||
variants: { orderBy: [{ sortOrder: 'asc' }, { id: 'asc' }] },
|
||||
_count: { select: { variants: true } },
|
||||
family: { select: { id: true, familyCode: true, familyName: true, stale: true } },
|
||||
},
|
||||
},
|
||||
goodTags: { include: { tag: true } },
|
||||
@@ -334,6 +335,18 @@ export class GoodsService {
|
||||
}
|
||||
if (dto.goodPriority !== undefined) data.goodPriority = dto.goodPriority;
|
||||
if (dto.goodImage !== undefined) data.goodImage = dto.goodImage;
|
||||
if (dto.familyId !== undefined) {
|
||||
if (dto.familyId !== null) {
|
||||
const family = await this.prisma.productFamily.findUnique({
|
||||
where: { id: BigInt(dto.familyId) },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!family) throw new NotFoundException(`product family ${dto.familyId} not found`);
|
||||
data.family = { connect: { id: family.id } };
|
||||
} else {
|
||||
data.family = { disconnect: true };
|
||||
}
|
||||
}
|
||||
if (dto.tagIds !== undefined) {
|
||||
for (const tagId of dto.tagIds) {
|
||||
await this.ensureTag(tagId);
|
||||
|
||||
Reference in New Issue
Block a user