| 4 | |
| 5 | @Route('PostTest') |
| 6 | export class PostTestController { |
| 7 | private statusCode?: number = undefined; |
| 8 | |
| 9 | public setStatus(statusCode: number) { |
| 10 | this.statusCode = statusCode; |
| 11 | } |
| 12 | |
| 13 | public getStatus() { |
| 14 | return this.statusCode; |
| 15 | } |
| 16 | |
| 17 | public getHeaders() { |
| 18 | return []; |
| 19 | } |
| 20 | |
| 21 | @Post() |
| 22 | public async postModel(@Body() model: TestModel): Promise<TestModel> { |
| 23 | return model; |
| 24 | } |
| 25 | |
| 26 | @Post('Object') |
| 27 | public async postObject(@Body() body: { obj: { [key: string]: string } }): Promise<{ [key: string]: string }> { |
| 28 | return body.obj; |
| 29 | } |
| 30 | |
| 31 | @Patch() |
| 32 | public async updateModel(@Body() model: TestModel): Promise<TestModel> { |
| 33 | return new ModelService().getModel(); |
| 34 | } |
| 35 | |
| 36 | @Post('WithDifferentReturnCode') |
| 37 | public async postWithDifferentReturnCode(@Body() model: TestModel): Promise<TestModel> { |
| 38 | this.setStatus(201); |
| 39 | return model; |
| 40 | } |
| 41 | |
| 42 | @Post('WithClassModel') |
| 43 | public async postClassModel(@Body() model: TestClassModel): Promise<TestClassModel> { |
| 44 | const augmentedModel = new TestClassModel('test', 'test2', 'test3', 'test4', 'test5'); |
| 45 | augmentedModel.id = 700; |
| 46 | |
| 47 | return augmentedModel; |
| 48 | } |
| 49 | |
| 50 | @Post('File') |
| 51 | public async postWithFile(@UploadedFile('someFile') aFile: File): Promise<File> { |
| 52 | return aFile; |
| 53 | } |
| 54 | |
| 55 | @Post('FileOptional') |
| 56 | public async postWithOptionalFile(@UploadedFile('optionalFile') optionalFile?: File): Promise<string> { |
| 57 | return optionalFile?.originalname ?? 'no file'; |
| 58 | } |
| 59 | |
| 60 | @Post('FileWithoutName') |
| 61 | public async postWithFileWithoutName(@UploadedFile() aFile: File): Promise<File> { |
| 62 | return aFile; |
| 63 | } |