This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcontroller.js
95 lines (85 loc) · 2.31 KB
/
controller.js
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
class Controller {
constructor(dataService) {
this._dataService = dataService;
}
async create(req, res, next){
try {
// there can be only 1!
let response = await this._dataService.exists();
if (response) {
response = await this._dataService.read();
res.status(302).json(response);
} else {
response = await this._dataService.create(req.body, req.currentUser);
res.status(201).json(response);
}
} catch (error) {
next(error);
}
}
async update(req, res, next){
try {
const response = await this._dataService.update(req.body, req.currentUser);
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async read(req, res, next){
try {
const response = await this._dataService.read();
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async current (req, res, next){
try {
const response = await this._dataService.current();
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async searchSubmissions(req, res, next) {
try {
const response = await this._dataService.searchSubmissions(req.params);
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async createSubmission(req, res, next) {
try {
const response = await this._dataService.createSubmission(req.body, req.currentUser);
res.status(201).json(response);
} catch (error) {
next(error);
}
}
async readSubmissionPublic(req, res, next){
try {
const response = await this._dataService.readSubmission(req.params.submissionId, true);
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async updateSubmission (req, res, next) {
try {
const response = await this._dataService.updateSubmission(req.params.submissionId, req.body, req.currentUser);
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async deleteSubmission (req, res, next) {
try {
const response = await this._dataService.deleteSubmission(req.params.submissionId, req.currentUser);
res.status(200).json(response);
} catch (error) {
next(error);
}
}
}
module.exports.Controller = Controller;