-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eig): differentiate read by ddets and dreets (#498)
close jira 596, 597. j'ai rajouté la jira 584 : envoie d'un mail au reponsable du sejour et 613 : nouveau texte des mails qui s'inseraient bien dans cette PR loom : https://www.loom.com/share/a9b5d74d611248fbae2ffecb1442ba15?sid=379a4e6b-9ec0-4f92-b95d-3307c227fbb9 **Remarque :** j'utilise le service commune de geo qui semble etre un pur copié collé du SIHONO : les nom de colonnes ne sont pas les bon, j'ai corrigé ca, a priori, on utilisait ce service nul par ailleurs
- Loading branch information
Showing
19 changed files
with
456 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const logger = require("../utils/logger"); | ||
const AppError = require("../utils/error"); | ||
const { getById } = require("../services/eig"); | ||
const { statuts, mustMarkAsRead } = require("../helpers/eig"); | ||
|
||
const log = logger(module.filename); | ||
|
||
async function checkPermissionEIG(req, res, next) { | ||
const { id: userId, territoireCode } = req.decoded; | ||
const { id: eigId } = req.params; | ||
|
||
if (!eigId || isNaN(eigId)) { | ||
return next( | ||
new AppError("Vous n'êtes pas autorisé à accéder à cet EIG", { | ||
statusCode: 400, | ||
}), | ||
); | ||
} | ||
|
||
log.i("IN", { eigId, userId }); | ||
|
||
let eig; | ||
|
||
try { | ||
eig = await getById({ eigId }); | ||
} catch (err) { | ||
return res.status(400).send({ errors: err.errors, name: err.name }); | ||
} | ||
|
||
if (!eig) { | ||
log.w("EIG introuvable"); | ||
return next( | ||
new AppError("Not found", { | ||
statusCode: 400, | ||
}), | ||
); | ||
} | ||
|
||
if (eig.statut === statuts.BROUILLON) { | ||
log.w("L'EIG a un statut brouillon et ne peut pas être lu"); | ||
return next( | ||
new AppError("Statut incompatible", { | ||
statusCode: 400, | ||
}), | ||
); | ||
} | ||
|
||
if (mustMarkAsRead(territoireCode, eig)) { | ||
log.w("L'EIG doit d'abord être marqué comme lu"); | ||
return next( | ||
new AppError("l'EIG doit d'abord être marqué comme lu", { | ||
statusCode: 400, | ||
}), | ||
); | ||
} | ||
|
||
log.i("DONE"); | ||
next(); | ||
} | ||
|
||
module.exports = checkPermissionEIG; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.