123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import ExitCodes from '../ExitCodes'
- import { flags } from '@oclif/command'
- import { AvailableGroups, GroupMember, OpeningDetails, ApplicationDetails } from '../Types'
- import chalk from 'chalk'
- import { memberHandle } from '../helpers/display'
- import WorkingGroupCommandBase from './WorkingGroupCommandBase'
- export default abstract class WorkingGroupsCommandBase extends WorkingGroupCommandBase {
- static flags = {
- group: flags.enum({
- char: 'g',
- description:
- 'The working group context in which the command should be executed\n' +
- `Available values are: ${AvailableGroups.join(', ')}.`,
- required: false,
- options: [...AvailableGroups],
- }),
- ...WorkingGroupCommandBase.flags,
- }
- async promptForApplicationsToAccept(opening: OpeningDetails): Promise<number[]> {
- const acceptedApplications = await this.simplePrompt<number[]>({
- message: 'Select succesful applicants',
- type: 'checkbox',
- choices: opening.applications.map((a) => ({
- name: ` ${a.applicationId}: ${memberHandle(a.member)}`,
- value: a.applicationId,
- })),
- })
- return acceptedApplications
- }
- async getOpeningForLeadAction(id: number): Promise<OpeningDetails> {
- const opening = await this.getApi().groupOpening(this.group, id)
- if (!opening.type.isOfType('Regular')) {
- this.error('A lead can only manage Regular openings!', { exit: ExitCodes.AccessDenied })
- }
- return opening
- }
-
- validateOpeningForLeadAction = this.getOpeningForLeadAction
- async getApplicationForLeadAction(id: number): Promise<ApplicationDetails> {
- const application = await this.getApi().groupApplication(this.group, id)
- const opening = await this.getApi().groupOpening(this.group, application.openingId)
- if (!opening.type.isOfType('Regular')) {
- this.error('A lead can only manage Regular opening applications!', { exit: ExitCodes.AccessDenied })
- }
- return application
- }
- async getWorkerForLeadAction(id: number, requireStakeProfile = false): Promise<GroupMember> {
- const groupMember = await this.getApi().groupMember(this.group, id)
- const groupLead = await this.getApi().groupLead(this.group)
- if (groupLead?.workerId.eq(groupMember.workerId)) {
- this.error('A lead cannot manage his own role this way!', { exit: ExitCodes.AccessDenied })
- }
- if (requireStakeProfile && !groupMember.stake) {
- this.error('This worker has no associated role stake profile!', { exit: ExitCodes.InvalidInput })
- }
- return groupMember
- }
-
-
- async getWorkerWithStakeForLeadAction(id: number): Promise<GroupMember & Required<Pick<GroupMember, 'stake'>>> {
- return (await this.getWorkerForLeadAction(id, true)) as GroupMember & Required<Pick<GroupMember, 'stake'>>
- }
- async init(): Promise<void> {
- await super.init()
- const { flags } = this.parse(this.constructor as typeof WorkingGroupsCommandBase)
- if (flags.group) {
- this._group = flags.group
- }
- this.log(chalk.magentaBright('Current Group: ' + this.group))
- }
- }
|