-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Add new decorator ApiCallbacks
- Loading branch information
1 parent
1b38cea
commit 207e7a6
Showing
11 changed files
with
160 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { DECORATORS } from '../constants'; | ||
import { createMixedDecorator } from './helpers'; | ||
import { CallBackObject } from '../interfaces/callback-object.interface' | ||
|
||
export function ApiCallbacks(...callbackObject: Array<CallBackObject<any>>) { | ||
return createMixedDecorator(DECORATORS.API_CALLBACKS, callbackObject); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Type } from '@nestjs/common'; | ||
import { DECORATORS } from '../constants'; | ||
import { getSchemaPath } from '../utils'; | ||
import { CallBackObject } from '../interfaces/callback-object.interface' | ||
|
||
export const exploreApiCallbacksMetadata = ( | ||
instance: object, | ||
prototype: Type<unknown>, | ||
method: object | ||
) => { | ||
const callbacksData = Reflect.getMetadata(DECORATORS.API_CALLBACKS, method); | ||
if (!callbacksData) return callbacksData; | ||
|
||
return callbacksData.reduce((acc, callbackData: CallBackObject<string | Function>) => { | ||
const { | ||
name: eventName, | ||
callbackUrl, | ||
method: callbackMethod, | ||
requestBody, | ||
expectedResponse | ||
} = callbackData; | ||
return { | ||
...acc, | ||
[eventName]: { | ||
[callbackUrl]: { | ||
[callbackMethod]: { | ||
requestBody: { | ||
required: true, | ||
content: { | ||
'application/json': { | ||
schema: { | ||
$ref: getSchemaPath(requestBody.type) | ||
} | ||
} | ||
} | ||
}, | ||
responses: { | ||
[expectedResponse.status]: { | ||
description: | ||
expectedResponse.description || | ||
'Your server returns this code if it accepts the callback' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
}, {}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export interface CallBackObject<T> { | ||
name: string, | ||
callbackUrl: string, | ||
method: string, | ||
requestBody: { | ||
type: T | ||
}, | ||
expectedResponse: { | ||
status: number | ||
description?: string | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters