fix: resolve TypeScript type errors in route params

This commit is contained in:
root 2026-03-20 22:55:51 +00:00
parent d58d53fa3b
commit 4adcb42bb5
4 changed files with 21 additions and 19 deletions

View File

@ -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 },

View File

@ -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) {

View File

@ -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') {

View File

@ -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) {