Skip to content
Merged
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
34 changes: 27 additions & 7 deletions apps/meteor/app/api/server/ApiClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,21 @@ export type ExtractRoutesFromAPI<T> =

type ConvertToRoute<TRoute extends MinimalRoute> = {
[K in TRoute['path']]: {
[K2 in TRoute['method']]: K2 extends 'GET'
? (params: ExtractValidation<TRoute['query']>) => ExtractValidation<TRoute['response'][200]>
: (params: ExtractValidation<TRoute['body']>) => ExtractValidation<TRoute['response'][200 | 201]>;
[K2 in Extract<TRoute, { path: K }>['method']]: K2 extends 'GET'
? (
params: ExtractValidation<Extract<TRoute, { path: K; method: K2 }>['query']>,
) => ExtractValidation<Extract<TRoute, { path: K; method: K2 }>['response'][200]>
: K2 extends 'POST'
? (
params: ExtractValidation<Extract<TRoute, { path: K; method: K2 }>['body']>,
) => ExtractValidation<
200 extends keyof Extract<TRoute, { path: K; method: K2 }>['response']
? Extract<TRoute, { path: K; method: K2 }>['response'][200]
: 201 extends keyof Extract<TRoute, { path: K; method: K2 }>['response']
? Extract<TRoute, { path: K; method: K2 }>['response'][201]
: never
>
: never;
};
};

Expand Down Expand Up @@ -622,10 +634,12 @@ export class APIClass<
): APIClass<
TBasePath,
| TOperations
| ({
method: Method;
path: TPathPattern;
} & Omit<TOptions, 'response'>)
| Prettify<
{
method: Method;
path: TPathPattern;
} & Omit<TOptions, 'response'>
>
> {
this.addRoute([subpath], { tags: [], ...options, typed: true }, { [method.toLowerCase()]: { action } } as any);
this.registerTypedRoutes(method, subpath, options);
Expand Down Expand Up @@ -660,6 +674,12 @@ export class APIClass<
method: 'POST';
path: TPathPattern;
} & Omit<TOptions, 'response'>)
| Prettify<
{
method: 'POST';
path: TPathPattern;
} & TOptions
>
> {
return this.method('POST', subpath, options, action);
}
Expand Down
Loading