-
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(BO): liste territoire et détail 635-636
- Loading branch information
Showing
12 changed files
with
186 additions
and
137 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
17 changes: 17 additions & 0 deletions
17
packages/backend/src/controllers/bo-user/list-users-territoire.js
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,17 @@ | ||
const BoUser = require("../../services/BoUser"); | ||
const logger = require("../../utils/logger"); | ||
|
||
const log = logger(module.filename); | ||
|
||
module.exports = async function listUsersTerritoire(req, res, next) { | ||
log.i("IN"); | ||
const territoireCode = req.params.territoireCode; | ||
try { | ||
const result = await BoUser.readTerritoires(territoireCode); | ||
log.d(result); | ||
return res.status(200).json(result); | ||
} catch (error) { | ||
log.w("DONE with error"); | ||
return next(error); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,20 +1,28 @@ | ||
const AppError = require("../../utils/error"); | ||
const Territoire = require("../../services/Territoire"); | ||
|
||
const logger = require("../../utils/logger"); | ||
|
||
const log = logger(module.filename); | ||
|
||
module.exports = async function update(req, res) { | ||
module.exports = async function update(req, res, next) { | ||
log.i("IN"); | ||
console.log("req.params", req.decoded); | ||
const { id, territoireCode } = req.params; | ||
const { userTerritoireCode } = req.decoded; | ||
console.log("territoireCode : ", territoireCode); | ||
const { id } = req.params; | ||
const { territoire, parent } = req.body; | ||
const { territoireCode } = req.decoded; | ||
let response; | ||
if (userTerritoireCode === "FRA" || territoireCode === userTerritoireCode) { | ||
if ( | ||
territoireCode === "FRA" || | ||
territoireCode === territoire || | ||
territoireCode === parent | ||
) { | ||
response = await Territoire.update(id, req.body); | ||
console.log("territoires", response); | ||
} else response = "UnAuthorized"; | ||
} else { | ||
return next( | ||
new AppError("UnAuthorized", { | ||
statusCode: 400, | ||
}), | ||
); | ||
} | ||
log.i("DONE"); | ||
return res.json({ response }); | ||
}; |
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
Oops, something went wrong.