All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m15s
- 将逻辑转移到Server端后,简化前端逻辑
28 lines
661 B
TypeScript
28 lines
661 B
TypeScript
import { toDocumentListView } from '~~/server/mappers/documentMapper';
|
|
|
|
export const documentService = {
|
|
async getDocumentList(locale: string) {
|
|
const query = await loadAssetAsString(
|
|
'assets/server',
|
|
'graphql/documentList.graphql'
|
|
);
|
|
if (!query) {
|
|
throw createError({
|
|
statusCode: 500,
|
|
message: 'GraphQL query not found',
|
|
});
|
|
}
|
|
|
|
const data = await directus.query<{ product_documents: ProductDocument[] }>(
|
|
query,
|
|
{
|
|
locale: locale,
|
|
}
|
|
);
|
|
|
|
const documents = data?.product_documents || [];
|
|
|
|
return documents.map((document) => toDocumentListView(document));
|
|
},
|
|
};
|