3

I'm currently doing some research on Strapi in order to build my API on it, and I was wondering if it's possible to expose in the JSON a field that would contain information about the user responsible for the last modification on a particular content ?

I know the API exposes an "updatedAt" field in the JSON object by default that contains the datetime it was last updated, but as I understand it this field is handled by the database when the data is sent to it for persistance ?

Any help would be greatly appreciated ! Thanks a lot.

user2618966
  • 31
  • 1
  • 3

2 Answers2

0

There is not this feature by default in Strapi.

You have access to the code of your app, so you can add it yourself.

You can create an History content type with relation with users and you models. Then by updating the lifecycle of your entry (afterCreate and beforeUpdate) you create an new history by link your entry id and you user id.

Jim LAURIE
  • 3,859
  • 1
  • 11
  • 14
0

As of 2020, you can find the person who updated the record, in two places:

// ./api/yourmodelname/models/yourmodelname.js

module.exports = {
  async afterUpdate(modifications, filter, resultData) {
    console.log(modifications.updated_by) // Full user object of editing Strapi user
    console.log(resultData.updated_by)    // User ID of editing Strapi user
  }
}
jorisw
  • 875
  • 1
  • 11
  • 17