-
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.
- Loading branch information
Showing
14 changed files
with
405 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { actions } = require("../services/Tracking"); | ||
const boUser = require("../services/BoUser"); | ||
|
||
function trackFoUser({ action, userType }) { | ||
return async (req, res, next) => { | ||
const { id: userId } = req.decoded; | ||
const { id: boUserId } = req.params; | ||
|
||
let oldUser = null; | ||
if (boUserId) { | ||
oldUser = await boUser.getByUserId(boUserId); | ||
} | ||
|
||
res.on("finish", async () => { | ||
let newEig = null; | ||
|
||
if (action !== actions.deletion) { | ||
newEig = await boUser.getByUserId(boUserId); | ||
} | ||
|
||
if (boUserId) { | ||
boUser.addAsyncEigHistoric({ | ||
action, | ||
boUserId, | ||
data: { newData: newEig, 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,36 @@ | ||
const { actions } = require("../services/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 (eigId) { | ||
oldEig = await eigService.getByEigId(eigId); | ||
} | ||
|
||
req.on("finish", () => { | ||
let newEig = null; | ||
|
||
if (action !== actions.deletion) { | ||
newEig = eigService.getByEigId(eigId); | ||
} | ||
|
||
if (eigId) { | ||
eigService.addAsyncEigHistoric({ | ||
action, | ||
data: { newData: newEig, olData: oldEig }, | ||
eigId, | ||
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,36 @@ | ||
const { actions } = require("../services/Tracking"); | ||
const foUser = require("../services/User"); | ||
|
||
function trackFoUser({ action, userType }) { | ||
return async (req, res, next) => { | ||
const { id: userId } = req.decoded; | ||
const { id: foUserId } = req.params; | ||
|
||
let oldUser = null; | ||
if (foUserId) { | ||
oldUser = await foUser.getByUserId(foUserId); | ||
} | ||
|
||
req.on("finish", async () => { | ||
let newEig = null; | ||
|
||
if (action !== actions.deletion) { | ||
newEig = foUser.getByUserId(foUserId); | ||
} | ||
|
||
if (foUserId) { | ||
foUser.addAsyncEigHistoric({ | ||
action, | ||
data: { newData: newEig, olData: oldUser }, | ||
foUserId, | ||
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
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 pool = require("../utils/pgpool").getPool(); | ||
|
||
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; | ||
|
||
const query = { | ||
add: ` | ||
INSERT INTO tracking_actions (entity, entity_id, action, data, user_id, user_type) | ||
VALUES ($1, $2, $3, $4, $5 ,$6) | ||
`, | ||
}; | ||
|
||
module.exports.addHistoric = async ({ | ||
entity, | ||
entityId, | ||
action, | ||
data = null, | ||
userId, | ||
userType, | ||
}) => { | ||
if (!action || !entity || !userType) { | ||
throw new Error(`${module.filename}: Invalid action, entity or user type`, { | ||
action, | ||
entity, | ||
userType, | ||
}); | ||
} | ||
|
||
await pool.query(query.add, [ | ||
entity, | ||
entityId, | ||
action, | ||
data, | ||
userId, | ||
userType, | ||
]); | ||
}; |
Oops, something went wrong.