49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
|
import { faker } from '@faker-js/faker';
|
||
|
import { verifyAccessToken } from '~/utils/jwt-utils';
|
||
|
import { unAuthorizedResponse } from '~/utils/response';
|
||
|
|
||
|
function generateMockDataList(count: number) {
|
||
|
const dataList = [];
|
||
|
|
||
|
for (let i = 0; i < count; i++) {
|
||
|
const dataItem = {
|
||
|
id: faker.string.uuid(),
|
||
|
imageUrl: faker.image.avatar(),
|
||
|
imageUrl2: faker.image.avatar(),
|
||
|
open: faker.datatype.boolean(),
|
||
|
status: faker.helpers.arrayElement(['success', 'error', 'warning']),
|
||
|
productName: faker.commerce.productName(),
|
||
|
price: faker.commerce.price(),
|
||
|
currency: faker.finance.currencyCode(),
|
||
|
quantity: faker.number.int({ min: 1, max: 100 }),
|
||
|
available: faker.datatype.boolean(),
|
||
|
category: faker.commerce.department(),
|
||
|
releaseDate: faker.date.past(),
|
||
|
rating: faker.number.float({ min: 1, max: 5 }),
|
||
|
description: faker.commerce.productDescription(),
|
||
|
weight: faker.number.float({ min: 0.1, max: 10 }),
|
||
|
color: faker.color.human(),
|
||
|
inProduction: faker.datatype.boolean(),
|
||
|
tags: Array.from({ length: 3 }, () => faker.commerce.productAdjective()),
|
||
|
};
|
||
|
|
||
|
dataList.push(dataItem);
|
||
|
}
|
||
|
|
||
|
return dataList;
|
||
|
}
|
||
|
|
||
|
const mockData = generateMockDataList(100);
|
||
|
|
||
|
export default eventHandler(async (event) => {
|
||
|
const userinfo = verifyAccessToken(event);
|
||
|
if (!userinfo) {
|
||
|
return unAuthorizedResponse(event);
|
||
|
}
|
||
|
|
||
|
await sleep(600);
|
||
|
|
||
|
const { page, pageSize } = getQuery(event);
|
||
|
return usePageResponseSuccess(page as string, pageSize as string, mockData);
|
||
|
});
|