Skip to content
Snippets Groups Projects
Commit 4e720744 authored by Federico Hurtado's avatar Federico Hurtado
Browse files

Create repository for database change logs, but we need to wait to setup JWT to implement this.

parent 89d36a6a
No related branches found
No related tags found
1 merge request!8Feature/activity logger
......@@ -47,7 +47,41 @@ async function getLoginDataTimerange(start, end) {
async function getLoginDataByUser() {}
async function logDatabaseChange() {}
/*
Insert a row into changeLog which keeps track of every time the database is changed.
*/
async function logDatabaseChange(
tableName,
recordId,
userId,
changeType,
changedColumns,
oldValues,
newValues
) {
const query = `
INSERT INTO changeLog (changedTable, recordId, userId, changeType, changedColumns, oldValues, newValues)
VALUES (?, ?, ?, ?, ?, ?, ?)
`;
const values = [
tableName,
recordId,
userId,
changeType,
changedColumns,
oldValues,
newValues,
];
try {
await pool.query(query, values);
console.log("Change logged successfully.");
} catch (error) {
// throw error to be caught by service
console.log("activity repository error when logging change: ", error);
throw error;
}
}
async function getDatabaseChangeTimerange() {}
......@@ -56,4 +90,5 @@ async function getDatabaseChangeByUser() {}
module.exports = {
logSuccessfulLogin,
getLoginDataTimerange,
logDatabaseChange,
};
......@@ -154,6 +154,7 @@ async function deletePersonById(peopleId) {
}
console.log("row deleted");
return true;
} catch (error) {
console.error(error);
......
const {
logSuccessfulLogin,
getLoginDataTimerange,
logDatabaseChange,
} = require("../repository/activityRepository");
/*
......@@ -16,7 +17,15 @@ async function documentSuccessfulLogin(userId, timestamp) {
}
}
async function logDatabaseChange() {}
async function logDatabaseChange(
tableName,
recordId,
userId,
changeType,
changedColumns,
oldValues,
newValues
) {}
/*
Get the login data for a sopecific time range
......@@ -28,4 +37,8 @@ async function viewLoginsTimerange(start, end) {
async function viewDatabaseChanges() {}
module.exports = { documentSuccessfulLogin, viewLoginsTimerange };
module.exports = {
documentSuccessfulLogin,
viewLoginsTimerange,
logDatabaseChange,
};
......@@ -79,6 +79,7 @@ async function findByName(firstName, lastName) {
Function to delete person by their id.
*/
async function deleteById(peopleId) {
// delete the person
const personDeleted = await deletePersonById(peopleId);
if (personDeleted) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment