All files / server/src/features/results resultsService.ts

85.71% Statements 6/7
50% Branches 1/2
100% Functions 3/3
85.71% Lines 6/7

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 28 29      42x 15x 15x               15x             14x 13x              
import { GetResultsResponse } from "shared/types/api/results";
import { findResults } from "server/features/results/resultsRepository";
 
export const fetchResults = async (): Promise<GetResultsResponse> => {
  const findResultsResult = await findResults();
  Iif (!findResultsResult.ok) {
    return {
      message: "Getting results failed",
      status: "error",
      errorId: "unknown",
    };
  }
 
  return {
    message: "Getting results success",
    status: "success",
    // A run that placed nobody is recorded but holds nothing an attendee could read, so the
    // filter belongs here rather than to what gets stored. Individual user results and group
    // snapshots stay out of the public response too.
    assignmentRuns: findResultsResult.value
      .filter((assignmentResult) => assignmentResult.results.length > 0)
      .map((assignmentResult) => ({
        assignmentTime: assignmentResult.assignmentTime,
        algorithm: assignmentResult.algorithm,
        message: assignmentResult.message,
      })),
  };
};