-
Notifications
You must be signed in to change notification settings - Fork 503
/
postController.ts
131 lines (106 loc) · 4.09 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { Body, Deprecated, File, FormField, Patch, Post, Query, Route, UploadedFile, UploadedFiles } 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('FileOptional')
public async postWithOptionalFile(@UploadedFile('optionalFile') optionalFile?: File): Promise<string> {
return optionalFile?.originalname ?? 'no file';
}
@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('ManyFilesInDifferentFields')
public async postWithDifferentFields(@UploadedFile('file_a') fileA: File, @UploadedFile('file_b') fileB: File): Promise<File[]> {
return [fileA, fileB];
}
@Post('ManyFilesInDifferentArrayFields')
public async postWithDifferentArrayFields(@UploadedFiles('files_a') filesA: File[], @UploadedFile('file_b') fileB: File, @UploadedFiles('files_c') filesC: File[]): Promise<File[][]> {
return [filesA, [fileB], filesC];
}
@Post('MixedFormDataWithFilesContainsOptionalFile')
public async mixedFormDataWithFile(
@FormField('username') username: string,
@UploadedFile('avatar') avatar: File,
@UploadedFile('optionalAvatar') optionalAvatar?: File,
): Promise<{ username: string; avatar: File; optionalAvatar?: File }> {
return { username, avatar, optionalAvatar };
}
/**
*
* @param aFile File description of multipart
* @param a FormField description of multipart
* @param c
*/
@Post('DescriptionOfFileAndFormFields')
public async postWithFileAndParams(@UploadedFile('file') aFile: File, @FormField('a') a: string, @FormField('c') c: string): Promise<File> {
return aFile;
}
@Post('DeprecatedFormField')
public async postWithDeprecatedParam(@FormField('a') a: string, @FormField('dontUse') @Deprecated() dontUse?: string): Promise<TestModel> {
return new ModelService().getModel();
}
@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;
}
}