All files / server/src/features/assignment/utils getDynamicStartTime.ts

87.5% Statements 7/8
50% Branches 1/2
100% Functions 1/1
87.5% Lines 7/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27              48x     11x   11x 11x       11x         11x   11x    
import { addMinutes, startOfMinute } from "date-fns";
import { config } from "shared/config";
import { MongoDbError } from "shared/types/api/errors";
import { Result, makeSuccessResult } from "shared/utils/result";
import { getTimeNow } from "server/features/assignment/utils/getTimeNow";
import { logger } from "server/utils/logger";
 
export const getDynamicStartTime = async (): Promise<
  Result<string, MongoDbError>
> => {
  const { directSignupPhaseStart } = config.event();
 
  const timeNowResult = await getTimeNow();
  Iif (!timeNowResult.ok) {
    return timeNowResult;
  }
 
  const dynamicStartTime = addMinutes(
    startOfMinute(timeNowResult.value),
    directSignupPhaseStart,
  ).toISOString();
 
  logger.info(`Using dynamic start time: ${dynamicStartTime}`);
 
  return makeSuccessResult(dynamicStartTime);
};