@@ -6,6 +6,7 @@ import { ChatInstance, Enrolment, UserChatInstanceUsage, Prompt, User, Responsib
6
6
import { getOwnCourses } from '../services/chatInstances/access'
7
7
import { encrypt , decrypt } from '../util/util'
8
8
import { ApplicationError } from '../util/ApplicationError'
9
+ import { cleanIdStringSchema } from '../util/zodSchemas'
9
10
10
11
const courseRouter = express . Router ( )
11
12
@@ -340,6 +341,15 @@ courseRouter.put('/:id/responsibilities/assign', async (req, res) => {
340
341
}
341
342
const assignedUserId :string = body . assignedUserId
342
343
344
+ const chatInstanceIdClean = cleanIdStringSchema . safeParse ( chatInstanceId )
345
+ if ( ! chatInstanceIdClean . success ) {
346
+ res . status ( 400 ) . send ( 'Malformed chat instance id' )
347
+ }
348
+ const assignedUserIdClean = cleanIdStringSchema . safeParse ( assignedUserId )
349
+ if ( ! assignedUserIdClean . success ) {
350
+ res . status ( 400 ) . send ( 'Malformed assigned user id' )
351
+ }
352
+
343
353
const request = req as unknown as RequestWithUser
344
354
const { user} = request
345
355
const chatInstance = await getChatInstance ( chatInstanceId )
@@ -348,7 +358,7 @@ courseRouter.put('/:id/responsibilities/assign', async (req, res) => {
348
358
const userToAssign = await getUser ( assignedUserId )
349
359
const userAssignedAlready = await userAssignedAsResponsible ( assignedUserId , chatInstance )
350
360
if ( userAssignedAlready ) {
351
- res . status ( 401 ) . send ( 'User is already responsible for the course' )
361
+ res . status ( 400 ) . send ( 'User is already responsible for the course' )
352
362
return
353
363
}
354
364
0 commit comments