Skip to content

Commit

Permalink
Do not queue a player if their deck is empty
Browse files Browse the repository at this point in the history
Relates to #28
  • Loading branch information
4Ply committed Jun 8, 2024
1 parent f49d1ff commit e7201fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/modules/card/card.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const updateCardById = async (cardId: mongoose.Types.ObjectId, updateBody
export const deleteCard = async (filter: DeleteCard): Promise<ICardDoc | null> => {
const card = await Card.findOne(filter).exec();
if (!card) {
throw new ApiError(httpStatus.NOT_FOUND, 'Card not found');
throw new ApiError(httpStatus.NOT_FOUND, `Card not found for filter ${filter}`);
}
await card.deleteOne();
return card;
Expand Down
8 changes: 6 additions & 2 deletions src/modules/event/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { QueueStates } from './player.interfaces';
import Task from '../task/task.model';
import { logger } from '../logger';
import { notifyOps } from '../task';
import config from '../../config/config';
import { InstanceStates } from './instance.interfaces';
import { Card } from '../card';

/**
* Create an event, and potentially react to the event depending on DB state
Expand Down Expand Up @@ -150,7 +150,7 @@ async function createDungeonInstanceRecordIfMissing(eventBody: NewCreatedEvent)
existingInstance.state !== update.state ||
existingInstance.requiresRebuild !== update.requiresRebuild ||
existingInstance.activePlayers !== update.activePlayers;
if (anUpdateOccurred || config.env === 'development') {
if (anUpdateOccurred) {
await notifyOps(
`Updated ${eventBody.server}: state=${update.state} requiresRebuild=${update.requiresRebuild} activePlayers=${update.activePlayers}`
);
Expand Down Expand Up @@ -213,6 +213,10 @@ async function addPlayerToQueue(eventBody: NewCreatedEvent) {
throw new ApiError(httpStatus.PRECONDITION_FAILED, `Player '${eventBody.player}' is not allowed to play Decked Out 2`);
}

if (!(await Card.findOne({ player: player.playerName }).exec())) {
throw new ApiError(httpStatus.PRECONDITION_FAILED, `Player '${eventBody.player}' has no cards`);
}

await player.updateOne({
state: QueueStates.IN_QUEUE,
server: eventBody.server,
Expand Down

0 comments on commit e7201fe

Please sign in to comment.