Skip to content

Commit

Permalink
feat(api): added a referential_updateCertificationCompetenceBloc muta…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
agarbe committed Nov 13, 2024
1 parent c4fe9b4 commit 5639f4d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { prismaClient } from "../../../prisma/client";
import {
CompetenceInput,
UpdateCompetenceBlocInput,
} from "../referential.types";

export const updateCertificationCompetenceBloc = (
args: UpdateCompetenceBlocInput,
) => {
const competencesToUpdate = args.competences.filter(
(competence): competence is CompetenceInput & { id: string } =>
!!competence.id,
);
const competencesToCreate = args.competences.filter(
(competence) => !competence.id,
);

return prismaClient.certificationCompetenceBloc.update({
where: { id: args.id },
data: {
label: args.label,
competences: {
deleteMany: { id: { notIn: competencesToUpdate.map((c) => c.id) } },
createMany: { data: competencesToCreate },
updateMany: competencesToUpdate.map((c) => ({
where: { id: c.id },
data: c,
})),
},
},
});
};
8 changes: 8 additions & 0 deletions packages/reva-api/modules/referential/referential.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ input UpdateCompetenceBlocsInput {
certificationId: ID!
blocs: [CompetenceBlocInput!]!
}
input UpdateCompetenceBlocInput {
id: ID
label: String!
competences: [CompetenceInput!]!
}

type Mutation {
referential_updateCertification(
Expand All @@ -314,4 +319,7 @@ type Mutation {
referential_updateCompetenceBlocsByCertificationId(
input: UpdateCompetenceBlocsInput!
): [CertificationCompetenceBloc!]!
referential_updateCertificationCompetenceBloc(
input: UpdateCompetenceBlocInput!
): CertificationCompetenceBloc
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { referentialResolversSecurityMap } from "./referential.security";
import {
CertificationStatus,
UpdateCertificationInput,
UpdateCompetenceBlocInput,
UpdateCompetenceBlocsInput,
} from "./referential.types";
import { RNCPReferential } from "./rncp";
Expand All @@ -38,6 +39,7 @@ import { getAvailableFormacodes } from "./features/getFormacodes";
import { getActiveCertifications } from "./features/getActiveCertifications";
import { getCandidacyFinancingMethods } from "./features/getCandidacyFinancingMethods";
import { getCertificationCompetenceBlocById } from "./features/getCertificationCompetenceBlocById";
import { updateCertificationCompetenceBloc } from "./features/updateCertificationCompetenceBloc";

const unsafeReferentialResolvers = {
Certification: {
Expand Down Expand Up @@ -154,6 +156,10 @@ const unsafeReferentialResolvers = {
_parent: unknown,
{ input }: { input: UpdateCompetenceBlocsInput },
) => updateCompetenceBlocsByCertificationId(input),
referential_updateCertificationCompetenceBloc: (
_parent: unknown,
{ input }: { input: UpdateCompetenceBlocInput },
) => updateCertificationCompetenceBloc(input),
},
};

Expand Down
3 changes: 3 additions & 0 deletions packages/reva-api/modules/referential/referential.security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export const referentialResolversSecurityMap = {
"Mutation.referential_updateCompetenceBlocsByCertificationId": [
hasRole(["admin"]),
],
"Mutation.referential_updateCertificationCompetenceBloc": [
hasRole(["admin"]),
],

"Query.getEtablissementAsAdmin": [hasRole(["admin"])],
"Query.getCertificationCompetenceBloc": [hasRole(["admin"])],
Expand Down
8 changes: 7 additions & 1 deletion packages/reva-api/modules/referential/referential.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface UpdateCertificationInput {
expiresAt: Date;
}

interface CompetenceInput {
export interface CompetenceInput {
id?: string;
index: number;
label: string;
Expand All @@ -82,3 +82,9 @@ export interface UpdateCompetenceBlocsInput {
certificationId: string;
blocs: CompetenceBlocInput[];
}

export interface UpdateCompetenceBlocInput {
id: string;
label: string;
competences: CompetenceInput[];
}

0 comments on commit 5639f4d

Please sign in to comment.