Skip to content

Commit 35ea74f

Browse files
Fix for filtering by compound id (#1806)
1 parent c344f77 commit 35ea74f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

packages/server/src/api/rest/index.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -1234,11 +1234,11 @@ class RequestHandler extends APIHandlerBase {
12341234
return r.toString();
12351235
}
12361236

1237-
private makePrismaIdFilter(idFields: FieldInfo[], resourceId: string) {
1237+
private makePrismaIdFilter(idFields: FieldInfo[], resourceId: string, nested: boolean = true) {
12381238
const decodedId = decodeURIComponent(resourceId);
12391239
if (idFields.length === 1) {
12401240
return { [idFields[0].name]: this.coerce(idFields[0].type, decodedId) };
1241-
} else {
1241+
} else if (nested) {
12421242
return {
12431243
// TODO: support `@@id` with custom name
12441244
[idFields.map((idf) => idf.name).join(prismaIdDivider)]: idFields.reduce(
@@ -1249,6 +1249,14 @@ class RequestHandler extends APIHandlerBase {
12491249
{}
12501250
),
12511251
};
1252+
} else {
1253+
return idFields.reduce(
1254+
(acc, curr, idx) => ({
1255+
...acc,
1256+
[curr.name]: this.coerce(curr.type, decodedId.split(this.idDivider)[idx]),
1257+
}),
1258+
{}
1259+
);
12521260
}
12531261
}
12541262

@@ -1608,11 +1616,11 @@ class RequestHandler extends APIHandlerBase {
16081616
const values = value.split(',').filter((i) => i);
16091617
const filterValue =
16101618
values.length > 1
1611-
? { OR: values.map((v) => this.makePrismaIdFilter(info.idFields, v)) }
1612-
: this.makePrismaIdFilter(info.idFields, value);
1619+
? { OR: values.map((v) => this.makePrismaIdFilter(info.idFields, v, false)) }
1620+
: this.makePrismaIdFilter(info.idFields, value, false);
16131621
return { some: filterValue };
16141622
} else {
1615-
return { is: this.makePrismaIdFilter(info.idFields, value) };
1623+
return { is: this.makePrismaIdFilter(info.idFields, value, false) };
16161624
}
16171625
} else {
16181626
const coerced = this.coerce(fieldInfo.type, value);

0 commit comments

Comments
 (0)