feat: 标准化响应体
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const listDeploymentsQuerySchema = z.object({
|
||||
page: z.coerce.number().int().min(1).optional().default(1),
|
||||
pageSize: z.coerce.number().int().min(1).max(100).optional().default(10),
|
||||
page: z.coerce.number().int().min(1).optional(),
|
||||
pageSize: z.coerce.number().int().min(1).max(100).optional(),
|
||||
projectId: z.coerce.number().int().positive().optional(),
|
||||
});
|
||||
|
||||
|
||||
@@ -20,22 +20,28 @@ export class DeploymentController {
|
||||
where.projectId = projectId;
|
||||
}
|
||||
|
||||
const isPagination = page !== undefined && pageSize !== undefined;
|
||||
|
||||
const result = await prisma.deployment.findMany({
|
||||
where,
|
||||
take: pageSize,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: isPagination ? pageSize : undefined,
|
||||
skip: isPagination ? (page! - 1) * pageSize! : 0,
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
});
|
||||
const total = await prisma.deployment.count({ where });
|
||||
|
||||
return {
|
||||
data: result,
|
||||
page,
|
||||
pageSize,
|
||||
total,
|
||||
};
|
||||
if (isPagination) {
|
||||
return {
|
||||
list: result,
|
||||
page,
|
||||
pageSize,
|
||||
total,
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Post('')
|
||||
|
||||
Reference in New Issue
Block a user