diff --git a/apps/meteor/app/api/server/ApiClass.ts b/apps/meteor/app/api/server/ApiClass.ts index d54563b459462..90fa11a81f9c0 100644 --- a/apps/meteor/app/api/server/ApiClass.ts +++ b/apps/meteor/app/api/server/ApiClass.ts @@ -71,9 +71,21 @@ export type ExtractRoutesFromAPI = type ConvertToRoute = { [K in TRoute['path']]: { - [K2 in TRoute['method']]: K2 extends 'GET' - ? (params: ExtractValidation) => ExtractValidation - : (params: ExtractValidation) => ExtractValidation; + [K2 in Extract['method']]: K2 extends 'GET' + ? ( + params: ExtractValidation['query']>, + ) => ExtractValidation['response'][200]> + : K2 extends 'POST' + ? ( + params: ExtractValidation['body']>, + ) => ExtractValidation< + 200 extends keyof Extract['response'] + ? Extract['response'][200] + : 201 extends keyof Extract['response'] + ? Extract['response'][201] + : never + > + : never; }; }; @@ -622,10 +634,12 @@ export class APIClass< ): APIClass< TBasePath, | TOperations - | ({ - method: Method; - path: TPathPattern; - } & Omit) + | Prettify< + { + method: Method; + path: TPathPattern; + } & Omit + > > { this.addRoute([subpath], { tags: [], ...options, typed: true }, { [method.toLowerCase()]: { action } } as any); this.registerTypedRoutes(method, subpath, options); @@ -660,6 +674,12 @@ export class APIClass< method: 'POST'; path: TPathPattern; } & Omit) + | Prettify< + { + method: 'POST'; + path: TPathPattern; + } & TOptions + > > { return this.method('POST', subpath, options, action); }