Skip to content

Commit

Permalink
feat(candidate,api): remove department from certification update
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricss committed Nov 13, 2024
1 parent b5dba6a commit 9ee0189
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type Mutation {
candidacy_certification_updateCertification(
candidacyId: ID!
certificationId: ID!
departmentId: ID!
): Void
candidacy_certification_updateCertificationWithinOrganismScope(
candidacyId: ID!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const unsafeResolvers = {
updateCertificationOfCandidacy({
candidacyId: payload.candidacyId,
certificationId: payload.certificationId,
departmentId: payload.departmentId,
userKeycloakId: context.auth.userInfo?.sub,
userEmail: context.auth?.userInfo?.email,
userRoles: context.auth.userInfo?.realm_access?.roles || [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
import { prismaClient } from "../../../../prisma/client";

export const updateCertification = async (params: {
candidacyId: string;
certificationId: string;
departmentId: string;
author: string;
feasibilityFormat: "UPLOADED_PDF" | "DEMATERIALIZED";
}) => {
const department = await prismaClient.department.findFirst({
where: {
id: params.departmentId,
},
});

if (!department) {
throw new Error(`department not found ${params.departmentId}`);
}

return prismaClient.candidacy.update({
where: {
id: params.candidacyId,
},
data: {
department: {
connect: {
id: department.id,
},
},
certification: { connect: { id: params.certificationId } },
feasibilityFormat: params.feasibilityFormat,
},
});
};
import { prismaClient } from "../../../../prisma/client";

export const updateCertification = async (params: {
candidacyId: string;
certificationId: string;
author: string;
feasibilityFormat: "UPLOADED_PDF" | "DEMATERIALIZED";
}) => {
return prismaClient.candidacy.update({
where: {
id: params.candidacyId,
},
data: {
certification: { connect: { id: params.certificationId } },
feasibilityFormat: params.feasibilityFormat,
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import {
} from "../../../../test/helpers/create-db-entity";
import { injectGraphql } from "../../../../test/helpers/graphql-helper";

import { Candidacy, CandidacyStatusStep } from "@prisma/client";
import { CandidacyStatusStep } from "@prisma/client";
import { CANDIDATE_MAN } from "../../../../test/fixtures";
import { certificationId2FromSeed } from "../../../../test/fixtures/candidacy";
import {
candidacyUnifvae,
certificationId2FromSeed,
} from "../../../../test/fixtures/candidacy";
import { basicTrainingForm } from "../../../../test/fixtures/training";
import { clearDatabase } from "../../../../test/jestClearDatabaseBeforeEachTestFile";

let candidacyUnifvae: Candidacy;

const submitTraining = async () =>
await injectGraphql({
fastify: (global as any).fastify,
Expand Down Expand Up @@ -68,7 +69,6 @@ const updateCertification = async () =>
endpoint: "candidacy_certification_updateCertification",
arguments: {
candidacyId: candidacyUnifvae.id,
departmentId: candidacyUnifvae.departmentId,
certificationId: certificationId2FromSeed,
},
returnFields: "",
Expand All @@ -79,7 +79,7 @@ beforeEach(async () => {
await createExpertFiliereOrganism();
await createExpertBrancheOrganism();
await createCandidateJPL();
candidacyUnifvae = await createCandidacyUnifvae();
await createCandidacyUnifvae();

await prismaClient.candidacy.update({
where: { id: candidacyUnifvae.id },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import { resetTrainingInformation } from "../../training/features/resetTrainingI
export const updateCertificationOfCandidacy = async ({
candidacyId,
certificationId,
departmentId,
userKeycloakId,
userEmail,
userRoles,
}: {
candidacyId: string;
certificationId: string;
departmentId: string;
userKeycloakId?: string;
userEmail?: string;
userRoles: KeyCloakUserRole[];
Expand Down Expand Up @@ -61,7 +59,6 @@ export const updateCertificationOfCandidacy = async ({
await updateCertification({
candidacyId,
certificationId,
departmentId,
author: "candidate",
feasibilityFormat:
candidacy.typeAccompagnement === "ACCOMPAGNE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export const updateCertificationWithinOrganismScope = async ({
await updateCertification({
candidacyId,
certificationId,
departmentId: candidacy.departmentId || "",
author: hasRole("admin") ? "admin" : "organism",
feasibilityFormat:
candidacy.typeAccompagnement === "ACCOMPAGNE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const confirmRegistration = async ({
throw new Error("Candidature non trouvée");
}

// if the candidate has selected a certification during its registration, we assign it if it's available in his department
// if the candidate has selected a certification during its registration, we assign it if it's available
if (
certificationId &&
(await isCertificationAvailable({
Expand All @@ -100,7 +100,6 @@ const confirmRegistration = async ({
candidacyId: candidacy.id,
author: "candidate",
certificationId,
departmentId: candidateRegistrationInput.departmentId,
feasibilityFormat:
candidacy.typeAccompagnement === "ACCOMPAGNE"
? certification.feasibilityFormat
Expand Down
5 changes: 0 additions & 5 deletions packages/reva-candidate/cypress/e2e/certificate-list.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { stubMutation, stubQuery } from "../utils/graphql";
context("Certificate list", () => {
beforeEach(() => {
cy.intercept("POST", "/api/graphql", (req) => {
stubQuery(req, "getDepartments", "departments.json");
stubMutation(req, "candidate_login", "candidate_login.json");
stubQuery(req, "candidate_getCandidateWithCandidacy", "candidate1.json");
stubQuery(req, "searchCertificationsForCandidate", "certifications.json");
Expand All @@ -18,10 +17,6 @@ context("Certificate list", () => {

it("should show only 2 certifications", function () {
cy.get('[data-test="project-home-set-certification"]').click();
cy.wait("@getDepartments");
cy.get("[data-test='certificates-select-department']")
.children("select")
.select("Région 2");

cy.wait("@searchCertificationsForCandidate");

Expand Down
4 changes: 0 additions & 4 deletions packages/reva-candidate/cypress/e2e/certificates.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { stubMutation, stubQuery } from "../utils/graphql";
context("Certificates", () => {
beforeEach(() => {
cy.intercept("POST", "/api/graphql", (req) => {
stubQuery(req, "getDepartments", "departments.json");
stubMutation(req, "candidate_login", "candidate_login.json");
stubQuery(req, "candidate_getCandidateWithCandidacy", "candidate1.json");
stubQuery(req, "activeFeaturesForConnectedUser", "features.json");
Expand All @@ -23,9 +22,6 @@ context("Certificates", () => {
cy.wait("@activeFeaturesForConnectedUser");

cy.get('[data-test="project-home-set-certification"]').click();
cy.get("[data-test='certificates-select-department']")
.children("select")
.select("Région 2");
cy.wait("@searchCertificationsForCandidate");
});

Expand Down
16 changes: 0 additions & 16 deletions packages/reva-candidate/cypress/fixtures/departments.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import { PageLayout } from "@/layouts/page.layout";
import { useCandidacy } from "@/components/candidacy/candidacy.context";

import { FormOptionalFieldsDisclaimer } from "@/components/legacy/atoms/FormOptionalFieldsDisclaimer/FormOptionalFieldsDisclaimer";
import {
DepartmentType,
SelectDepartment,
} from "@/components/select-department/SelectDepartment.component";

import { Pagination } from "@/components/pagination/Pagination";
import { SearchBar } from "@/components/legacy/molecules/SearchBar/SearchBar";
import { Results } from "@/components/legacy/organisms/Results";
Expand Down Expand Up @@ -52,13 +49,8 @@ export default function SetCertification() {

const { canEditCandidacy, candidate, refetch } = useCandidacy();

const [department, setDepartment] = useState<DepartmentType | undefined>(
candidate.department,
);

const { searchCertificationsForCandidate, updateCertification } =
useSetCertification({
departmentId: department?.id || "",
searchText: searchFilter,
currentPage,
});
Expand Down Expand Up @@ -120,14 +112,6 @@ export default function SetCertification() {
label="Sélectionnez le diplôme que vous voulez valider"
/>

<SelectDepartment
required
departmentId={department?.id}
onSelectDepartment={(department) => {
setDepartment(department);
}}
/>

<SearchBar
label="Rechercher un diplôme"
className="mb-8"
Expand All @@ -149,11 +133,7 @@ export default function SetCertification() {
/>

<p className="mb-0" role="status">
{department
? `Nombre de diplômes disponibles pour le département ${
department.label
} : ${info?.totalRows}`
: null}
Nombre de diplômes disponibles : {info?.totalRows}
</p>

<div id="results" className="flex flex-col justify-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,18 @@ const UPDATE_CERTIFICATION = graphql(`
mutation candidacy_certification_updateCertification(
$candidacyId: ID!
$certificationId: ID!
$departmentId: ID!
) {
candidacy_certification_updateCertification(
candidacyId: $candidacyId
certificationId: $certificationId
departmentId: $departmentId
)
}
`);

export const useSetCertification = ({
departmentId,
searchText,
currentPage,
}: {
departmentId: string;
searchText?: string;
currentPage: number;
}) => {
Expand All @@ -62,17 +58,11 @@ export const useSetCertification = ({
const offset = (currentPage - 1) * RECORDS_PER_PAGE;

const searchCertificationsForCandidate = useQuery({
queryKey: [
"searchCertificationsForCandidate",
departmentId,
searchText,
currentPage,
],
queryKey: ["searchCertificationsForCandidate", searchText, currentPage],
queryFn: () =>
graphqlClient.request(SEARCH_CERTIFICATIONS_FOR_CANDIDATE, {
offset,
limit: RECORDS_PER_PAGE,
departmentId,
searchText,
}),
gcTime: 0,
Expand All @@ -90,7 +80,6 @@ export const useSetCertification = ({
graphqlClient.request(UPDATE_CERTIFICATION, {
candidacyId,
certificationId,
departmentId,
}),
});

Expand Down

This file was deleted.

This file was deleted.

Empty file.

0 comments on commit 9ee0189

Please sign in to comment.