Skip to content

Commit 3176b56

Browse files
committed
feat: add bulk extend expiration date functionality for users
- Introduced commands and routes for bulk extending users expiration dates. - Updated user repository methods to handle bulk operations efficiently.
1 parent f3754db commit 3176b56

File tree

22 files changed

+442
-27
lines changed

22 files changed

+442
-27
lines changed

libs/contract/api/controllers/users.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ export const USERS_ROUTES = {
3333
REVOKE_SUBSCRIPTION: 'bulk/revoke-subscription',
3434
DELETE: 'bulk/delete',
3535
UPDATE_SQUADS: 'bulk/update-squads',
36+
EXTEND_EXPIRATION_DATE: 'bulk/extend-expiration-date',
3637
ALL: {
3738
UPDATE: 'bulk/all/update',
3839
RESET_TRAFFIC: 'bulk/all/reset-traffic',
40+
EXTEND_EXPIRATION_DATE: 'bulk/all/extend-expiration-date',
3941
},
4042
},
4143

libs/contract/api/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,11 @@ export const REST_API = {
156156
REVOKE_SUBSCRIPTION: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.BULK.REVOKE_SUBSCRIPTION}`,
157157
DELETE: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.BULK.DELETE}`,
158158
UPDATE_SQUADS: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.BULK.UPDATE_SQUADS}`,
159+
EXTEND_EXPIRATION_DATE: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.BULK.EXTEND_EXPIRATION_DATE}`,
159160
ALL: {
160161
UPDATE: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.BULK.ALL.UPDATE}`,
161162
RESET_TRAFFIC: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.BULK.ALL.RESET_TRAFFIC}`,
163+
EXTEND_EXPIRATION_DATE: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.BULK.ALL.EXTEND_EXPIRATION_DATE}`,
162164
},
163165
},
164166
STATS: {
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 { REST_API, USERS_ROUTES } from '../../../api';
5+
6+
export namespace BulkAllExtendExpirationDateCommand {
7+
export const url = REST_API.USERS.BULK.ALL.EXTEND_EXPIRATION_DATE;
8+
export const TSQ_url = url;
9+
10+
export const endpointDetails = getEndpointDetails(
11+
USERS_ROUTES.BULK.ALL.EXTEND_EXPIRATION_DATE,
12+
'post',
13+
'Extend expiration date for all users by days',
14+
);
15+
16+
export const RequestSchema = z.object({
17+
extendDays: z.number().int().min(1, 'Extend days must be greater than 0'),
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+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from './bulk-all-extend-expiration-date.command';
12
export * from './bulk-all-reset-traffic-users.command';
23
export * from './bulk-all-update-users.command';

libs/contract/commands/users/bulk/bulk-delete-users.command.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export namespace BulkDeleteUsersCommand {
1414
);
1515

1616
export const RequestSchema = z.object({
17-
uuids: z.array(z.string().uuid()),
17+
uuids: z
18+
.array(z.string().uuid())
19+
.min(1, 'Must be at least 1 user UUID')
20+
.max(500, 'Maximum 500 user UUIDs'),
1821
});
1922

2023
export type Request = z.infer<typeof RequestSchema>;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { z } from 'zod';
2+
3+
import { getEndpointDetails } from '../../../constants';
4+
import { REST_API, USERS_ROUTES } from '../../../api';
5+
6+
export namespace BulkExtendExpirationDateCommand {
7+
export const url = REST_API.USERS.BULK.EXTEND_EXPIRATION_DATE;
8+
export const TSQ_url = url;
9+
10+
export const endpointDetails = getEndpointDetails(
11+
USERS_ROUTES.BULK.EXTEND_EXPIRATION_DATE,
12+
'post',
13+
'Extend expiration date for specified users by days',
14+
);
15+
16+
export const RequestSchema = z.object({
17+
uuids: z
18+
.array(z.string().uuid())
19+
.min(1, 'Must be at least 1 user UUID')
20+
.max(500, 'Maximum 500 user UUIDs'),
21+
22+
extendDays: z
23+
.number()
24+
.int()
25+
.min(1, 'Extend days must be greater than 0')
26+
.max(9999, 'Maximum 9999 days'),
27+
});
28+
29+
export type Request = z.infer<typeof RequestSchema>;
30+
31+
export const ResponseSchema = z.object({
32+
response: z.object({
33+
affectedRows: z.number(),
34+
}),
35+
});
36+
37+
export type Response = z.infer<typeof ResponseSchema>;
38+
}

libs/contract/commands/users/bulk/bulk-reset-traffic-users.command.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export namespace BulkResetTrafficUsersCommand {
1414
);
1515

1616
export const RequestSchema = z.object({
17-
uuids: z.array(z.string().uuid()),
17+
uuids: z
18+
.array(z.string().uuid())
19+
.min(1, 'Must be at least 1 user UUID')
20+
.max(500, 'Maximum 500 user UUIDs'),
1821
});
1922

2023
export type Request = z.infer<typeof RequestSchema>;

libs/contract/commands/users/bulk/bulk-revoke-users-subscription.command.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export namespace BulkRevokeUsersSubscriptionCommand {
1414
);
1515

1616
export const RequestSchema = z.object({
17-
uuids: z.array(z.string().uuid()),
17+
uuids: z
18+
.array(z.string().uuid())
19+
.min(1, 'Must be at least 1 user UUID')
20+
.max(500, 'Maximum 500 user UUIDs'),
1821
});
1922

2023
export type Request = z.infer<typeof RequestSchema>;

libs/contract/commands/users/bulk/bulk-update-users-squads.command.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export namespace BulkUpdateUsersSquadsCommand {
1414
);
1515

1616
export const RequestSchema = z.object({
17-
uuids: z.array(z.string().uuid()),
17+
uuids: z
18+
.array(z.string().uuid())
19+
.min(1, 'Must be at least 1 user UUID')
20+
.max(500, 'Maximum 500 user UUIDs'),
1821
activeInternalSquads: z.array(z.string().uuid(), {
1922
invalid_type_error: 'Enabled internal squads must be an array of UUIDs',
2023
}),

libs/contract/commands/users/bulk/bulk-update-users.command.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export namespace BulkUpdateUsersCommand {
1616
);
1717

1818
export const RequestSchema = z.object({
19-
uuids: z.array(z.string().uuid()),
19+
uuids: z
20+
.array(z.string().uuid())
21+
.min(1, 'Must be at least 1 user UUID')
22+
.max(500, 'Maximum 500 user UUIDs'),
2023
fields: z.object({
2124
status: UsersSchema.shape.status.optional(),
2225
trafficLimitBytes: z.optional(

0 commit comments

Comments
 (0)