Skip to content

Commit 5365f2a

Browse files
authored
fix: nest fastify multi-handler with query params (#284)
1 parent 75e81b9 commit 5365f2a

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

.changeset/twenty-turtles-yawn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ts-rest/nest': patch
3+
---
4+
5+
Fix multi-handler breaking in Fastify with query parameters

libs/ts-rest/nest/src/lib/ts-rest-nest-handler.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,9 @@ describe('ts-rest-nest-handler', () => {
876876
getPosts: {
877877
path: '/posts',
878878
method: 'GET',
879+
query: z.object({
880+
limit: z.string(),
881+
}),
879882
responses: {
880883
200: z.array(
881884
z.object({
@@ -984,7 +987,9 @@ describe('ts-rest-nest-handler', () => {
984987
await app.init();
985988
await app.getHttpAdapter().getInstance().ready();
986989

987-
const response = await supertest(app.getHttpServer()).get('/posts').send();
990+
const response = await supertest(app.getHttpServer())
991+
.get('/posts?limit=10')
992+
.send();
988993

989994
expect(response.status).toBe(200);
990995
expect(response.body).toEqual([{ id: 1 }, { id: 2 }]);

libs/ts-rest/nest/src/lib/ts-rest-nest-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ export class TsRestHandlerInterceptor implements NestInterceptor {
216216

217217
const appRouter = appRoute;
218218

219-
const foundAppRoute = Object.entries(appRouter).find(([key, value]) => {
219+
const foundAppRoute = Object.entries(appRouter).find(([, value]) => {
220220
if (isAppRoute(value)) {
221221
return (
222222
doesUrlMatchContractPath(
223223
value.path,
224-
'path' in req ? req.path : req.url
224+
'path' in req ? req.path : req.url.split('?')[0]
225225
) && req.method === value.method
226226
);
227227
}

0 commit comments

Comments
 (0)