feat(api): public good detail family block behind gray-release flag

This commit is contained in:
yeuimu
2026-08-28 13:40:19 +08:00
parent b4b9fbbe60
commit 6418aa7302
9 changed files with 324 additions and 6 deletions
+46
View File
@@ -32,6 +32,16 @@ const PUBLIC_GOOD_INCLUDE = {
include: {
detail: true,
variants: { orderBy: [{ sortOrder: 'asc' as const }, { id: 'asc' as const }] },
family: {
select: {
id: true,
familyCode: true,
familyName: true,
sizeChart: true,
packageSpecs: true,
priceMatrix: true,
},
},
},
},
mergedOriginGoods: {
@@ -402,6 +412,42 @@ export class PublicService {
sortOrder: variant.sortOrder,
})),
detailSyncedAt: detail?.syncedAt.toISOString() ?? null,
...this.familyBlock(good),
};
}
/**
* 灰度族块(设计 D4:零新增公开端点):仅当 PUBLIC_DETAIL_FROM_FAMILY=true
* 且主链接有所属族时输出;数据全部来自 ProductFamily 的物化 JSON,无额外查询。
*/
private familyBlock(
good: PublicGoodRow,
): Pick<PublicGoodDetailDto, 'family'> | Record<string, never> {
if (process.env.PUBLIC_DETAIL_FROM_FAMILY !== 'true') return {};
const family = good.originGood.family;
if (!family || !family.priceMatrix) return {};
const matrix = family.priceMatrix as {
sizes: Array<{ key: string; name: string | null }>;
colors: Array<{ key: string; name: string | null; hex: string | null; imageUrl: string | null }>;
crafts: string[];
logistics: string[];
rows: Array<{ price: string }>;
};
const prices = matrix.rows.map((r) => Number(r.price)).filter((n) => Number.isFinite(n));
return {
family: {
familyId: family.id.toString(),
familyCode: family.familyCode,
familyName: family.familyName,
sizes: matrix.sizes,
colors: matrix.colors,
crafts: matrix.crafts,
logistics: matrix.logistics,
sizeChart: (family.sizeChart as Record<string, unknown> | null) ?? null,
packageSpecs: (family.packageSpecs as Record<string, unknown> | null) ?? null,
priceMatrix: matrix as unknown as Record<string, unknown>,
minPrice: prices.length ? String(Math.min(...prices)) : null,
},
};
}