Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More #100

Merged
merged 11 commits into from
Sep 30, 2023
Merged

More #100

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"uglify-js": "^3.17.4",
"uuid": "^9.0.1",
"winston": "^3.10.0",
"winston-transport": "^4.5.0"
"winston-transport": "^4.5.0",
"zod": "^3.22.2"
},
"engines": {
"node": ">=18.0.0"
Expand Down
65 changes: 51 additions & 14 deletions server/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { program as cli } from "commander";
import { parse } from "csv-parse/sync";
import fs, { writeFileSync } from "fs";
import _ from "lodash";
import { z } from "zod";

import { basepath } from "./basepath";
import { migrateDownDB, migrateToLatest } from "./migrations/migrate";
Expand Down Expand Up @@ -36,21 +39,55 @@ export const down = async () => {};
);

cli
.command("create-user")
.requiredOption("--email <string>")
.requiredOption("--firstname <string>")
.requiredOption("--lastname <string>")
.requiredOption("--role <string>")
.action(
async (options: {
email: string;
firstname: string;
lastname: string;
role: string;
}) => {
await createUser(options);
.command("importUsers")
.description("usage: cat << EOF | xargs -0 -I arg yarn cli importUsers arg")
.argument("<json>")
.option("--dryRun <boolean>", "parse the data only", false)
.action(async (input: string, { dryRun }) => {
const data = (
parse(input, {
columns: true,
skip_empty_lines: true,
trim: true,
delimiter: ";",
}) as {
firstname: string;
lastname: string;
email: string;
role: string;
codeRegion?: string;
}[]
).map((user) => _.mapValues(user, (value) => value || undefined));

const users = z
.array(
z.object({
firstname: z.string(),
lastname: z.string(),
email: z.string(),
role: z.string(),
codeRegion: z
.string()
.optional()
.transform((val) => val || undefined),
})
)
.parse(data);

if (dryRun) {
console.log(users);
return;
}

for (const user of users) {
try {
await createUser(user);
console.log(`${user.email} created successfuly`);
} catch (e) {
console.log(`${user.email} failed`, (e as Error).message);
}
}
);
});

cli
.command("importFiles")
Expand Down
2 changes: 1 addition & 1 deletion server/src/modules/core/services/mailer/mailer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ async function generateHtml({
utils: { getPublicUrl },
});

const { html } = mjml(buffer.toString(), { minify: true });
const { html } = mjml(buffer.toString(), {});
return html;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ export const [createUser, createUserFactory] = inject(
firstname,
lastname,
role,
codeRegion,
}: {
email: string;
firstname?: string;
lastname?: string;
role: string;
codeRegion?: string;
}) => {
if (!email.match(emailRegex)) throw Boom.badRequest("email is not valid");

Expand All @@ -36,6 +38,7 @@ export const [createUser, createUserFactory] = inject(
firstname,
lastname,
role,
codeRegion,
});
const activationToken = jwt.sign(
{ email },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Insertable } from "kysely";

import { kdb } from "../../../../db/db";
import { DB } from "../../../../db/schema";

export const insertUserQuery = async (user: {
email: string;
firstname?: string;
lastname?: string;
role: string;
}) => {
export const insertUserQuery = async (user: Insertable<DB["user"]>) => {
await kdb.insertInto("user").values(user).execute();
};
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const [submitDemande, submitDemandeFactory] = inject(
const dataFormation = await deps.findOneDataFormation({ cfd });
if (!dataFormation) throw Boom.badRequest("Code diplome non valide");

const toSave = {
const demandeData = {
...currentDemande,
libelleColoration: null,
poursuitePedagogique: null,
Expand All @@ -114,11 +114,12 @@ export const [submitDemande, submitDemandeFactory] = inject(
compensationRentreeScolaire,
};

const errors = validateDemande(cleanNull(toSave));
if (errors) throw Boom.badData("Donnée incorrectes", { errors });
const errors = validateDemande(cleanNull(demandeData));
if (errors)
throw Boom.badData("Donnée incorrectes", { errors, demandeData });

const created = await deps.createDemandeQuery({
...toSave,
...demandeData,
id: currentDemande?.id ?? generateId(),
createurId: currentDemande?.createurId ?? user.id,
status: "submitted",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const [submitDraftDemande] = inject(
const dataFormation = await deps.findOneDataFormation({ cfd });
if (!dataFormation) throw Boom.badRequest("Code diplome non valide");

const toSave = {
const demandeData = {
...currentDemande,
libelleColoration: null,
libelleFCIL: null,
Expand All @@ -114,11 +114,12 @@ export const [submitDraftDemande] = inject(
compensationRentreeScolaire,
};

const errors = validateDemande(cleanNull(toSave));
if (errors) throw Boom.badData("Donnée incorrectes", { errors });
const errors = validateDemande(cleanNull(demandeData));
if (errors)
throw Boom.badData("Donnée incorrectes", { errors, demandeData });

const created = await deps.createDemandeQuery({
...toSave,
...demandeData,
id: currentDemande?.id ?? generateId(),
createurId: currentDemande?.createurId ?? user.id,
status: "draft",
Expand Down
6 changes: 6 additions & 0 deletions shared/DEMANDES_COLUMNS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ export const DEMANDES_COLUMNS = {
compensationCfd: "CFD compensé",
compensationUai: "UAI compensé",
compensationDispositifId: "Dispositif compensé",
capaciteScolaireActuelle: "Capacité scolaire actuelle",
capaciteScolaire: "Capacité scolaire",
capaciteScolaireColoree: "Capacité scolaire coloree",
capaciteApprentissageActuelle: "Capacité apprentissage actuelle",
capaciteApprentissage: "Capacité apprentissage",
capaciteApprentissageColoree: "Capacité apprentissage coloree",
} as const;
32 changes: 30 additions & 2 deletions shared/demandeValidators/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const isTypeDiminution = (typeDemande: string) =>
export const isTypeCompensation = (typeDemande: string) =>
["augmentation_compensation", "ouverture_compensation"].includes(typeDemande);

const isTransfertApprentissage = (motif: string[]) =>
motif.includes("transfert_apprentissage");

const isPositiveNumber = (value: number | undefined): value is number => {
if (!Number.isInteger(value)) return false;
if (value === undefined) return false;
Expand All @@ -40,6 +43,11 @@ export const demandeValidators: Record<
return "Le champ 'autre motif' est obligatoire";
}
},
mixte: (demande) => {
if (isTransfertApprentissage(demande.motif) && !demande.mixte) {
return "Dans le cas d'un transfert vers l'apprentissage, la demande doit être mixte";
}
},
poursuitePedagogique: (demande) => {
if (isTypeFermeture(demande.typeDemande) && demande.poursuitePedagogique) {
return "Le champ 'poursuite pédagogique' devrait être à non";
Expand Down Expand Up @@ -121,6 +129,13 @@ export const demandeValidators: Record<
if (demande.capaciteApprentissageActuelle === 0) return;
return "Le champ capacité en apprentissage actuelle doit être à 0";
}
if (
(isTypeDiminution(demande.typeDemande) ||
isTypeFermeture(demande.typeDemande)) &&
isTransfertApprentissage(demande.motif)
)
return;

if (
isTypeOuverture(demande.typeDemande) &&
demande.capaciteApprentissageActuelle !== 0
Expand Down Expand Up @@ -149,7 +164,19 @@ export const demandeValidators: Record<
) {
return "La capacité en apprentissage devrait être supérieure à 0 dans le cas d'une ouverture";
}

if (
(isTypeDiminution(demande.typeDemande) ||
isTypeFermeture(demande.typeDemande)) &&
isTransfertApprentissage(demande.motif)
) {
if (
isPositiveNumber(demande.capaciteApprentissageActuelle) &&
demande.capaciteApprentissage <= demande.capaciteApprentissageActuelle
) {
return "La capacité en apprentissage doit être supérieure à la capacité actuelle en apprentissage dans le cas d'un transfert vers l'apprentissage";
}
return;
}
if (
isTypeFermeture(demande.typeDemande) &&
demande.capaciteApprentissage !== 0
Expand Down Expand Up @@ -239,11 +266,12 @@ export const demandeValidators: Record<
},
sommeCapaciteColoree: (demande) => {
if (
demande.typeDemande === "fermeture" ||
isTypeFermeture(demande.typeDemande) ||
!demande.coloration ||
!demande.mixte
)
return;

if (
!demande.capaciteApprentissageColoree &&
!demande.capaciteScolaireColoree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const InformationsBlock = ({
Enregister le projet de demande
</Button>
<Text fontSize={"xs"} mt="1" align={"center"}>
(Phase d'enregistrement du 02 au 12 octobre)
(Phase d'enregistrement du 02 au 16 octobre)
</Text>
</Box>
<Box justifyContent={"center"}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,22 @@ export const CapaciteSection = () => {
<AmiCmaField />
</Flex>
<LibelleColorationField maxW="752px" mb="4" />
<Heading fontSize="lg" mb="6" mt="16" color="bluefrance.113">
<Heading fontSize="lg" mb="6" mt="10" color="bluefrance.113">
Capacité en voie scolaire {mixte ? " uniquement" : null}
</Heading>
<Flex mb="4" gap={4}>
<CapaciteScolaireActuelleField maxW={240} flex={1} />
<CapaciteScolaireField maxW={240} flex={1} />
<CapaciteScolaireColoreeField maxW={240} flex={1} />
</Flex>
<Flex mb="8">
<ConstanteSection
typeDemande={typeDemande}
capaciteActuelle={capaciteScolaireActuelle}
capacite={capaciteScolaire}
/>
</Flex>
<ConstanteSection
typeDemande={typeDemande}
capaciteActuelle={capaciteScolaireActuelle}
capacite={capaciteScolaire}
/>
{mixte && (
<>
<Heading mt="8" fontSize="lg" mb="6" color="bluefrance.113">
<Heading mt="10" fontSize="lg" mb="6" color="bluefrance.113">
Capacité en apprentissage
</Heading>
<Flex gap={4} mb="4">
Expand All @@ -145,9 +143,7 @@ export const CapaciteSection = () => {
/>
</>
)}
<Flex align={"flex-start"} mt={16}>
<CommentaireField maxW={752} />
</Flex>
<CommentaireField mt={12} maxW={752} />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function RadioCard({
display="flex"
flexDirection="column"
{...props}
onClick={!disabled ? props.onClick : undefined}
flex={1}
cursor={disabled ? "not-allowed" : "pointer"}
borderWidth="1px"
Expand Down
4 changes: 2 additions & 2 deletions ui/app/(wrapped)/intentions/menuIntention/MenuIntention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const MenuIntention = ({
});

return (
<Box pr={6} minW={250}>
<Box pr={4} minW={250}>
<Button
variant="createButton"
size={"md"}
Expand Down Expand Up @@ -77,7 +77,7 @@ export const MenuIntention = ({
isRecapView && status === "submitted" ? "bold" : "normal"
}
>
Demande validées
Demandes validées
</Text>
</Button>
<Button
Expand Down
Loading