Skip to content

Commit

Permalink
feat(api): add isObsolete field and resolver for Candidacy type to de…
Browse files Browse the repository at this point in the history
…termine obsolescence based on last activity date
  • Loading branch information
ThomasDos committed Dec 10, 2024
1 parent 1fe222d commit 5826990
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/reva-api/modules/candidacy/candidacy.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Candidacy {
status: CandidacyStatusStep!
typeAccompagnement: TypeAccompagnement!
lastActivityDate: Timestamp
isObsolete: Boolean!
}
enum TypeAccompagnement {
ACCOMPAGNE
Expand Down
3 changes: 3 additions & 0 deletions packages/reva-api/modules/candidacy/candidacy.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
sendCandidacyDropOutEmailToCertificateur,
} from "./mails";
import { resolversSecurityMap } from "./security/security";
import { getCandidacyIsObsolete } from "./features/getCandidacyIsObsolete";

const unsafeResolvers = {
Candidacy: {
Expand All @@ -83,6 +84,8 @@ const unsafeResolvers = {
getCandidacyDropOutByCandidacyId({ candidacyId }),
candidacyOnCandidacyFinancingMethods: ({ id: candidacyId }: Candidacy) =>
getCandidacyOnCandidacyFinancingMethodsByCandidacyId({ candidacyId }),
isObsolete: ({ id: candidacyId }: Candidacy) =>
getCandidacyIsObsolete({ candidacyId }),
},
CandidacyOnCandidacyFinancingMethod: {
candidacyFinancingMethod: ({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { addMonths, isBefore } from "date-fns";
import { getCandidacyById } from "./getCandidacyById";

export const getCandidacyIsObsolete = async ({
candidacyId,
}: {
candidacyId: string;
}): Promise<boolean> => {
const candidacy = await getCandidacyById({ candidacyId });

if (!candidacy?.lastActivityDate) {
return false;
}

const sixMonthsFromLastActivity = addMonths(candidacy.lastActivityDate, 6);

return isBefore(sixMonthsFromLastActivity, new Date());
};

0 comments on commit 5826990

Please sign in to comment.