-
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
- Loading branch information
1 parent
a90d7c9
commit e4e4857
Showing
16 changed files
with
291 additions
and
41 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,58 @@ | ||
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: 403, | ||
}), | ||
); | ||
} | ||
if (isNaN(eigId)) { | ||
return next( | ||
new AppError("Invalid param type", { | ||
statusCode: 403, | ||
}), | ||
); | ||
} | ||
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.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
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
Oops, something went wrong.