Skip to content

Commit

Permalink
fix(signups): fixes an issue with casing on remove signups (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssilve1989 authored May 15, 2024
1 parent 73ff251 commit bd6bbfb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ describe('Remove Signup Command Handler', () => {
signupsRepository = fixture.get(SignupCollection);

interaction = createMock<ChatInputCommandInteraction<'cached' | 'raw'>>({
user: createMock<User>({ id: '1', toString: () => '<@1>' }),
options: createMock({}),
user: createMock<User>({
id: '1',
toString: () => '<@1>',
valueOf: () => '',
}),
options: {
getString: () => '',
},
valueOf: () => '',
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { plainToClass } from 'class-transformer';
import { APIUser, ChatInputCommandInteraction, User } from 'discord.js';
import { DiscordService } from '../../../../discord/discord.service.js';
import { Encounter } from '../../../../encounters/encounters.consts.js';
Expand All @@ -8,6 +9,7 @@ import { SignupCompositeKeyProps } from '../../../../firebase/models/signup.mode
import { SheetsService } from '../../../../sheets/sheets.service.js';
import { SIGNUP_MESSAGES } from '../../signup.consts.js';
import { RemoveSignupCommand } from './remove-signup.command.js';
import { RemoveSignupDto } from './remove-signup.dto.js';

@CommandHandler(RemoveSignupCommand)
class RemoveSignupCommandHandler
Expand Down Expand Up @@ -61,11 +63,11 @@ class RemoveSignupCommandHandler
}

private getOptions({ options }: ChatInputCommandInteraction) {
return {
return plainToClass(RemoveSignupDto, {
character: options.getString('character')!,
world: options.getString('world')!,
encounter: options.getString('encounter')! as Encounter,
};
});
}

private async canModifySignup(
Expand All @@ -80,7 +82,9 @@ class RemoveSignupCommandHandler
guildId,
});

if (hasRole) return true;
if (hasRole) {
return true;
}

const signup = await this.signupsRepository.findOne(options);

Expand Down
21 changes: 21 additions & 0 deletions src/commands/signup/subcommands/remove-signup/remove-signup.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { IsEnum, IsString } from 'class-validator';
import { ToLowercase } from '../../../../common/decorators/to-lowercase.js';
import { Encounter } from '../../../../encounters/encounters.consts.js';
import { SignupDocument } from '../../../../firebase/models/signup.model.js';

class RemoveSignupDto
implements Pick<SignupDocument, 'character' | 'world' | 'encounter'>
{
@IsString()
@ToLowercase()
character: string;

@IsEnum(Encounter)
encounter: Encounter;

@IsString()
@ToLowercase()
world: string;
}

export { RemoveSignupDto };

0 comments on commit bd6bbfb

Please sign in to comment.