From 857c4f4646c18ef174dd9c0a67317619c1b012f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A8re=20Pique?= Date: Tue, 8 Oct 2024 11:48:38 +0200 Subject: [PATCH] fix: fix mino --- .kontinuous/values.yaml | 24 ++++++++----- .../src/controllers/documents/upload.js | 12 +++++-- packages/backend/src/services/Document.js | 35 +++++++++++-------- .../pdf/ARdeclaration2mois/generate.js | 9 ++++- .../pdf/ARdeclaration8jours/generate.js | 9 ++++- .../services/pdf/declaration2mois/generate.js | 9 ++++- .../pdf/declaration8jours/generate.js | 9 ++++- .../components/DS/informations-vacanciers.vue | 32 +++++++---------- 8 files changed, 90 insertions(+), 49 deletions(-) diff --git a/.kontinuous/values.yaml b/.kontinuous/values.yaml index 9cc771a90..c1d9a066b 100644 --- a/.kontinuous/values.yaml +++ b/.kontinuous/values.yaml @@ -3,6 +3,12 @@ pg: cnpg-cluster: persistence: size: "50Gi" + resources: + requests: + memory: 1Gi + limits: + cpu: "1" + memory: 1Gi annotations: oblik.socialgouv.io/enabled: "false" @@ -14,11 +20,11 @@ backend: containerPort: 3000 resources: requests: - cpu: 0.2 - memory: 256Mi - limits: - cpu: 2 - memory: 1Gi + cpu: 200m + memory: 512Mi + limits: # exports need a lot of CPU/RAM ATM + cpu: 500m + memory: 768Mi livenessProbe: tcpSocket: port: 3000 @@ -76,8 +82,8 @@ frontend-usagers: cpu: 50m memory: 128Mi limits: - cpu: 500m - memory: 256Mi + cpu: 100m + memory: 128Mi livenessProbe: tcpSocket: port: 8080 @@ -97,8 +103,8 @@ frontend-bo: cpu: 50m memory: 128Mi limits: - cpu: 500m - memory: 256Mi + cpu: 100m + memory: 128Mi livenessProbe: tcpSocket: port: 8080 diff --git a/packages/backend/src/controllers/documents/upload.js b/packages/backend/src/controllers/documents/upload.js index 4dcdc93f1..3fd0815bd 100644 --- a/packages/backend/src/controllers/documents/upload.js +++ b/packages/backend/src/controllers/documents/upload.js @@ -1,3 +1,4 @@ +const fs = require("node:fs/promises"); const DocumentService = require("../../services/Document"); const AppError = require("../../utils/error"); @@ -41,8 +42,15 @@ module.exports = async (req, res, next) => { } try { - const uuid = await DocumentService.uploadLegacy(category, file); - await DocumentService.upload(category, file, uuid); + const { path, originalname: filename, mimetype } = file; + const data = await fs.readFile(path); + const uuid = await DocumentService.uploadLegacy( + filename, + category, + mimetype, + data, + ); + await DocumentService.upload(filename, category, mimetype, data, uuid); log.d("DONE", uuid); return res.json({ uuid }); } catch (error) { diff --git a/packages/backend/src/services/Document.js b/packages/backend/src/services/Document.js index 30cdad315..809d16002 100644 --- a/packages/backend/src/services/Document.js +++ b/packages/backend/src/services/Document.js @@ -1,5 +1,3 @@ -/* eslint-disable no-param-reassign */ -const fs = require("node:fs/promises"); const logger = require("../utils/logger"); const poolDoc = require("../utils/pgpoolDoc").getPool(); const AppError = require("../utils/error"); @@ -82,16 +80,14 @@ module.exports.download = async (uuid) => { } }; -module.exports.uploadLegacy = async (category, file) => { +module.exports.uploadLegacy = async (filename, category, mimetype, data) => { log.i("uploadLegacy - In"); try { - const { path, originalname: filename } = file; - const data = await fs.readFile(path); log.d("uploadLegacy", category, filename); const { rows: [{ uuid }], } = await poolDoc.query( - ...query.create(category, filename, file.mimetype, data), + ...query.create(category, filename, mimetype, data), ); log.d("uploadLegacy - Done"); return uuid; @@ -101,11 +97,15 @@ module.exports.uploadLegacy = async (category, file) => { } }; -module.exports.upload = async (category, file, uuid = crypto.randomUUID()) => { +module.exports.upload = async ( + filename, + category, + mimetype, + data, + uuid = crypto.randomUUID(), +) => { log.i("upload - In"); try { - const { path, originalname: filename } = file; - const data = await fs.readFile(path); log.d("upload", category, filename); await s3Client.send( new PutObjectCommand({ @@ -115,7 +115,7 @@ module.exports.upload = async (category, file, uuid = crypto.randomUUID()) => { Metadata: { category, created_at: String(new Date()), - mimetype: file.mimetype, + mimetype: mimetype, originalname: filename, }, }), @@ -127,20 +127,25 @@ module.exports.upload = async (category, file, uuid = crypto.randomUUID()) => { } }; -module.exports.createFile = async (filename, category, typeMime, data) => { - log.i("createFile - In"); +module.exports.createFileLegacy = async ( + filename, + category, + typeMime, + data, +) => { + log.i("createFile pg - In"); try { - log.i("createFile", { category, filename, typeMime }); + log.i("createFile pg", { category, filename, typeMime }); const { rows: [{ uuid }], } = await poolDoc.query( ...query.create(category, filename, typeMime, data), ); - log.i("createFile - Done"); + log.i("createFile pg - Done"); return uuid; } catch (err) { log.w(err); - throw new AppError("createFile failed", { cause: err }); + throw new AppError("createFile pg failed", { cause: err }); } }; diff --git a/packages/backend/src/services/pdf/ARdeclaration2mois/generate.js b/packages/backend/src/services/pdf/ARdeclaration2mois/generate.js index f780b2d92..528b4983d 100644 --- a/packages/backend/src/services/pdf/ARdeclaration2mois/generate.js +++ b/packages/backend/src/services/pdf/ARdeclaration2mois/generate.js @@ -14,12 +14,19 @@ const generate = async (declaration) => { const buffer = await build(declaration ?? {}); // insert into documents table - const uuid = await Document.createFile( + const uuid = await Document.createFileLegacy( `AR_${declaration.idFonctionnelle}.pdf`, "AR_declaration_2_mois", "application/pdf", buffer, ); + await Document.upload( + `AR_${declaration.idFonctionnelle}.pdf`, + "AR_declaration_2_mois", + "application/pdf", + buffer, + uuid, + ); log.d(`http://localhost:3010/documents/${uuid}`); // insert into demande_sejour table diff --git a/packages/backend/src/services/pdf/ARdeclaration8jours/generate.js b/packages/backend/src/services/pdf/ARdeclaration8jours/generate.js index 12cf06456..0d656dbdb 100644 --- a/packages/backend/src/services/pdf/ARdeclaration8jours/generate.js +++ b/packages/backend/src/services/pdf/ARdeclaration8jours/generate.js @@ -14,12 +14,19 @@ const generate = async (declaration) => { const buffer = await build(declaration ?? {}); // insert into documents table - const uuid = await Document.createFile( + const uuid = await Document.createFileLegacy( `AR_${declaration.idFonctionnelle}_8J.pdf`, "AR_declaration_8_jours", "application/pdf", buffer, ); + await Document.upload( + `AR_${declaration.idFonctionnelle}_8J.pdf`, + "AR_declaration_8_jours", + "application/pdf", + buffer, + uuid, + ); log.d(`http://localhost:3010/documents/${uuid}`); // insert into demande_sejour table diff --git a/packages/backend/src/services/pdf/declaration2mois/generate.js b/packages/backend/src/services/pdf/declaration2mois/generate.js index dae3e6523..5be3f1608 100644 --- a/packages/backend/src/services/pdf/declaration2mois/generate.js +++ b/packages/backend/src/services/pdf/declaration2mois/generate.js @@ -16,12 +16,19 @@ const generate = async (declaration, idFonctionnelle, departementSuivi) => { const buffer = await build(declaration ?? {}, departementSuivi); // insert into documents table - const uuid = await Document.createFile( + const uuid = await Document.createFileLegacy( `${idFonctionnelle}.pdf`, "declaration_2_mois", "application/pdf", buffer, ); + await Document.upload( + `${idFonctionnelle}.pdf`, + "declaration_2_mois", + "application/pdf", + buffer, + uuid, + ); log.d(`http://localhost:3010/documents/${uuid}`); // insert into demande_sejour table diff --git a/packages/backend/src/services/pdf/declaration8jours/generate.js b/packages/backend/src/services/pdf/declaration8jours/generate.js index ecd23329e..e09b13b40 100644 --- a/packages/backend/src/services/pdf/declaration8jours/generate.js +++ b/packages/backend/src/services/pdf/declaration8jours/generate.js @@ -25,12 +25,19 @@ const generate = async ( ); // insert into documents table - const uuid = await Document.createFile( + const uuid = await Document.createFileLegacy( `${idFonctionnelle}_8jours.pdf`, "declaration_8jours", "application/pdf", buffer, ); + await Document.upload( + `${idFonctionnelle}_8jours.pdf`, + "declaration_8jours", + "application/pdf", + buffer, + uuid, + ); log.d(`http://localhost:3010/documents/${uuid}`); // insert into demande_sejour table diff --git a/packages/frontend-usagers/src/components/DS/informations-vacanciers.vue b/packages/frontend-usagers/src/components/DS/informations-vacanciers.vue index bf8471705..8a02d5d30 100644 --- a/packages/frontend-usagers/src/components/DS/informations-vacanciers.vue +++ b/packages/frontend-usagers/src/components/DS/informations-vacanciers.vue @@ -38,15 +38,9 @@ name="effectifPrevisionnel" :label="`${DeclarationSejour.isPost8Jour(declarationStatut) ? 'Effectif des vacanciers' : 'Effectif prévisionnel des vacanciers'}`" :label-visible="true" - :model-value=" - effectifPrevisionnel ?? - (parseInt(effectifPrevisionnelFemme, 10) || 0) + - (parseInt(effectifPrevisionnelHomme, 10) || 0) - " - :readonly="!props.modifiable" - :is-valid="effectifPrevisionnelMeta.valid" - :error-message="effectifPrevisionnelErrorMessage" + :model-value="effectifs" placeholder="5" + readonly disabled /> @@ -138,11 +132,6 @@ const { meta, values } = useForm({ validateOnMount: props.validateOnMount, }); -const { - value: effectifPrevisionnel, - errorMessage: effectifPrevisionnelErrorMessage, - meta: effectifPrevisionnelMeta, -} = useField("effectifPrevisionnel"); const { value: effectifPrevisionnelHomme, errorMessage: effectifPrevisionnelHommeErrorMessage, @@ -166,6 +155,16 @@ const { meta: precisionDeficiencesMeta, } = useField("precisionDeficiences"); +const effectifs = computed(() => { + const total = + (parseInt(effectifPrevisionnelFemme.value, 10) || 0) + + (parseInt(effectifPrevisionnelHomme.value, 10) || 0); + if (total === initialValues.effectifPrevisionnel) { + return initialValues.effectifPrevisionnel ?? 0; + } + return total; +}); + function next() { if (!meta.value.dirty || !props.modifiable) { return emit("next"); @@ -175,12 +174,7 @@ function next() { { ...values, meta: meta.value.valid, - effectifPrevisionnel: - effectifPrevisionnel.value ?? - String( - (parseInt(effectifPrevisionnelHomme.value, 10) || 0) + - (parseInt(effectifPrevisionnelFemme.value, 10) || 0), - ), + effectifPrevisionnel: effectifs.value, }, "informationsVacanciers", );