@@ -11,73 +11,85 @@ export namespace UpdateUserCommand {
11
11
export const endpointDetails = getEndpointDetails (
12
12
USERS_ROUTES . UPDATE ,
13
13
'patch' ,
14
- 'Update a user' ,
14
+ 'Update a user by UUID or username ' ,
15
15
) ;
16
16
17
- export const RequestSchema = z . object ( {
18
- uuid : z . string ( ) . uuid ( ) ,
19
- status : z
20
- . enum ( [ USERS_STATUS . ACTIVE , USERS_STATUS . DISABLED ] , {
21
- errorMap : ( ) => ( {
22
- message :
23
- "You can't change status to LIMITED or EXPIRED. These statuses handled by Remnawave." ,
24
- } ) ,
25
- } )
17
+ export const RequestSchema = z
18
+ . object ( {
19
+ username : z . optional ( z . string ( ) . describe ( 'Username of the user' ) ) ,
20
+ uuid : z . optional (
21
+ z
22
+ . string ( )
23
+ . uuid ( )
24
+ . describe (
25
+ 'UUID of the user. UUID has higher priority than username, so if both are provided, username will be ignored.' ,
26
+ ) ,
27
+ ) ,
28
+ status : z
29
+ . enum ( [ USERS_STATUS . ACTIVE , USERS_STATUS . DISABLED ] , {
30
+ errorMap : ( ) => ( {
31
+ message :
32
+ "You can't change status to LIMITED or EXPIRED. These statuses handled by Remnawave." ,
33
+ } ) ,
34
+ } )
26
35
27
- . optional ( ) ,
28
- trafficLimitBytes : z
29
- . number ( {
30
- invalid_type_error : 'Traffic limit must be a number' ,
31
- } )
32
- . int ( 'Traffic limit must be an integer' )
33
- . min ( 0 , 'Traffic limit must be greater than 0' )
34
- . describe ( 'Traffic limit in bytes. 0 - unlimited' )
35
- . optional ( ) ,
36
- trafficLimitStrategy : UsersSchema . shape . trafficLimitStrategy
37
- . describe ( 'Traffic limit reset strategy' )
38
- . superRefine ( ( val , ctx ) => {
39
- if ( val && ! Object . values ( RESET_PERIODS ) . includes ( val ) ) {
40
- ctx . addIssue ( {
41
- code : z . ZodIssueCode . invalid_enum_value ,
42
- message : 'Invalid traffic limit strategy' ,
43
- path : [ 'trafficLimitStrategy' ] ,
44
- received : val ,
45
- options : Object . values ( RESET_PERIODS ) ,
46
- } ) ;
47
- }
48
- } )
49
- . optional ( ) ,
50
- expireAt : z
51
- . string ( )
52
- . datetime ( { local : true , offset : true , message : 'Invalid date format' } )
53
- . transform ( ( str ) => new Date ( str ) )
54
- . refine ( ( date ) => date > new Date ( ) , {
55
- message : 'Expiration date cannot be in the past' ,
56
- } )
57
- . describe ( 'Expiration date: 2025-01-17T15:38:45.065Z' )
58
- . optional ( ) ,
59
- description : z . optional ( z . string ( ) . nullable ( ) ) ,
60
- tag : z . optional (
61
- z
36
+ . optional ( ) ,
37
+ trafficLimitBytes : z
38
+ . number ( {
39
+ invalid_type_error : 'Traffic limit must be a number' ,
40
+ } )
41
+ . int ( 'Traffic limit must be an integer' )
42
+ . min ( 0 , 'Traffic limit must be greater than 0' )
43
+ . describe ( 'Traffic limit in bytes. 0 - unlimited' )
44
+ . optional ( ) ,
45
+ trafficLimitStrategy : UsersSchema . shape . trafficLimitStrategy
46
+ . describe ( 'Traffic limit reset strategy' )
47
+ . superRefine ( ( val , ctx ) => {
48
+ if ( val && ! Object . values ( RESET_PERIODS ) . includes ( val ) ) {
49
+ ctx . addIssue ( {
50
+ code : z . ZodIssueCode . invalid_enum_value ,
51
+ message : 'Invalid traffic limit strategy' ,
52
+ path : [ 'trafficLimitStrategy' ] ,
53
+ received : val ,
54
+ options : Object . values ( RESET_PERIODS ) ,
55
+ } ) ;
56
+ }
57
+ } )
58
+ . optional ( ) ,
59
+ expireAt : z
62
60
. string ( )
63
- . regex (
64
- / ^ [ A - Z 0 - 9 _ ] + $ / ,
65
- 'Tag can only contain uppercase letters, numbers, underscores' ,
66
- )
67
- . max ( 16 , 'Tag must be less than 16 characters' )
68
- . nullable ( ) ,
69
- ) ,
70
- telegramId : z . optional ( z . number ( ) . int ( ) . nullable ( ) ) ,
71
- email : z . optional ( z . string ( ) . email ( 'Invalid email format' ) . nullable ( ) ) ,
72
- hwidDeviceLimit : z . optional (
73
- z . number ( ) . int ( ) . min ( 0 , 'Device limit must be non-negative' ) . nullable ( ) ,
74
- ) ,
75
- activeInternalSquads : z
76
- . array ( z . string ( ) . uuid ( ) , {
77
- invalid_type_error : 'Enabled internal squads must be an array of UUIDs' ,
78
- } )
79
- . optional ( ) ,
80
- } ) ;
61
+ . datetime ( { local : true , offset : true , message : 'Invalid date format' } )
62
+ . transform ( ( str ) => new Date ( str ) )
63
+ . refine ( ( date ) => date > new Date ( ) , {
64
+ message : 'Expiration date cannot be in the past' ,
65
+ } )
66
+ . describe ( 'Expiration date: 2025-01-17T15:38:45.065Z' )
67
+ . optional ( ) ,
68
+ description : z . optional ( z . string ( ) . nullable ( ) ) ,
69
+ tag : z . optional (
70
+ z
71
+ . string ( )
72
+ . regex (
73
+ / ^ [ A - Z 0 - 9 _ ] + $ / ,
74
+ 'Tag can only contain uppercase letters, numbers, underscores' ,
75
+ )
76
+ . max ( 16 , 'Tag must be less than 16 characters' )
77
+ . nullable ( ) ,
78
+ ) ,
79
+ telegramId : z . optional ( z . number ( ) . int ( ) . nullable ( ) ) ,
80
+ email : z . optional ( z . string ( ) . email ( 'Invalid email format' ) . nullable ( ) ) ,
81
+ hwidDeviceLimit : z . optional (
82
+ z . number ( ) . int ( ) . min ( 0 , 'Device limit must be non-negative' ) . nullable ( ) ,
83
+ ) ,
84
+ activeInternalSquads : z
85
+ . array ( z . string ( ) . uuid ( ) , {
86
+ invalid_type_error : 'Enabled internal squads must be an array of UUIDs' ,
87
+ } )
88
+ . optional ( ) ,
89
+ } )
90
+ . refine ( ( data ) => data . uuid || data . username , {
91
+ message : 'Either uuid or username must be provided' ,
92
+ } ) ;
81
93
82
94
export type Request = z . infer < typeof RequestSchema > ;
83
95
0 commit comments