-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGitTemplate.ts
More file actions
80 lines (71 loc) · 2.09 KB
/
Copy pathGitTemplate.ts
File metadata and controls
80 lines (71 loc) · 2.09 KB
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
import {
Authorized,
Body,
CurrentUser,
Delete,
Get,
HttpCode,
JsonController,
OnNull,
OnUndefined,
Param,
Post,
QueryParams
} from 'routing-controllers';
import { ResponseSchema } from 'routing-controllers-openapi';
import { BaseFilter, GitTemplate, GitTemplateListChunk, User } from '../model';
import { gitTemplateService, hackathonService } from '../service';
import { searchConditionOf } from '../utility';
@JsonController('/hackathon/:name/git-template')
export class GitTemplateController {
service = gitTemplateService;
@Post()
@Authorized()
@HttpCode(201)
@ResponseSchema(GitTemplate)
async createOne(
@CurrentUser() createdBy: User,
@Param('name') name: string,
@Body() { html_url }: GitTemplate
) {
const hackathon = await hackathonService.ensureAdmin(createdBy.id, name);
const repository = await gitTemplateService.getRepository(html_url);
return this.service.createOne({ ...repository, hackathon }, createdBy);
}
@Delete('/:id')
@Authorized()
@OnUndefined(204)
async deleteOne(
@CurrentUser() deletedBy: User,
@Param('name') name: string,
@Param('id') id: number
) {
await hackathonService.ensureAdmin(deletedBy.id, name);
await this.service.deleteOne(id, deletedBy);
}
@Get('/:id')
@OnNull(404)
@ResponseSchema(GitTemplate)
getOne(@Param('id') id: number) {
return this.service.getOne(id);
}
@Get()
@ResponseSchema(GitTemplateListChunk)
getList(@Param('name') name: string, @QueryParams() { keywords, ...filter }: BaseFilter) {
const where = searchConditionOf<GitTemplate>(
[
'name',
'full_name',
'html_url',
'default_branch',
'languages',
'topics',
'description',
'homepage'
],
keywords,
{ hackathon: { name } }
);
return this.service.getList({ keywords, ...filter }, where);
}
}