forked from lukeautry/tsoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostController.ts
71 lines (56 loc) · 1.88 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
import { Body, Patch, Post, Query, Route } from '../../../src';
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;
}
@Patch()
public async updateModel(@Body() model: TestModel): Promise<TestModel> {
return await 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('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;
}
}