Is there a way to add virtual property in api response object ?
I tried to do this in the controller, but the values I add are not displayed in the API return.
My goal is to dynamically define the value of the virtual field according to the current day.
findOne: async ctx => {
if (!ctx.params._id.match(/^[0-9a-fA-F]{24}$/)) {
return ctx.notFound();
}
const cake = strapi.services.cake.fetch(ctx.params);
cake.virtualproperty = "test to add value in api return";
return cake;
}
ps: I try to do this in strapi cake example project
prototype
like thiscake.prototype.virtualproperty = 'what I want'
? I am new instrapi
and I don't have tested that yet. What do you mean by virtual ? Just a custom property in return if I well understand ? It's very interesting. There is also the way to use maybe in the modelafterFetch: async (model, response, options) => {}
to add a property to the model.