-
Notifications
You must be signed in to change notification settings - Fork 7
/
agency.ts
48 lines (43 loc) · 1.48 KB
/
agency.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
import { ApiResponse } from '../models/ApiResponse';
import { AgencyDAO } from '../models/DAO/AgencyDAO';
import { User } from '../models/User';
const agency = (app: { [key: string]: any }): void => {
app.get('/agency/list', async (req: { [key: string]: any }, res: { [key: string]: any }) => {
const apiResponse = new ApiResponse();
const company = req.company;
const agency = req.agency;
const permission = req.permission;
new AgencyDAO()
.getAllAgenciesFrom(company, agency, permission)
.then((agencies: string[]) => {
apiResponse.responseText = JSON.stringify(agencies);
})
.catch((err) => {
apiResponse.statusCode = 500;
apiResponse.responseText = err.message;
apiResponse.errorMessage = err.message;
})
.finally(() => {
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
});
});
app.get('/agency/users', async (req: { [key: string]: any }, res: { [key: string]: any }) => {
const apiResponse = new ApiResponse();
const company = req.company;
const agency = req.agency;
new AgencyDAO()
.getAllUsersFromAgency(company, agency)
.then((users: User[]) => {
apiResponse.responseText = JSON.stringify(users.map((user: User) => user.toJson()));
})
.catch((err) => {
apiResponse.statusCode = 500;
apiResponse.responseText = err.message;
apiResponse.errorMessage = err.message;
})
.finally(() => {
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
});
});
};
export default agency;