Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 12 additions & 36 deletions packages/server/src/api/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1042,43 +1042,19 @@ class RequestHandler {
{
relatedName: field,
linkers: {
related: new Linker((primary, related) =>
!related || Array.isArray(related)
? this.makeLinkUrl(
`/${lowerCaseFirst(model)}/${this.getId(
model,
primary,
modelMeta
)}/${field}`
)
: this.makeLinkUrl(
`/${lowerCaseFirst(model)}/${this.getId(
model,
primary,
modelMeta
)}/${field}/${this.getId(fieldMeta.type, related, modelMeta)}`
)
related: new Linker((primary) =>
this.makeLinkUrl(
`/${lowerCaseFirst(model)}/${this.getId(model, primary, modelMeta)}/${field}`
)
),
relationship: new Linker((primary, related) =>
!related || Array.isArray(related)
? this.makeLinkUrl(
`/${lowerCaseFirst(model)}/${this.getId(
model,
primary,
modelMeta
)}/relationships/${field}`
)
: this.makeLinkUrl(
`/${lowerCaseFirst(model)}/${this.getId(
model,
primary,
modelMeta
)}/relationships/${field}/${this.getId(
fieldMeta.type,
related,
modelMeta
)}`
)
relationship: new Linker((primary) =>
this.makeLinkUrl(
`/${lowerCaseFirst(model)}/${this.getId(
model,
primary,
modelMeta
)}/relationships/${field}`
)
),
},
}
Expand Down
4 changes: 2 additions & 2 deletions packages/server/tests/api/rest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1386,8 +1386,8 @@ describe('REST server tests - regular prisma', () => {
relationships: {
author: {
links: {
self: 'http://localhost/api/post/1/relationships/author/user1',
related: 'http://localhost/api/post/1/author/user1',
self: 'http://localhost/api/post/1/relationships/author',
related: 'http://localhost/api/post/1/author',
},
data: { type: 'user', id: 'user1' },
},
Expand Down