Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ describe('ClanRoleService.checkVotingOnExpire', () => {
// Player should have updated clanRole_id
const updatedPlayer = await playerModel.findById(player._id);
expect(updatedPlayer.clanRole_id.toString()).toBe(role_id.toString());
expect((roleService as any).votingService.finalizeVoting).toHaveBeenCalledWith(
votingDto._id,
);

expect(result).toBe(true);
expect(errors).toBeNull();
Expand Down Expand Up @@ -90,6 +93,9 @@ describe('ClanRoleService.checkVotingOnExpire', () => {
// Player should NOT have updated clanRole_id
const updatedPlayer = await playerModel.findById(player._id);
expect(updatedPlayer.clanRole_id).toEqual(clanRoleId);
expect((roleService as any).votingService.finalizeVoting).toHaveBeenCalledWith(
votingDto._id,
);

expect(result).toBe(true);
expect(errors).toBeNull();
Expand Down
2 changes: 2 additions & 0 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ApiResponseDescription from '../common/swagger/response/ApiResponseDescri
import { ModelName } from '../common/enum/modelName.enum';
import { NoBoxIdFilter } from '../box/auth/decorator/NoBoxIdFilter.decorator';
import { SignInResponseDto } from './dto/signInResponse.dto';
import { ApiBody } from '@nestjs/swagger';

@NoAuth()
@Controller('auth')
Expand All @@ -25,6 +26,7 @@ export class AuthController {
*
* If the user provides the correct credentials, the access token will be returned, which should be used as a Bearer token in the Authorization header.
*/
@ApiBody({ type: SignInDto })
@ApiResponseDescription({
success: {
status: 201,
Expand Down
44 changes: 21 additions & 23 deletions src/clan/role/clanRole.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,31 +474,29 @@ export default class ClanRoleService {
true,
);

if (!votePassed) {
return [true, null];
}

if (!voting.setClanRole?.player_id || !voting.setClanRole?.role_id) {
return [
null,
[
new ServiceError({
reason: SEReason.REQUIRED,
field: 'setClanRole',
value: voting.setClanRole,
message:
'Voting is missing player_id or role_id for clan role update',
}),
],
];
if (votePassed) {
if (!voting.setClanRole?.player_id || !voting.setClanRole?.role_id) {
return [
null,
[
new ServiceError({
reason: SEReason.REQUIRED,
field: 'setClanRole',
value: voting.setClanRole,
message:
'Voting is missing player_id or role_id for clan role update',
}),
],
];
}

const [, updateErrors] = await this.playerBasicService.updateOneById(
voting.setClanRole.player_id.toString(),
{ clanRole_id: new ObjectId(voting.setClanRole.role_id.toString()) },
);
if (updateErrors) return [null, updateErrors];
}

const [, updateErrors] = await this.playerBasicService.updateOneById(
voting.setClanRole.player_id.toString(),
{ clanRole_id: new ObjectId(voting.setClanRole.role_id.toString()) },
);
if (updateErrors) return [null, updateErrors];

await this.votingService.finalizeVoting(voting._id);

return [true, null];
Expand Down
Loading