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

feat: amélioration de l'interface d'administration des listes de diffusion #371

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 18 additions & 0 deletions server/src/db/migrations/20240722133614-document-import-status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Db, MongoClient } from "mongodb";

import { getDbCollection } from "../../common/utils/mongodbUtils";

export const up = async (_db: Db, _client: MongoClient) => {
await getDbCollection("documents").updateMany(
{
job_status: "pending",
job_id: null,
created_at: { $lte: new Date(Date.now() - 24 * 3600 * 1000) },
},
{
$set: {
job_status: "error",
},
}
);
};
38 changes: 29 additions & 9 deletions server/src/modules/server/admin/upload.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import {
deleteDocumentById,
findDocuments,
getDocumentTypes,
updateDocument,
uploadFile,
} from "../../actions/documents.actions";
import { findMailingListWithDocument } from "../../actions/mailingLists.actions";
import { Server } from "../server";

const validateFile = (file: MultipartFile) => {
Expand Down Expand Up @@ -81,18 +83,22 @@ export const uploadAdminRoutes = ({ server }: { server: Server }) => {
mimetype: data.mimetype,
});

if (request.query?.import_content === "true") {
await addJob({
name: "import:document",
payload: {
document_id: document._id,
},
queued: true,
});
}
await addJob({
name: "import:document",
payload: {
document_id: document._id,
},
queued: true,
});

return response.status(200).send(toPublicDocument(document));
} catch (error) {
await updateDocument(document._id, {
$set: {
job_status: "error",
},
});

if (error.isBoom) {
throw error;
}
Expand Down Expand Up @@ -125,6 +131,20 @@ export const uploadAdminRoutes = ({ server }: { server: Server }) => {
return response.status(200).send(documents.map(toPublicDocument));
}
);
server.get(
"/admin/mailing-list/:user_id",
{
schema: zRoutes.get["/admin/mailing-list/:user_id"],
onRequest: [server.auth(zRoutes.get["/admin/mailing-list/:user_id"])],
},
async (request, response) => {
const mailingLists = await findMailingListWithDocument({
added_by: request.params.user_id.toString(),
});

return response.status(200).send(mailingLists);
}
);

server.delete(
"/admin/document/:id",
Expand Down
5 changes: 1 addition & 4 deletions server/src/modules/server/admin/user.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ export const userAdminRoutes = ({ server }: { server: Server }) => {
}

// Fixme: maybe we return too much data!!
return response.status(200).send({
...toPublicUser(user),
person: user.person,
});
return response.status(200).send(user);
}
);
};
3 changes: 1 addition & 2 deletions shared/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
},
"plugins": ["zod"],
"rules": {
"zod/prefer-enum": "error",
"zod/require-strict": "error"
"zod/prefer-enum": "error"
},
"parserOptions": {
"project": "shared/tsconfig.json"
Expand Down
18 changes: 0 additions & 18 deletions shared/helpers/openapi/__snapshots__/generateOpenapi.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
},
"schemas": {
"Error": {
"additionalProperties": false,
"properties": {
"code": {
"type": [
Expand Down Expand Up @@ -158,11 +157,9 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"schema": {
"anyOf": [
{
"additionalProperties": false,
"description": "Organisation deca Response body",
"properties": {
"contrats": {
"additionalProperties": false,
"properties": {
"appr": {
"type": "number",
Expand All @@ -182,7 +179,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"type": "object",
},
"dernier_contrat": {
"additionalProperties": false,
"properties": {
"date_debut_contrat": {
"type": "string",
Expand All @@ -197,7 +193,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
],
},
"premier_contrat": {
"additionalProperties": false,
"properties": {
"date_debut_contrat": {
"type": "string",
Expand All @@ -218,7 +213,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"type": "object",
},
{
"additionalProperties": false,
"properties": {
"code": {
"type": [
Expand Down Expand Up @@ -324,7 +318,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"content": {
"application/json": {
"schema": {
"additionalProperties": false,
"description": "Organisation deca Request body",
"properties": {
"siret": {
Expand All @@ -350,11 +343,9 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"schema": {
"anyOf": [
{
"additionalProperties": false,
"description": "Organisation deca Response body",
"properties": {
"contrats": {
"additionalProperties": false,
"properties": {
"appr": {
"type": "number",
Expand All @@ -374,7 +365,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"type": "object",
},
"dernier_contrat": {
"additionalProperties": false,
"properties": {
"date_debut_contrat": {
"type": "string",
Expand All @@ -389,7 +379,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
],
},
"premier_contrat": {
"additionalProperties": false,
"properties": {
"date_debut_contrat": {
"type": "string",
Expand All @@ -410,7 +399,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"type": "object",
},
{
"additionalProperties": false,
"properties": {
"code": {
"type": [
Expand Down Expand Up @@ -520,7 +508,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"content": {
"application/json": {
"schema": {
"additionalProperties": false,
"description": "Organisation validation Request body",
"properties": {
"email": {
Expand Down Expand Up @@ -551,11 +538,9 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"schema": {
"anyOf": [
{
"additionalProperties": false,
"description": "Organisation deca Response body",
"properties": {
"contrats": {
"additionalProperties": false,
"properties": {
"appr": {
"type": "number",
Expand All @@ -575,7 +560,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"type": "object",
},
"dernier_contrat": {
"additionalProperties": false,
"properties": {
"date_debut_contrat": {
"type": "string",
Expand All @@ -590,7 +574,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
],
},
"premier_contrat": {
"additionalProperties": false,
"properties": {
"date_debut_contrat": {
"type": "string",
Expand All @@ -611,7 +594,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"type": "object",
},
{
"additionalProperties": false,
"properties": {
"code": {
"type": [
Expand Down
1 change: 0 additions & 1 deletion shared/mailer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { z } from "zod";

// Ignore any extra props added by jwt parsing (iat, iss, ...)
// eslint-disable-next-line zod/require-strict
const zTemplateResetPassword = z.object({
name: z.literal("reset_password"),
to: z.string().email(),
Expand Down
1 change: 0 additions & 1 deletion shared/models/bouncer.domain.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const zBouncerDomain = z
updated_at: z.date(),
created_at: z.date(),
})
.strict();

export type BouncerDomain = z.output<typeof zBouncerDomain>;

Expand Down
4 changes: 2 additions & 2 deletions shared/models/bouncer.email.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const zBouncerPingResult = z
responseCode: z.string().nullable(),
responseMessage: z.string().nullable(),
})
.strict();
;

export type BouncerPingResult = z.output<typeof zBouncerPingResult>;

Expand All @@ -32,7 +32,7 @@ export const zBouncerEmail = z
ping: zBouncerPingResult,
created_at: z.date(),
})
.strict();
;

export type BouncerEmail = z.output<typeof zBouncerEmail>;

Expand Down
8 changes: 4 additions & 4 deletions shared/models/catalogue.api.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const etablissementFormateurSchema = z
rncp_etablissement_formateur_habilite: z.boolean().nullish(),
etablissement_formateur_date_creation: z.string().nullish(),
})
.strict();
;

const etablissementGestionnaireSchema = z
.object({
Expand Down Expand Up @@ -62,7 +62,7 @@ const etablissementGestionnaireSchema = z
rncp_etablissement_gestionnaire_habilite: z.boolean().nullish(),
etablissement_gestionnaire_date_creation: z.string().nullish(),
})
.strict();
;

const etablissementReferenceSchema = z
.object({
Expand All @@ -72,7 +72,7 @@ const etablissementReferenceSchema = z
etablissement_reference_certifie_qualite: z.boolean().nullish(),
etablissement_reference_date_creation: z.string().nullish(),
})
.strict();
;

const stringOrArraySchema = z.union([z.string(), z.array(z.string())]);

Expand Down Expand Up @@ -172,7 +172,7 @@ export const zFormationCatalogue = z
num_tel: z.string().nullish().describe("Numéro de téléphone de contact"),
distance: z.number().nullish(),
})
.strict()

.merge(etablissementFormateurSchema)
.merge(etablissementGestionnaireSchema)
.merge(etablissementReferenceSchema);
2 changes: 1 addition & 1 deletion shared/models/catalogueEmailSiret.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ZCatalogueEmailSiret = z
updated_at: z.date().optional().describe("Date de mise à jour en base de données"),
created_at: z.date().optional().describe("Date d'ajout en base de données"),
})
.strict();
;

export type ICatalogueEmailSiret = z.output<typeof ZCatalogueEmailSiret>;

Expand Down
2 changes: 1 addition & 1 deletion shared/models/deca.model/deca.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const ZDeca = z
updated_at: z.date().optional().describe("Date de mise à jour en base de données"),
created_at: z.date().nullish().describe("Date d'ajout en base de données"),
})
.strict();
;

export const ZDecaNew = ZDeca.omit({
_id: true,
Expand Down
2 changes: 1 addition & 1 deletion shared/models/deca.model/decaHistory.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const ZDecaHistory = z
deca_id: zObjectId,
time: z.date().describe("Modified time"),
})
.strict();
;

export type IDecaHistory = z.output<typeof ZDecaHistory>;
export type IDecaHistoryJson = Jsonify<z.input<typeof ZDecaHistory>>;
Expand Down
2 changes: 1 addition & 1 deletion shared/models/deca.model/decaImportJobResult.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ZDecaImportJobResult = z
),
created_at: z.date().describe("Date d'ajout en base de données"),
})
.strict();
;

export type IDecaImportJobResult = z.output<typeof ZDecaImportJobResult>;
export type IDecaImportJobResultJson = Jsonify<z.input<typeof ZDecaImportJobResult>>;
Expand Down
4 changes: 2 additions & 2 deletions shared/models/deca.model/parts/deca.apprenant.part.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export const ZDecaApprenant = z
voie: z.string().optional().describe("La voie de l'adresse"),
code_postal: z.string().optional().describe("Le code postal de l'adresse"),
})
.strict()

.optional(),
derniere_classe: z.coerce.number().nullish().describe("La dernière classe de l'apprenant"),
})
.strict();
;

export type IDecaApprenant = z.output<typeof ZDecaApprenant>;
export type IDecaApprenantJson = Jsonify<z.input<typeof ZDecaApprenant>>;
4 changes: 2 additions & 2 deletions shared/models/deca.model/parts/deca.employeur.part.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export const ZDecaEmployeur = z
.object({
code_postal: z.string().describe("Le code postal de l'adresse"),
})
.strict()

.optional(),
naf: z.string().optional().describe("Code NAF de l’entreprise"),
code_idcc: z.string().optional().describe("Le code IDCC de l'employeur"),
nombre_de_salaries: z.number().nullish().describe("Effectif salarié de l'entreprise"),
courriel: z.string().optional().describe("Email de l’employeur"),
telephone: z.string().optional().describe("Téléphone de l'employeur"),
})
.strict();
;

export type IDecaEmployeur = z.output<typeof ZDecaEmployeur>;
export type IDecaEmployeurJson = Jsonify<z.input<typeof ZDecaEmployeur>>;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const ZDecaEtablissementFormation = z
.object({
siret: extensions.siret.optional().describe("Le siret de l'établissement de la formation"),
})
.strict();
;

export type IDecaEtablissementFormation = z.output<typeof ZDecaEtablissementFormation>;
export type IDecaEtablissementFormationJson = Jsonify<z.input<typeof ZDecaEtablissementFormation>>;
2 changes: 1 addition & 1 deletion shared/models/deca.model/parts/deca.formation.part.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ZDecaFormation = z
rncp: z.string().optional().describe("Le code RNCP de la formation"),
type_diplome: z.string().optional().describe("Catégorie par niveau du Diplôme ou titre visé par l'Alternant"),
})
.strict();
;

export type IDecaFormation = z.output<typeof ZDecaFormation>;
export type IDecaFormationJson = Jsonify<z.input<typeof ZDecaFormation>>;
Loading
Loading