From 4adcb42bb512742482fc40528eb737c71b57f0e6 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 20 Mar 2026 22:55:51 +0000 Subject: [PATCH] fix: resolve TypeScript type errors in route params --- backend/src/routes/category.routes.ts | 6 +++--- backend/src/routes/tenant.routes.ts | 6 +++--- backend/src/routes/user.routes.ts | 8 ++++---- backend/src/routes/workflow.routes.ts | 20 +++++++++++--------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/backend/src/routes/category.routes.ts b/backend/src/routes/category.routes.ts index dd5f4f4..657fb38 100644 --- a/backend/src/routes/category.routes.ts +++ b/backend/src/routes/category.routes.ts @@ -63,7 +63,7 @@ router.get('/', async (req: Request, res: Response, next: NextFunction) => { router.get('/:id', async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id } = req.params; + const id = req.params.id as string; const category = await prisma.category.findUnique({ where: { id }, @@ -138,7 +138,7 @@ router.post('/', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), asyn router.put('/:id', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id } = req.params; + const id = req.params.id as string; const parsed = updateCategorySchema.safeParse(req.body); if (!parsed.success) { @@ -182,7 +182,7 @@ router.put('/:id', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), as router.delete('/:id', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id } = req.params; + const id = req.params.id as string; const category = await prisma.category.findUnique({ where: { id }, diff --git a/backend/src/routes/tenant.routes.ts b/backend/src/routes/tenant.routes.ts index 86beb6b..106f862 100644 --- a/backend/src/routes/tenant.routes.ts +++ b/backend/src/routes/tenant.routes.ts @@ -54,7 +54,7 @@ router.get('/', async (req: Request, res: Response, next: NextFunction) => { router.get('/:id', async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id } = req.params; + const id = req.params.id as string; // Customer users can only view their own tenant if ((user.role === 'CUSTOMER_ADMIN' || user.role === 'CUSTOMER_USER') && id !== user.tenantId) { @@ -110,7 +110,7 @@ router.post('/', authorize('SYSTEM_ADMIN'), async (req: Request, res: Response, // PUT /api/tenants/:id (SYSTEM_ADMIN only) router.put('/:id', authorize('SYSTEM_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { - const { id } = req.params; + const id = req.params.id as string; const parsed = updateTenantSchema.safeParse(req.body); if (!parsed.success) { res.status(400).json({ error: 'Validation error', details: parsed.error.flatten().fieldErrors }); @@ -145,7 +145,7 @@ router.put('/:id', authorize('SYSTEM_ADMIN'), async (req: Request, res: Response // DELETE /api/tenants/:id (SYSTEM_ADMIN only) router.delete('/:id', authorize('SYSTEM_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { - const { id } = req.params; + const id = req.params.id as string; const tenant = await prisma.tenant.findUnique({ where: { id } }); if (!tenant) { diff --git a/backend/src/routes/user.routes.ts b/backend/src/routes/user.routes.ts index 4f7d85c..92a4225 100644 --- a/backend/src/routes/user.routes.ts +++ b/backend/src/routes/user.routes.ts @@ -82,7 +82,7 @@ router.get('/', async (req: Request, res: Response, next: NextFunction) => { router.get('/:id', async (req: Request, res: Response, next: NextFunction) => { try { const currentUser = req.user!; - const { id } = req.params; + const id = req.params.id as string; const targetUser = await prisma.user.findUnique({ where: { id }, @@ -191,7 +191,7 @@ router.post('/', authorize('SYSTEM_ADMIN', 'CUSTOMER_ADMIN'), async (req: Reques router.put('/:id', authorize('SYSTEM_ADMIN', 'CUSTOMER_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { const currentUser = req.user!; - const { id } = req.params; + const id = req.params.id as string; const parsed = updateUserSchema.safeParse(req.body); if (!parsed.success) { res.status(400).json({ error: 'Validation error', details: parsed.error.flatten().fieldErrors }); @@ -254,7 +254,7 @@ router.put('/:id', authorize('SYSTEM_ADMIN', 'CUSTOMER_ADMIN'), async (req: Requ router.delete('/:id', authorize('SYSTEM_ADMIN', 'CUSTOMER_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { const currentUser = req.user!; - const { id } = req.params; + const id = req.params.id as string; if (id === currentUser.id) { res.status(400).json({ error: 'Bad request', message: 'You cannot delete your own account' }); @@ -288,7 +288,7 @@ router.delete('/:id', authorize('SYSTEM_ADMIN', 'CUSTOMER_ADMIN'), async (req: R router.patch('/:id/password', async (req: Request, res: Response, next: NextFunction) => { try { const currentUser = req.user!; - const { id } = req.params; + const id = req.params.id as string; // Users can only change their own password (admins can reset via update) if (id !== currentUser.id && currentUser.role !== 'SYSTEM_ADMIN') { diff --git a/backend/src/routes/workflow.routes.ts b/backend/src/routes/workflow.routes.ts index 7d5db71..e4cd0d1 100644 --- a/backend/src/routes/workflow.routes.ts +++ b/backend/src/routes/workflow.routes.ts @@ -154,7 +154,7 @@ router.get('/', async (req: Request, res: Response, next: NextFunction) => { router.get('/:id', async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id } = req.params; + const id = req.params.id as string; const workflow = await prisma.workflow.findUnique({ where: { id }, @@ -257,7 +257,7 @@ router.post('/', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), asyn router.put('/:id', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id } = req.params; + const id = req.params.id as string; const parsed = updateWorkflowSchema.safeParse(req.body); if (!parsed.success) { @@ -312,7 +312,7 @@ router.put('/:id', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), as router.patch('/:id/status', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id } = req.params; + const id = req.params.id as string; const parsed = statusChangeSchema.safeParse(req.body); if (!parsed.success) { @@ -355,7 +355,7 @@ router.patch('/:id/status', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_AD router.delete('/:id', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id } = req.params; + const id = req.params.id as string; const workflow = await prisma.workflow.findUnique({ where: { id } }); if (!workflow) { @@ -380,7 +380,7 @@ router.delete('/:id', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), router.post('/:id/duplicate', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id } = req.params; + const id = req.params.id as string; const targetTenantId = req.body.tenantId as string | undefined; @@ -449,7 +449,7 @@ router.post('/:id/duplicate', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ router.post('/:id/steps', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id } = req.params; + const id = req.params.id as string; const parsed = createStepSchema.safeParse(req.body); if (!parsed.success) { @@ -495,7 +495,8 @@ router.post('/:id/steps', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMI router.put('/:id/steps/:stepId', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id, stepId } = req.params; + const id = req.params.id as string; + const stepId = req.params.stepId as string; const parsed = updateStepSchema.safeParse(req.body); if (!parsed.success) { @@ -543,7 +544,8 @@ router.put('/:id/steps/:stepId', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOM router.delete('/:id/steps/:stepId', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id, stepId } = req.params; + const id = req.params.id as string; + const stepId = req.params.stepId as string; const workflow = await prisma.workflow.findUnique({ where: { id } }); if (!workflow) { @@ -582,7 +584,7 @@ router.delete('/:id/steps/:stepId', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUS router.patch('/:id/steps/reorder', authorize('SYSTEM_ADMIN', 'TECHNICIAN', 'CUSTOMER_ADMIN'), async (req: Request, res: Response, next: NextFunction) => { try { const user = req.user!; - const { id } = req.params; + const id = req.params.id as string; const parsed = reorderStepsSchema.safeParse(req.body); if (!parsed.success) {