aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/server-commands/src/users/registrations-command.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/server-commands/src/users/registrations-command.ts')
-rw-r--r--packages/server-commands/src/users/registrations-command.ts157
1 files changed, 157 insertions, 0 deletions
diff --git a/packages/server-commands/src/users/registrations-command.ts b/packages/server-commands/src/users/registrations-command.ts
new file mode 100644
index 000000000..2111fbd39
--- /dev/null
+++ b/packages/server-commands/src/users/registrations-command.ts
@@ -0,0 +1,157 @@
1import { pick } from '@peertube/peertube-core-utils'
2import {
3 HttpStatusCode,
4 ResultList,
5 UserRegistration,
6 UserRegistrationRequest,
7 UserRegistrationUpdateState
8} from '@peertube/peertube-models'
9import { unwrapBody } from '../requests/index.js'
10import { AbstractCommand, OverrideCommandOptions } from '../shared/index.js'
11
12export class RegistrationsCommand extends AbstractCommand {
13
14 register (options: OverrideCommandOptions & Partial<UserRegistrationRequest> & Pick<UserRegistrationRequest, 'username'>) {
15 const { password = 'password', email = options.username + '@example.com' } = options
16 const path = '/api/v1/users/register'
17
18 return this.postBodyRequest({
19 ...options,
20
21 path,
22 fields: {
23 ...pick(options, [ 'username', 'displayName', 'channel' ]),
24
25 password,
26 email
27 },
28 implicitToken: false,
29 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
30 })
31 }
32
33 requestRegistration (
34 options: OverrideCommandOptions & Partial<UserRegistrationRequest> & Pick<UserRegistrationRequest, 'username' | 'registrationReason'>
35 ) {
36 const { password = 'password', email = options.username + '@example.com' } = options
37 const path = '/api/v1/users/registrations/request'
38
39 return unwrapBody<UserRegistration>(this.postBodyRequest({
40 ...options,
41
42 path,
43 fields: {
44 ...pick(options, [ 'username', 'displayName', 'channel', 'registrationReason' ]),
45
46 password,
47 email
48 },
49 implicitToken: false,
50 defaultExpectedStatus: HttpStatusCode.OK_200
51 }))
52 }
53
54 // ---------------------------------------------------------------------------
55
56 accept (options: OverrideCommandOptions & { id: number } & UserRegistrationUpdateState) {
57 const { id } = options
58 const path = '/api/v1/users/registrations/' + id + '/accept'
59
60 return this.postBodyRequest({
61 ...options,
62
63 path,
64 fields: pick(options, [ 'moderationResponse', 'preventEmailDelivery' ]),
65 implicitToken: true,
66 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
67 })
68 }
69
70 reject (options: OverrideCommandOptions & { id: number } & UserRegistrationUpdateState) {
71 const { id } = options
72 const path = '/api/v1/users/registrations/' + id + '/reject'
73
74 return this.postBodyRequest({
75 ...options,
76
77 path,
78 fields: pick(options, [ 'moderationResponse', 'preventEmailDelivery' ]),
79 implicitToken: true,
80 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
81 })
82 }
83
84 // ---------------------------------------------------------------------------
85
86 delete (options: OverrideCommandOptions & {
87 id: number
88 }) {
89 const { id } = options
90 const path = '/api/v1/users/registrations/' + id
91
92 return this.deleteRequest({
93 ...options,
94
95 path,
96 implicitToken: true,
97 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
98 })
99 }
100
101 // ---------------------------------------------------------------------------
102
103 list (options: OverrideCommandOptions & {
104 start?: number
105 count?: number
106 sort?: string
107 search?: string
108 } = {}) {
109 const path = '/api/v1/users/registrations'
110
111 return this.getRequestBody<ResultList<UserRegistration>>({
112 ...options,
113
114 path,
115 query: pick(options, [ 'start', 'count', 'sort', 'search' ]),
116 implicitToken: true,
117 defaultExpectedStatus: HttpStatusCode.OK_200
118 })
119 }
120
121 // ---------------------------------------------------------------------------
122
123 askSendVerifyEmail (options: OverrideCommandOptions & {
124 email: string
125 }) {
126 const { email } = options
127 const path = '/api/v1/users/registrations/ask-send-verify-email'
128
129 return this.postBodyRequest({
130 ...options,
131
132 path,
133 fields: { email },
134 implicitToken: false,
135 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
136 })
137 }
138
139 verifyEmail (options: OverrideCommandOptions & {
140 registrationId: number
141 verificationString: string
142 }) {
143 const { registrationId, verificationString } = options
144 const path = '/api/v1/users/registrations/' + registrationId + '/verify-email'
145
146 return this.postBodyRequest({
147 ...options,
148
149 path,
150 fields: {
151 verificationString
152 },
153 implicitToken: false,
154 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
155 })
156 }
157}