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
132 lines (116 loc) · 3.54 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
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
132
const EventEmitter = require('events');
const events = require('./events');
class Controller extends EventEmitter {
constructor(dataService) {
super();
this._dataService = dataService;
}
async current(req, res, next) {
try {
const response = await this._dataService.current();
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async createSubmissionStatus (req, res, next) {
try {
const response = await this._dataService.createSubmissionStatus(req.body, req.params.submissionId, req.currentUser);
this.emit(events.STATUS_CREATED, response);
res.status(201).json(response);
} catch (error) {
next(error);
}
}
async readSubmissionStatuses(req, res, next){
try {
const response = await this._dataService.readSubmissionStatuses(req.params.submissionId);
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async createSubmissionStatusNote(req, res, next){
try {
const response = await this._dataService.createSubmissionStatusNote(req.body, req.params.statusId, req.currentUser);
res.status(201).json(response);
} catch (error) {
next(error);
}
}
async readSubmissionStatusNotes (req, res, next){
try {
const response = await this._dataService.readSubmissionStatusNotes(req.params.statusId);
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async createSubmissionNote(req, res, next) {
try {
const response = await this._dataService.createSubmissionNote(req.body, req.params.submissionId, req.currentUser);
res.status(201).json(response);
} catch (error) {
next(error);
}
}
async readSubmissionNotes(req, res, next) {
try {
const response = await this._dataService.readSubmissionNotes(req.params.submissionId);
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async readCurrentStatusCodes(req, res, next) {
try {
const enabled = ['true','false'].includes(req.query.enabled) ? req.query.enabled === 'true' : undefined;
const response = await this._dataService.readCurrentStatusCodes(enabled);
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async updateCurrentStatusCodes(req, res, next) {
try {
const response = await this._dataService.updateCurrentStatusCodes(req.body, req.currentUser);
res.status(201).json(response);
} catch (error) {
next(error);
}
}
async createSettings(req, res, next){
try {
const response = await this._dataService.createSettings(req.body, req.currentUser);
res.status(201).json(response);
} catch (error) {
next(error);
}
}
async updateSettings (req, res, next) {
try {
const response = await this._dataService.updateSettings(req.params.name, req.body, req.currentUser);
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async readSettings(req, res, next) {
try {
const response = await this._dataService.readSettings(req.params.name);
res.status(200).json(response);
} catch (error) {
next(error);
}
}
async allSettings(req, res, next){
try {
const enabled = ['true','false'].includes(req.query.enabled) ? req.query.enabled === 'true' : undefined;
const response = await this._dataService.allSettings(enabled);
res.status(200).json(response);
} catch (error) {
next(error);
}
}
}
module.exports = Controller;