diff --git a/packages/server/src/api/rest/index.ts b/packages/server/src/api/rest/index.ts index 2e0bcaec..e8d5138c 100644 --- a/packages/server/src/api/rest/index.ts +++ b/packages/server/src/api/rest/index.ts @@ -1236,11 +1236,11 @@ class RequestHandler extends APIHandlerBase { return r.toString(); } - private makePrismaIdFilter(idFields: FieldInfo[], resourceId: string) { + private makePrismaIdFilter(idFields: FieldInfo[], resourceId: string, nested: boolean = true) { const decodedId = decodeURIComponent(resourceId); if (idFields.length === 1) { return { [idFields[0].name]: this.coerce(idFields[0].type, decodedId) }; - } else { + } else if (nested) { return { // TODO: support `@@id` with custom name [idFields.map((idf) => idf.name).join(prismaIdDivider)]: idFields.reduce( @@ -1251,6 +1251,14 @@ class RequestHandler extends APIHandlerBase { {} ), }; + } else { + return idFields.reduce( + (acc, curr, idx) => ({ + ...acc, + [curr.name]: this.coerce(curr.type, decodedId.split(this.idDivider)[idx]), + }), + {} + ); } } @@ -1594,11 +1602,11 @@ class RequestHandler extends APIHandlerBase { const values = value.split(',').filter((i) => i); const filterValue = values.length > 1 - ? { OR: values.map((v) => this.makePrismaIdFilter(info.idFields, v)) } - : this.makePrismaIdFilter(info.idFields, value); + ? { OR: values.map((v) => this.makePrismaIdFilter(info.idFields, v, false)) } + : this.makePrismaIdFilter(info.idFields, value, false); return { some: filterValue }; } else { - return { is: this.makePrismaIdFilter(info.idFields, value) }; + return { is: this.makePrismaIdFilter(info.idFields, value, false) }; } } else { const coerced = this.coerce(fieldInfo.type, value);