-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): implement CandidacyContestationCaducite module with resolv…
…ers and security rules - Added CandidacyContestationCaducite model and related GraphQL types for contestation handling. - Introduced resolvers for creating and retrieving contestations linked to candidacies. - Implemented security rules to ensure only owners can create contestations. - Refactored existing resolvers to integrate new contestation logic.
- Loading branch information
Showing
8 changed files
with
143 additions
and
4 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...modules/candidacy/candidacy-contestation-caducite/candidacy-contestation-caducite.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
type CandidacyContestationCaducite { | ||
id: ID! | ||
candidacyId: ID! | ||
contestationSentAt: Timestamp! | ||
contestationReason: String! | ||
contestationDecision: CertificationAuthorityContestationDecision! | ||
} | ||
|
||
enum CertificationAuthorityContestationDecision { | ||
DECISION_PENDING | ||
CADUCITE_INVALIDATED | ||
CADUCITE_CONFIRMED | ||
} | ||
|
||
type Candidacy { | ||
candidacyContestationsCaducite: [CandidacyContestationCaducite] | ||
} | ||
|
||
type Mutation { | ||
candidacy_contestation_caducite_create_contestation( | ||
candidacyId: ID! | ||
contestationReason: String! | ||
readyForJuryEstimatedAt: Timestamp! | ||
): CandidacyContestationCaducite | ||
} |
25 changes: 25 additions & 0 deletions
25
...es/candidacy/candidacy-contestation-caducite/candidacy-contestation-caducite.resolvers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { composeResolvers } from "@graphql-tools/resolvers-composition"; | ||
|
||
import { Candidacy } from "@prisma/client"; | ||
import { resolversSecurityMap } from "./candidacy-contestation-caducite.security"; | ||
import { CreateCandidacyContestationCaduciteInput } from "./candidacy-contestation-caducite.types"; | ||
import { createCandidacyContestationCaducite } from "./features/createCandidacyContestationCaducite"; | ||
import { getCandidacyContestationsCaduciteByCandidacyId } from "./features/getCandidacyContestationsCaduciteByCandidacyId"; | ||
|
||
const unsafeResolvers = { | ||
Candidacy: { | ||
candidacyContestationsCaducite: ({ id: candidacyId }: Candidacy) => | ||
getCandidacyContestationsCaduciteByCandidacyId({ candidacyId }), | ||
}, | ||
Mutation: { | ||
candidacy_contestation_caducite_create_contestation: ( | ||
_: unknown, | ||
input: CreateCandidacyContestationCaduciteInput, | ||
) => createCandidacyContestationCaducite(input), | ||
}, | ||
}; | ||
|
||
export const candidacyContestationCaduciteResolvers = composeResolvers( | ||
unsafeResolvers, | ||
resolversSecurityMap, | ||
); |
15 changes: 15 additions & 0 deletions
15
...les/candidacy/candidacy-contestation-caducite/candidacy-contestation-caducite.security.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { | ||
defaultSecurity, | ||
isOwnerOfCandidacy, | ||
} from "../../shared/security/presets"; | ||
|
||
export const resolversSecurityMap = { | ||
// Sécurité par défaut | ||
// cf https://the-guild.dev/graphql/tools/docs/resolvers-composition#supported-path-matcher-format | ||
"Query.*": defaultSecurity, | ||
|
||
"Mutation.*": defaultSecurity, | ||
|
||
"Mutation.candidacy_contestation_caducite_create_contestation": | ||
isOwnerOfCandidacy, | ||
}; |
5 changes: 5 additions & 0 deletions
5
...odules/candidacy/candidacy-contestation-caducite/candidacy-contestation-caducite.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type CreateCandidacyContestationCaduciteInput = { | ||
candidacyId: string; | ||
contestationReason: string; | ||
readyForJuryEstimatedAt: Date; | ||
}; |
55 changes: 55 additions & 0 deletions
55
...candidacy/candidacy-contestation-caducite/features/createCandidacyContestationCaducite.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { CertificationAuthorityContestationDecision } from "@prisma/client"; | ||
import { isBefore, startOfToday } from "date-fns"; | ||
import { prismaClient } from "../../../../prisma/client"; | ||
import { CreateCandidacyContestationCaduciteInput } from "../candidacy-contestation-caducite.types"; | ||
|
||
export const createCandidacyContestationCaducite = async ({ | ||
candidacyId, | ||
contestationReason, | ||
readyForJuryEstimatedAt, | ||
}: CreateCandidacyContestationCaduciteInput) => { | ||
if (!contestationReason) { | ||
throw new Error("La raison de la contestation est obligatoire"); | ||
} | ||
|
||
if (isBefore(readyForJuryEstimatedAt, startOfToday())) { | ||
throw new Error("La date prévisionnelle ne peut pas être dans le passé"); | ||
} | ||
|
||
const candidacy = await prismaClient.candidacy.findUnique({ | ||
where: { | ||
id: candidacyId, | ||
}, | ||
include: { candidacyContestationCaducite: true }, | ||
}); | ||
|
||
if (!candidacy) { | ||
throw new Error("La candidature n'a pas été trouvée"); | ||
} | ||
|
||
const contestationPending = candidacy.candidacyContestationCaducite.find( | ||
(contestation) => | ||
contestation.certificationAuthorityContestationDecision === | ||
CertificationAuthorityContestationDecision.DECISION_PENDING, | ||
); | ||
|
||
if (contestationPending) { | ||
throw new Error( | ||
"Une contestation est déjà en cours pour cette candidature", | ||
); | ||
} | ||
|
||
await prismaClient.candidacy.update({ | ||
where: { id: candidacyId }, | ||
data: { | ||
readyForJuryEstimatedAt, | ||
}, | ||
}); | ||
|
||
return prismaClient.candidacyContestationCaducite.create({ | ||
data: { | ||
candidacyId, | ||
contestationReason, | ||
}, | ||
}); | ||
}; |
12 changes: 12 additions & 0 deletions
12
...andidacy-contestation-caducite/features/getCandidacyContestationsCaduciteByCandidacyId.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { prismaClient } from "../../../../prisma/client"; | ||
|
||
export const getCandidacyContestationsCaduciteByCandidacyId = async ({ | ||
candidacyId, | ||
}: { | ||
candidacyId: string; | ||
}) => | ||
prismaClient.candidacyContestationCaducite.findMany({ | ||
where: { | ||
candidacyId, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters