Skip to content

Commit

Permalink
refactor: ♻️ evalLog의 fieldExtractor의 커서 검사 사항 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
niamu01 committed Feb 20, 2024
1 parent 1d3d5c3 commit 7f5667c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions app/src/page/evalLog/evalLog.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { BadRequestException, Injectable } from '@nestjs/common';
import { FilterQuery } from 'mongoose';
import { scale_team } from 'src/api/scaleTeam/db/scaleTeam.database.schema';
import {
Expand Down Expand Up @@ -143,7 +143,20 @@ const cursorExtractor: CursorExtractor<EvalLog> = (doc) =>
doc.id.toString() + '_' + doc.header.beginAt.toISOString();

const fieldExtractor: FieldExtractor<EvalLogCursorField> = (cursor: string) => {
const [idString, dateString] = cursor.split('_');
const cursorDataList = cursor.split('_');
if (cursorDataList.length !== 2) {
throw new BadRequestException('Invalid Cursor');
}

const userId = parseInt(cursorDataList[0]);
if (isNaN(userId)) {
throw new BadRequestException('Invalid Cursor');
}

const date = new Date(cursorDataList[1]).getTime();
if (isNaN(date)) {
throw new BadRequestException('Invalid Cursor');
}

return [parseInt(idString), new Date(dateString)];
return [userId, new Date(date)];
};

0 comments on commit 7f5667c

Please sign in to comment.