mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 08:52:26 +00:00
fix test and add wrapResult support
This commit is contained in:
parent
b29e20c7b5
commit
3fdbbfc203
@ -37,6 +37,7 @@ const singleTypeModel = {
|
|||||||
localized: true,
|
localized: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
attributes: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const models = {
|
const models = {
|
||||||
@ -355,6 +356,7 @@ describe('Entity service decorator', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const defaultService = {
|
const defaultService = {
|
||||||
|
wrapResult: jest.fn((input) => Promise.resolve(input)),
|
||||||
wrapParams: jest.fn(() => Promise.resolve(entry)),
|
wrapParams: jest.fn(() => Promise.resolve(entry)),
|
||||||
findMany: jest.fn(() => Promise.resolve(entry)),
|
findMany: jest.fn(() => Promise.resolve(entry)),
|
||||||
};
|
};
|
||||||
|
@ -80,8 +80,19 @@ const assignValidLocale = async (data) => {
|
|||||||
*/
|
*/
|
||||||
const decorator = (service) => ({
|
const decorator = (service) => ({
|
||||||
/**
|
/**
|
||||||
|
* Wraps result
|
||||||
|
* @param {object} params - Query options object (params, data, files, populate)
|
||||||
|
* @param {object} ctx - Query context
|
||||||
|
* @param {object} ctx.model - Model that is being used
|
||||||
|
*/
|
||||||
|
async wrapResult(params = {}, ctx = {}) {
|
||||||
|
return service.wrapResult.call(this, params, ctx);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
* Wraps query options. In particular will add default locale to query params
|
* Wraps query options. In particular will add default locale to query params
|
||||||
* @param {object} opts - Query options object (params, data, files, populate)
|
* @param {object} params - Query options object (params, data, files, populate)
|
||||||
* @param {object} ctx - Query context
|
* @param {object} ctx - Query context
|
||||||
* @param {object} ctx.model - Model that is being used
|
* @param {object} ctx.model - Model that is being used
|
||||||
*/
|
*/
|
||||||
@ -156,7 +167,7 @@ const decorator = (service) => ({
|
|||||||
* @param {string} uid - Model uid
|
* @param {string} uid - Model uid
|
||||||
* @param {object} opts - Query options object (params, data, files, populate)
|
* @param {object} opts - Query options object (params, data, files, populate)
|
||||||
*/
|
*/
|
||||||
async findMany(uid, opts) {
|
async findMany(uid, opts = {}) {
|
||||||
const model = strapi.getModel(uid);
|
const model = strapi.getModel(uid);
|
||||||
|
|
||||||
const { isLocalizedContentType } = getService('content-types');
|
const { isLocalizedContentType } = getService('content-types');
|
||||||
@ -170,9 +181,12 @@ const decorator = (service) => ({
|
|||||||
if (kind === 'singleType') {
|
if (kind === 'singleType') {
|
||||||
if (opts[LOCALE_QUERY_FILTER] === 'all') {
|
if (opts[LOCALE_QUERY_FILTER] === 'all') {
|
||||||
// TODO Fix so this won't break lower lying find many wrappers
|
// TODO Fix so this won't break lower lying find many wrappers
|
||||||
const wrappedParams = await this.wrapParams(opts, { uid, action: 'findMany' }) || {};
|
const wrappedParams = await this.wrapParams(opts, { uid, action: 'findMany' });
|
||||||
const query = transformParamsToQuery(model, wrappedParams);
|
console.log("ABC")
|
||||||
return strapi.db.query(uid).findMany(query);
|
console.log(wrappedParams)
|
||||||
|
const query = transformParamsToQuery(uid, wrappedParams);
|
||||||
|
const entities = await strapi.db.query(uid).findMany(query);
|
||||||
|
return this.wrapResult(entities, { uid, action: 'findMany' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// This one gets transformed into a findOne on a lower layer
|
// This one gets transformed into a findOne on a lower layer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user