mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 07:03:38 +00:00
fix(i18n): support locale=all for single types
This commit is contained in:
parent
a40cce0407
commit
97e930e505
@ -69,14 +69,6 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
||||
|
||||
const query = transformParamsToQuery(uid, wrappedParams);
|
||||
|
||||
const { kind } = strapi.getModel(uid);
|
||||
if (kind === 'singleType') {
|
||||
if (opts?.locale === 'all') {
|
||||
return db.query(uid).findMany(query);
|
||||
}
|
||||
return db.query(uid).findOne(query);
|
||||
}
|
||||
|
||||
return db.query(uid).findMany(query);
|
||||
},
|
||||
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
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';
|
||||
@ -148,6 +150,36 @@ const decorator = (service) => ({
|
||||
await syncNonLocalizedAttributes(entry, { model });
|
||||
return entry;
|
||||
},
|
||||
|
||||
/**
|
||||
* Find an entry or several if fetching all locales
|
||||
* @param {string} uid - Model uid
|
||||
* @param {object} opts - Query options object (params, data, files, populate)
|
||||
*/
|
||||
async findMany(uid, opts = {}) {
|
||||
const model = strapi.getModel(uid);
|
||||
|
||||
const { isLocalizedContentType } = getService('content-types');
|
||||
|
||||
if (!isLocalizedContentType(model)) {
|
||||
return service.findMany.call(this, uid, opts);
|
||||
}
|
||||
|
||||
const { kind } = strapi.getModel(uid);
|
||||
|
||||
const wrappedParams = await this.wrapParams(opts, { uid, action: 'findMany' });
|
||||
|
||||
const query = transformParamsToQuery(uid, wrappedParams);
|
||||
|
||||
if (kind === 'singleType') {
|
||||
if (opts[LOCALE_QUERY_FILTER] === 'all') {
|
||||
return strapi.db.query(uid).findMany(query);
|
||||
}
|
||||
return strapi.db.query(uid).findOne(query);
|
||||
}
|
||||
|
||||
return strapi.db.query(uid).findMany(query);
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = () => ({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user