Hi,
I am developing a plugin and I need to modify some of the queries before I send them to the db. I have tried to use db subscriptions class but it is not enough for me. I need to modify the query builder class. Right now I am patching this class which works but I need to find a cleaner way to do it. Is there any way to replace this class in the bootstrap or register hooks? Any suggestions help me a lot.
Thanks!
You could see if strapi.entityService.decorate
is the solution for you. this will be ran on all quarry’s
example of i18n using it.
});
};
module.exports = async ({ strapi }) => {
const { sendDidInitializeEvent } = getService('metrics');
const { decorator } = getService('entity-service-decorator');
const { initDefaultLocale } = getService('locales');
const { sectionsBuilder, actions, engine } = getService('permissions');
// Entity Service
strapi.entityService.decorate(decorator);
// Data
await initDefaultLocale();
// Sections Builder
sectionsBuilder.registerLocalesPropertyHandler();
// Actions
await actions.registerI18nActions();
actions.registerI18nActionsHooks();
'use strict';
const { has, get, omit, isArray } = require('lodash/fp');
const { ApplicationError } = require('@strapi/utils').errors;
const { transformParamsToQuery } = require('@strapi/utils').convertQueryParams;
const { getService } = require('../utils');
const LOCALE_QUERY_FILTER = 'locale';
const SINGLE_ENTRY_ACTIONS = ['findOne', 'update', 'delete'];
const BULK_ACTIONS = ['delete'];
const paramsContain = (key, params) => {
return (
has(key, params.filters) ||
(isArray(params.filters) && params.filters.some((clause) => has(key, clause))) ||
(isArray(get('$and', params.filters)) && params.filters.$and.some((clause) => has(key, clause)))
);
};
This file has been truncated. show original
1 Like
@Boegie19 Thanks, This is actually useful. Is there any documentation about it out there?