Skip to content

Commit e382246

Browse files
committed
feat: add reset traffic functionality for nodes
1 parent 74c2531 commit e382246

File tree

14 files changed

+142
-10
lines changed

14 files changed

+142
-10
lines changed

libs/contract/api/controllers/nodes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const NODES_ROUTES = {
1313
ENABLE: (uuid: string) => `${uuid}/${NODE_ACTIONS_ROUTE}/enable`,
1414
DISABLE: (uuid: string) => `${uuid}/${NODE_ACTIONS_ROUTE}/disable`,
1515
RESTART: (uuid: string) => `${uuid}/${NODE_ACTIONS_ROUTE}/restart`,
16+
RESET_TRAFFIC: (uuid: string) => `${uuid}/${NODE_ACTIONS_ROUTE}/reset-traffic`,
1617

1718
RESTART_ALL: `${NODE_ACTIONS_ROUTE}/restart-all`,
1819
REORDER: `${NODE_ACTIONS_ROUTE}/reorder`,

libs/contract/api/routes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export const REST_API = {
6161
uuid,
6262
)}`,
6363
RESTART_ALL: `${ROOT}/${CONTROLLERS.NODES_CONTROLLER}/${CONTROLLERS.NODES_ROUTES.ACTIONS.RESTART_ALL}`,
64+
RESET_TRAFFIC: (uuid: string) =>
65+
`${ROOT}/${CONTROLLERS.NODES_CONTROLLER}/${CONTROLLERS.NODES_ROUTES.ACTIONS.RESET_TRAFFIC(
66+
uuid,
67+
)}`,
6468
REORDER: `${ROOT}/${CONTROLLERS.NODES_CONTROLLER}/${CONTROLLERS.NODES_ROUTES.ACTIONS.REORDER}`,
6569
},
6670

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './disable.command';
22
export * from './enable.command';
33
export * from './reorder.command';
4+
export * from './reset-traffic.command';
45
export * from './restart-all.command';
56
export * from './restart.command';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { z } from 'zod';
2+
3+
import { getEndpointDetails } from '../../../constants';
4+
import { NODES_ROUTES, REST_API } from '../../../api';
5+
6+
export namespace ResetNodeTrafficCommand {
7+
export const url = REST_API.NODES.ACTIONS.RESET_TRAFFIC;
8+
export const TSQ_url = url(':uuid');
9+
10+
export const endpointDetails = getEndpointDetails(
11+
NODES_ROUTES.ACTIONS.RESET_TRAFFIC(':uuid'),
12+
'post',
13+
'Reset Node Traffic',
14+
);
15+
16+
export const RequestSchema = z.object({
17+
uuid: z.string().uuid(),
18+
});
19+
20+
export type Request = z.infer<typeof RequestSchema>;
21+
22+
export const ResponseSchema = z.object({
23+
response: z.object({
24+
eventSent: z.boolean(),
25+
}),
26+
});
27+
28+
export type Response = z.infer<typeof ResponseSchema>;
29+
}

libs/contract/constants/errors/errors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,4 +1009,9 @@ export const ERRORS = {
10091009
message: 'Get computed config profile by UUID error',
10101010
httpCode: 500,
10111011
},
1012+
RESET_NODE_TRAFFIC_ERROR: {
1013+
code: 'A201',
1014+
message: 'Reset node traffic error',
1015+
httpCode: 500,
1016+
},
10121017
} as const;

libs/contract/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@remnawave/backend-contract",
3-
"version": "2.2.31",
3+
"version": "2.2.32",
44
"public": true,
55
"license": "AGPL-3.0-only",
66
"description": "A contract library for Remnawave Backend. It can be used in backend and frontend.",

src/modules/nodes/dtos/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from './enable-node.request.dto';
55
export * from './get-all-nodes.dto';
66
export * from './get-one-node.dto';
77
export * from './reorder.dto';
8+
export * from './reset-traffic.request.dto';
89
export * from './restart-all.dto';
910
export * from './restart-node.request.dto';
1011
export * from './update-node.dto';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { createZodDto } from 'nestjs-zod';
2+
3+
import { ResetNodeTrafficCommand } from '@contract/commands';
4+
5+
export class ResetNodeTrafficRequestDto extends createZodDto(
6+
ResetNodeTrafficCommand.RequestSchema,
7+
) {}
8+
export class ResetNodeTrafficResponseDto extends createZodDto(
9+
ResetNodeTrafficCommand.ResponseSchema,
10+
) {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export class BaseEventResponseModel {
2+
public eventSent: boolean;
3+
4+
constructor(eventSent: boolean) {
5+
this.eventSent = eventSent;
6+
}
7+
}

src/modules/nodes/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './base-event.response.model';
12
export * from './create-node.response.model';
23
export * from './delete-node.response.model';
34
export * from './get-all-nodes.response.model';

0 commit comments

Comments
 (0)