Fix some bugs introduced by the ts migration

This commit is contained in:
Alexandre Bodin 2023-09-18 09:43:24 +02:00
parent af1f80b6e8
commit 5802a65a2d
2 changed files with 9 additions and 21 deletions

View File

@ -20,7 +20,7 @@ type Entry = {
}; };
function isEntry(property: unknown): property is Entry | Entry[] { function isEntry(property: unknown): property is Entry | Entry[] {
return isPlainObject(property) || Array.isArray(property); return property === null || isPlainObject(property) || Array.isArray(property);
} }
function isDZEntries(property: unknown): property is (Entry & { __component: UID.Component })[] { function isDZEntries(property: unknown): property is (Entry & { __component: UID.Component })[] {
@ -102,12 +102,7 @@ function transformEntry(
const property = properties[key]; const property = properties[key];
const attribute = type && type.attributes[key]; const attribute = type && type.attributes[key];
if ( if (attribute && attribute.type === 'relation' && isEntry(property) && 'target' in attribute) {
attribute &&
contentTypeUtils.isRelationalAttribute(attribute) &&
isEntry(property) &&
'target' in attribute
) {
const data = transformEntry( const data = transformEntry(
property, property,
strapi.contentType(attribute.target as Common.UID.ContentType) strapi.contentType(attribute.target as Common.UID.ContentType)

View File

@ -54,12 +54,14 @@ const transformLoadParamsToQuery = (
params: Record<string, unknown>, params: Record<string, unknown>,
pagination = {} pagination = {}
) => { ) => {
const transformedParams = transformParamsToQuery(uid, params); const query = transformParamsToQuery(uid, { populate: { [field]: params } as any }) as any;
return { const res = {
...(_.get(transformedParams, ['populate', field]) ?? {}), ...query.populate[field],
...pagination, ...pagination,
}; };
return res;
}; };
const databaseErrorsToTransform = [ const databaseErrorsToTransform = [
@ -417,11 +419,7 @@ const createDefaultImplementation = ({
const loadedEntity = await db const loadedEntity = await db
.query(uid) .query(uid)
.load( .load(entity, field, transformLoadParamsToQuery(uid, field, params ?? {}));
entity,
field,
transformLoadParamsToQuery(uid, field, params as Record<string, unknown>)
);
return this.wrapResult(loadedEntity, { uid, field, action: 'load' }); return this.wrapResult(loadedEntity, { uid, field, action: 'load' });
}, },
@ -438,12 +436,7 @@ const createDefaultImplementation = ({
throw new Error(`Invalid load. Expected "${field}" to be an anyToMany relational attribute`); throw new Error(`Invalid load. Expected "${field}" to be an anyToMany relational attribute`);
} }
const query = transformLoadParamsToQuery( const query = transformLoadParamsToQuery(uid, field, params ?? {}, pagination);
uid,
field,
params as Record<string, unknown>,
pagination
);
const loadedPage: any = await db.query(uid).loadPages(entity, field, query); const loadedPage: any = await db.query(uid).loadPages(entity, field, query);