-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathupdateCategoryModeratorStatus.ts
50 lines (44 loc) · 1.7 KB
/
updateCategoryModeratorStatus.ts
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
import { flags } from '@oclif/command'
import chalk from 'chalk'
import ForumCommandBase from '../../base/ForumCommandBase'
export default class ForumUpdateCategoryModeratorStatusCommand extends ForumCommandBase {
static description = 'Update moderator status of a worker in relation to a category.'
static flags = {
categoryId: flags.integer({
char: 'c',
required: true,
description: 'Forum category id',
}),
workerId: flags.integer({
char: 'w',
required: true,
description: 'Forum working group worker id',
}),
status: flags.enum<'active' | 'disabled'>({
options: ['active', 'disabled'],
required: true,
description: 'Status of the moderator membership in the category',
}),
...ForumCommandBase.flags,
}
async run(): Promise<void> {
const api = await this.getOriginalApi()
const { categoryId, workerId, status } = this.parse(ForumUpdateCategoryModeratorStatusCommand).flags
const lead = await this.getRequiredLeadContext()
await this.ensureCategoryExists(categoryId)
await this.ensureWorkerExists(workerId)
this.jsonPrettyPrint(JSON.stringify({ categoryId, workerId, status }))
await this.requireConfirmation('Do you confirm the provided input?', true)
await this.sendAndFollowTx(
await this.getDecodedPair(lead.roleAccount),
api.tx.forum.updateCategoryMembershipOfModerator(workerId, categoryId, status === 'active')
)
this.log(
chalk.green(
`Worker ${chalk.magentaBright(workerId.toString())} moderation permissions for category ${chalk.magentaBright(
categoryId.toString()
)} successfully ${status === 'active' ? 'granted' : 'revoked'}`
)
)
}
}