refactor: 产品页与产品列表的API重构
- 将产品页与产品列表的API由REST重构为GraphQL - 修改Mapper与单元测试
This commit is contained in:
@ -10,7 +10,9 @@ describe('toProductListView', () => {
|
||||
translations: [
|
||||
{ id: 10, name: 'Product Name', summary: 'Product Summary' },
|
||||
],
|
||||
cover: 'cover-file-uuid-1234',
|
||||
cover: {
|
||||
id: 'cover-file-uuid-1234',
|
||||
},
|
||||
product_type: {
|
||||
id: 1,
|
||||
translations: [{ id: 20, name: 'Type Name' }],
|
||||
@ -35,7 +37,9 @@ describe('toProductListView', () => {
|
||||
const rawData: Product = {
|
||||
id: 1,
|
||||
translations: [],
|
||||
cover: 'cover-file-uuid-1234',
|
||||
cover: {
|
||||
id: 'cover-file-uuid-1234',
|
||||
},
|
||||
product_type: {
|
||||
id: 20,
|
||||
translations: [],
|
||||
|
||||
@ -33,12 +33,14 @@ export function toProductListView(raw: Product): ProductListView {
|
||||
? toProductTypeView(raw.product_type)
|
||||
: undefined;
|
||||
|
||||
const cover = isObject<DirectusFile>(raw.cover) ? raw.cover.id : '';
|
||||
|
||||
return {
|
||||
id: raw.id,
|
||||
product_type: type,
|
||||
name: trans.name,
|
||||
summary: trans.summary,
|
||||
cover: raw.cover.toString(),
|
||||
cover: cover,
|
||||
};
|
||||
}
|
||||
|
||||
@ -110,9 +112,10 @@ export function toProductView(raw: Product): ProductView {
|
||||
.map((item) => item.product_images_id)
|
||||
.filter(isObject<ProductImage>)
|
||||
.map((item) => {
|
||||
const image = isObject<DirectusFile>(item.image) ? item.image.id : '';
|
||||
return {
|
||||
id: item.id,
|
||||
image: item.image.toString(),
|
||||
image: image,
|
||||
caption: item.translations?.[0]?.caption || '',
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user