-
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(historic): add historic in app (#718)
## Tickets liés Close # tickets liés : ## Description ### dont régressions potentielles à tester ## Screenshot / liens loom ## Check-list - [x] Ma branche est rebase sur main - [ ] Des tests ont été écrits pour tous les endpoints créés ou modifiés - [ ] Refacto "à la volée" des parties sur lesquelles j'ai codée - [x] Plus de `console.log`
- Loading branch information
Showing
17 changed files
with
430 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const actions = { | ||
creation: "CREATION", | ||
deactivation: "DEACTIVATION", | ||
deletion: "DELETION", | ||
modification: "MODIFICATION", | ||
}; | ||
|
||
module.exports.actions = actions; | ||
|
||
const entities = { | ||
eig: "EIG", | ||
userBack: "USER_BACK", | ||
userFront: "USER_FRONT", | ||
}; | ||
|
||
module.exports.entities = entities; | ||
|
||
const userTypes = { | ||
back: "BACK", | ||
front: "FRONT", | ||
}; | ||
|
||
module.exports.userTypes = userTypes; |
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,39 @@ | ||
const { actions } = require("../helpers/tracking"); | ||
const boUser = require("../services/BoUser"); | ||
|
||
function trackFoUser({ action, userType, itself }) { | ||
return async (req, res, next) => { | ||
const { id: userId } = req.decoded; | ||
|
||
const boUserId = itself ? userId : req.params.userId; | ||
|
||
let oldUser = null; | ||
if (action !== actions.creation) { | ||
oldUser = await boUser.getByUserId(boUserId); | ||
} | ||
res.on("finish", async () => { | ||
if (res.statusMessage !== "OK") { | ||
return null; | ||
} | ||
|
||
let newUser = null; | ||
const id = action === actions.creation ? req.tracking.id : boUserId; | ||
|
||
if (action !== actions.deletion) { | ||
newUser = await boUser.getByUserId(id); | ||
} | ||
|
||
boUser.addAsyncUserHistoric({ | ||
action, | ||
boUserId: id, | ||
data: { newData: newUser, olData: oldUser }, | ||
userId, | ||
userType, | ||
}); | ||
}); | ||
|
||
next(); | ||
}; | ||
} | ||
|
||
module.exports = trackFoUser; |
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,41 @@ | ||
const { actions } = require("../helpers/tracking"); | ||
const eigService = require("../services/eig"); | ||
|
||
function trackEig({ action, userType }) { | ||
return async (req, res, next) => { | ||
const { id: userId } = req.decoded; | ||
const { id: eigId } = req.params; | ||
|
||
let oldEig = null; | ||
if (action !== actions.creation) { | ||
oldEig = await eigService.getByEigId(eigId); | ||
} | ||
|
||
res.on("finish", () => { | ||
if (res.statusMessage !== "OK") { | ||
return null; | ||
} | ||
|
||
let newEig = null; | ||
const id = action === actions.creation ? req.tracking.id : eigId; | ||
|
||
if (action !== actions.deletion) { | ||
newEig = eigService.getByEigId(id); | ||
} | ||
|
||
if (eigId) { | ||
eigService.addAsyncEigHistoric({ | ||
action, | ||
data: { newData: newEig, olData: oldEig }, | ||
eigId: id, | ||
userId, | ||
userType, | ||
}); | ||
} | ||
}); | ||
|
||
next(); | ||
}; | ||
} | ||
|
||
module.exports = trackEig; |
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,42 @@ | ||
const { actions } = require("../helpers/tracking"); | ||
const foUser = require("../services/User"); | ||
|
||
function trackFoUser({ action, userType, itself }) { | ||
return async (req, res, next) => { | ||
const { id: userId } = req.decoded; | ||
|
||
const foUserId = itself ? userId : req.params.userId; | ||
|
||
let oldUser = null; | ||
if (action !== actions.creation) { | ||
oldUser = await foUser.getByUserId(foUserId); | ||
} | ||
|
||
res.on("finish", async () => { | ||
if (res.statusMessage !== "OK") { | ||
return null; | ||
} | ||
|
||
let newUser = null; | ||
const id = action === actions.creation ? req.tracking.id : foUserId; | ||
|
||
if (action !== actions.deletion) { | ||
newUser = foUser.getByUserId(id); | ||
} | ||
|
||
if (foUserId) { | ||
foUser.addAsyncUserHistoric({ | ||
action, | ||
data: { newData: newUser, olData: oldUser }, | ||
foUserId: id, | ||
userId, | ||
userType, | ||
}); | ||
} | ||
}); | ||
|
||
next(); | ||
}; | ||
} | ||
|
||
module.exports = trackFoUser; |
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.