forked from lukeautry/tsoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postController.ts
91 lines (72 loc) · 2.53 KB
/
postController.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { Body, Patch, Post, Query, Route, File, UploadedFile, UploadedFiles, FormField } from '@tsoa/runtime';
import { ModelService } from '../services/modelService';
import { GenericRequest, TestClassModel, TestModel } from '../testModel';
@Route('PostTest')
export class PostTestController {
private statusCode?: number = undefined;
public setStatus(statusCode: number) {
this.statusCode = statusCode;
}
public getStatus() {
return this.statusCode;
}
public getHeaders() {
return [];
}
@Post()
public async postModel(@Body() model: TestModel): Promise<TestModel> {
return model;
}
@Post('Object')
public async postObject(@Body() body: { obj: { [key: string]: string } }): Promise<{ [key: string]: string }> {
return body.obj;
}
@Patch()
public async updateModel(@Body() model: TestModel): Promise<TestModel> {
return new ModelService().getModel();
}
@Post('WithDifferentReturnCode')
public async postWithDifferentReturnCode(@Body() model: TestModel): Promise<TestModel> {
this.setStatus(201);
return model;
}
@Post('WithClassModel')
public async postClassModel(@Body() model: TestClassModel): Promise<TestClassModel> {
const augmentedModel = new TestClassModel('test', 'test2', 'test3', 'test4', 'test5');
augmentedModel.id = 700;
return augmentedModel;
}
@Post('File')
public async postWithFile(@UploadedFile('someFile') aFile: File): Promise<File> {
return aFile;
}
@Post('FileWithoutName')
public async postWithFileWithoutName(@UploadedFile() aFile: File): Promise<File> {
return aFile;
}
@Post('ManyFilesAndFormFields')
public async postWithFiles(@UploadedFiles('someFiles') files: File[], @FormField('a') a: string, @FormField('c') c: string): Promise<File[]> {
return files;
}
@Post('Location')
public async postModelAtLocation(): Promise<TestModel> {
return new ModelService().getModel();
}
@Post('Multi')
public async postWithMultiReturn(): Promise<TestModel[]> {
const model = new ModelService().getModel();
return [model, model];
}
@Post('WithId/{id}')
public async postWithId(id: number): Promise<TestModel> {
return new ModelService().getModel();
}
@Post('WithBodyAndQueryParams')
public async postWithBodyAndQueryParams(@Body() model: TestModel, @Query() query: string): Promise<TestModel> {
return new ModelService().getModel();
}
@Post('GenericBody')
public async getGenericRequest(@Body() genericReq: GenericRequest<TestModel>): Promise<TestModel> {
return genericReq.value;
}
}