Skip to content

Commit b27248c

Browse files
returned the created value
1 parent 01f358f commit b27248c

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/server/routes/course.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,27 +332,37 @@ courseRouter.put('/:id', async (req, res) => {
332332
}
333333
return user
334334
}
335+
335336
courseRouter.put('/:id/responsibilities/assign', async (req, res) => {
336337
const chatInstanceId = req.params.id
337338
const body = req.body as {
338339
assignedUserId: string
339340
}
340341
const assignedUserId:string = body.assignedUserId
341342

342-
const request = req as unknown as RequestWithUser
343+
const request = req as unknown as RequestWithUser
343344
const {user} = request
344345
const chatInstance = await getChatInstance(chatInstanceId)
345346
const hasPermission = await enforceUserHasFullAccess(user, chatInstanceId)
346347

347348
const userToAssign = await getUser(assignedUserId)
348-
const userNotAssignedAlready = await !userAssignedAsResponsible(assignedUserId, chatInstance)
349-
if(hasPermission && userToAssign && userNotAssignedAlready){
350-
await Responsibility.create({
349+
const userAssignedAlready = await userAssignedAsResponsible(assignedUserId, chatInstance)
350+
if(userAssignedAlready){
351+
res.status(401).send('User is already responsible for the course')
352+
}
353+
354+
if(hasPermission && userToAssign && !userAssignedAlready){
355+
const createdResponsibility = await Responsibility.create({
351356
userId: assignedUserId,
352357
chatInstanceId: chatInstance.id,
353358
createdByUserId: user.id
354359
})
360+
361+
return res.json(createdResponsibility)
355362
}
363+
364+
365+
res.status(500).send('Unknown error occurred')
356366
})
357367

358368

0 commit comments

Comments
 (0)