All files / apps/huella-legal/layers/articles/server/mappers home.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 3/3
100% Lines 8/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        2x 2x 2x     2x 7x   7x       52x   21x      
import type { ArticleSummary } from "../../shared/types/ArticleSummary";
import type { Home } from "../../shared/types/Home";
import { toFormats, toSubjects } from "./articleListing";
 
const LATEST = 5;
const RECENT = 3;
const THESES = 3;
 
// The index arrives newest first from getArticleIndex
export const toHome = (index: ArticleSummary[]): Home => {
    const [lead, ...rest] = index;
 
    return {
        lead,
        latest: rest.slice(0, LATEST),
        recent: rest.slice(LATEST, LATEST + RECENT),
        theses: index.filter(({ format }) => format === "tfg-tfm").slice(0, THESES),
        subjects: toSubjects(index),
        formats: toFormats(index).filter(({ count }) => count > 0),
    };
};