fix: remove dead code, add ZodError handling, fix NaN pagination, add like routes, fix schemesCount sync
This commit is contained in:
@@ -19,7 +19,9 @@ router.get('/', optionalAuth, async (req: Request, res: Response) => {
|
||||
sort = 'newest',
|
||||
} = req.query;
|
||||
|
||||
const skip = (Number(page) - 1) * Number(limit);
|
||||
const pageNum = Math.max(1, parseInt(String(page)) || 1);
|
||||
const limitNum = Math.min(100, Math.max(1, parseInt(String(limit)) || 20));
|
||||
const skip = (pageNum - 1) * limitNum;
|
||||
|
||||
const where: any = { status: 'PUBLISHED' };
|
||||
if (weapon) where.weaponName = { contains: String(weapon) };
|
||||
@@ -219,6 +221,11 @@ router.delete('/:id', authMiddleware, async (req: Request, res: Response) => {
|
||||
data: { status: 'DELETED' },
|
||||
});
|
||||
|
||||
await prisma.user.update({
|
||||
where: { id: req.user!.userId },
|
||||
data: { schemesCount: { decrement: 1 } },
|
||||
});
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: '方案已删除',
|
||||
|
||||
Reference in New Issue
Block a user