forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagents.controller.ts
More file actions
84 lines (73 loc) · 1.88 KB
/
Copy pathagents.controller.ts
File metadata and controls
84 lines (73 loc) · 1.88 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
81
82
83
84
import type { Request, Response } from "express";
import { AppError } from "../../common/http/app-error";
import type { ApiSuccessResponse } from "../../common/types/api-response";
import type { AgentStatus, CreateAgentInput } from "./agents.types";
import { agentsService } from "./agents.service";
export const listAgents = (
_request: Request,
response: Response<
ApiSuccessResponse<ReturnType<typeof agentsService.listAgents>>
>,
): void => {
response.status(200).json({
success: true,
data: agentsService.listAgents(),
});
};
export const getAgentById = (
request: Request<{ id: string }>,
response: Response,
): void => {
const agent = agentsService.getAgentById(request.params.id);
if (!agent) {
throw new AppError(
404,
`Agent not found: ${request.params.id}`,
undefined,
"NOT_FOUND",
);
}
response.status(200).json({
success: true,
data: { agent },
});
};
export const createAgent = (
request: Request<Record<string, never>, unknown, CreateAgentInput>,
response: Response,
): void => {
const agent = agentsService.createAgent(request.body);
response.status(201).json({
success: true,
data: { agent },
});
};
export const updateAgentStatus = (
request: Request<{ id: string }, unknown, { status: AgentStatus }>,
response: Response<
ApiSuccessResponse<ReturnType<typeof agentsService.updateAgentStatus>>
>,
): void => {
const data = agentsService.updateAgentStatus(
request.params.id,
request.body.status,
);
response.status(200).json({
success: true,
data,
});
};
export const deleteAgent = (
request: Request<{ id: string }>,
response: Response,
): void => {
if (!agentsService.deleteAgent(request.params.id)) {
throw new AppError(
404,
`Agent not found: ${request.params.id}`,
undefined,
"NOT_FOUND",
);
}
response.status(204).end();
};