Strapi is a Javascript-based, next-generation, open-source headless CMS. It provides developers the facility to use their favorite frameworks and tools to create, modify and expose to any digital device. it also saves the development of Back-end API.
During the development of a project, one of the admins updated a few important records wrongly and we were unable to recognize who has done it. So I started finding out a way to fetch the record of the user responsible for the last modification on a particular content. And below is the block of code that the developer needs to add in the code block.
Go to the file ./api/yourmodelname/models/yourmodelname.js
and add this block of code there.
Once you deploy this change, every time when anyone modifies the content, a JSON will be printed in the log like below.
[JSON] updated_by: { isActive: true, blocked: false, roles: [ 611b60adddf2350662048bf9 ], _id: 6321919f44ba7a7deb7d6289, username: null, registrationToken: null, firstname: ‘Rohit’, lastname: ‘Ranjan’, email: ‘rohit.ranjan@example.com’, __v: 0, password: ‘$2a$10$1RlJ9uRzL3Ka/0lTxPXHSeXZkyBd5yhMTpWPqokoLJ4ubh0rmt47C’, id: ‘6321919f44ba7a7deb7d6289’ } [JSON]Once you deploy this change, every time when anyone modifies the content, a JSON will be printed in the log like below.
[JSON] updated_by: { isActive: true, blocked: false, roles: [ 611b60adddf2350662048bf9 ], _id: 6321919f44ba7a7deb7d6289, username: null, registrationToken: null, firstname: ‘Rohit’, lastname: ‘Ranjan’, email: ‘rohit.ranjan@example.com’, __v: 0, password: ‘$2a$10$1RlJ9uRzL3Ka/0lTxPXHSeXZkyBd5yhMTpWPqokoLJ4ubh0rmt47C’, id: ‘6321919f44ba7a7deb7d6289’ } [JSON]