Hi,
could somone give me an example how to get also the data of a related collection type?
The default emited data contains only a count:
id: 7
note: "TEXT TEXT"
order: Object { count: 1 } // How to get the related order data?
count: 1
<prototype>: Object { … }
updatedAt: "2023-06-13T17:09:01.693Z"
updatedBy: Object { id: 1, firstname: "Max", lastname: "Example", … }
users_permissions_user: Object { count: 1 } // How to get the related user data?
I tried to extend the update action in the order-note controller with strapi.$io.emit('api::order-note.order-note.update', static-testdata)
, but that doesn’t change anything.
Thanks Roman
My mistake: strapi.$io.emit('api::order-note.order-note.update', static-testdata)
in controller works, when updateing through api (not updating in Strapi-Admin).
My controllers/order-note.js now is:
'use strict';
/**
* order-note controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
async function getEmitData(id) {
const entry = await strapi.entityService.findOne('api::order-note.order-note', id, {
fields: ['note', 'createdAt', 'updatedAt'],
populate: {
users_permissions_user: {
fields: ['id', 'fullname', 'email']
},
order: {
fields: ['order_no']
}
},
});
return entry
}
module.exports = createCoreController('api::order-note.order-note', ({ strapi }) => ({
async update(ctx) {
const response = await super.update(ctx);
const data = response.data
const emit = await getEmitData(data.id)
strapi.$io.emit('api::order-note.order-note.update', emit);
return response
},
async create(ctx) {
const response = await super.create(ctx);
const data = response.data
const emit = await getEmitData(data.id)
strapi.$io.emit('api::order-note.order-note.create', emit);
return response
}
}))
Now I get it emittet twice. First comes my custom emit strapi.$io.emit('api::order-note.order-note.create', emit);
and then the standard emit. How can I avoid the standard emit?