feat: sign load entities

This commit is contained in:
Marc-Roig 2023-05-08 15:41:42 +02:00
parent 2394ae2b9b
commit 06f9367dc3
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249

View File

@ -14,9 +14,18 @@ const addSignedFileUrlsToEntityService = async () => {
const decorator = (service) => ({
async wrapResult(result, options) {
const wrappedResult = await service.wrapResult.call(this, result, options);
// Load returns only the attribute of the entity, not the entity itself,
if (options.action === 'load') {
const entity = { [options.field]: result };
const signedEntity = await signEntityMedia(entity, options.uid);
return signedEntity[options.field];
}
if (Array.isArray(wrappedResult)) {
return Promise.all(wrappedResult.map((entity) => signEntityMedia(entity, options.uid)));
}
return signEntityMedia(wrappedResult, options.uid);
},
});