-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoleController.js
More file actions
44 lines (34 loc) · 1.11 KB
/
Copy pathRoleController.js
File metadata and controls
44 lines (34 loc) · 1.11 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
import { RoleRepository } from "../repository";
import { GlobalHandler, ThrowableError, } from "../utils";
export default class ProfileController {
constructor(){
this.repository = new RoleRepository();
}
async listRoles(req, res) {
const filters = req.filters;
let roles = await this.repository.findAll(filters)
res.send(roles)
}
async saveRole(req, res) {
try {
const role = req.body;
let savedRole = await this.repository.store(role)
res.send(savedRole)
} catch (error){
const sanitizedError = GlobalHandler.handle(error);
res.status(sanitizedError.code).send(sanitizedError)
}
}
async deleteRole(req, res) {
try {
const { id } = req.params;
await this.repository.delete(id)
res.json({
message: `Role with id ${id} successful deleted!`
})
} catch (error){
const sanitizedError = GlobalHandler.handle(error);
res.status(sanitizedError.code).send(sanitizedError)
}
}
}