a month ago
Hi All!
I'm doing an Experiment for an 'audit log table' for CAP. My objective is log all create/update/delete transactions, something like this:
this.before(['CREATE', 'UPDATE', 'DELETE'], 'Users', async (req) => {
const { ID, firstName, lastName, Country, favouriteFood } = req.data;
// Capture change details
const changeDetails = {
firstName, lastName, Country, favouriteFood
};
const db = await cds.connect.to('db')
// Create an audit log entry
await cds.run(INSERT.into("pocaudit.AuditLogs").entries({
ID: cds.utils.uuid(),
entityName: 'Users',
entityID: ID,
action: req.event.toUpperCase(),
timestamp: new Date().toISOString(),
changedBy: req.user.id,
changes: JSON.stringify(changeDetails)
}));
});
But this event requires I mention the entity. Do you know any way to capture ALL entities so I can make only one handler?
Thanks!!
P.S.: I'm aware of Audit Log Service, but my context requires the audit to stay on a table.
Hi Daniel,
you can achieve the requested functionality by using *. So adjust your before event registration to:
this.before(['CREATE', 'UPDATE', 'DELETE'], '*', async (req)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
69 | |
11 | |
10 | |
10 | |
9 | |
9 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.