Skip to content

Commit

Permalink
fix: find checker user id
Browse files Browse the repository at this point in the history
  • Loading branch information
aaliakseyenka committed Sep 14, 2023
1 parent 4f42471 commit 0881cb9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions server/src/routes/course/crossCheck/createMessage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Router from '@koa/router';
import { getRepository } from 'typeorm';
import { StatusCodes } from 'http-status-codes';
import { ILogger } from '../../../logger';
import { IUserSession } from '../../../models';
import { IUserSession, Student } from '../../../models';
import { CrossCheckMessageAuthorRole } from '../../../models/taskSolutionResult';
import { courseService, CrossCheckService, notificationService } from '../../../services';
import { getTaskSolutionResultById } from '../../../services/taskResults.service';
Expand Down Expand Up @@ -67,9 +68,15 @@ export const createMessage = (_: ILogger) => async (ctx: Router.RouterContext) =
user: user,
});

const userId = await getUserId(student.id, taskSolutionResult.checkerId, inputData.role);
if (!userId) {
setErrorResponse(ctx, StatusCodes.BAD_REQUEST, 'user not found');
return;
}

await notificationService
.sendNotification({
userId: inputData.role === CrossCheckMessageAuthorRole.Reviewer ? student.userId : taskSolutionResult.checkerId,
userId,
notificationId: 'messages',
data: {
isReviewerMessage: inputData.role === CrossCheckMessageAuthorRole.Reviewer,
Expand All @@ -83,3 +90,13 @@ export const createMessage = (_: ILogger) => async (ctx: Router.RouterContext) =

setResponse(ctx, StatusCodes.OK);
};

async function getUserId(studentId: number, checkerId: number, role: CrossCheckMessageAuthorRole) {
if (role === CrossCheckMessageAuthorRole.Reviewer) {
return studentId;
}

const checker = await getRepository(Student).findOne({ where: { id: checkerId } });

return checker?.userId;
}

0 comments on commit 0881cb9

Please sign in to comment.