Skip to content

Commit

Permalink
Qodana
Browse files Browse the repository at this point in the history
  • Loading branch information
JessicaMulein committed Nov 24, 2024
1 parent 27e0be9 commit cea88c5
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 105 deletions.
2 changes: 1 addition & 1 deletion chili-and-cilantro-api/src/controllers/api/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export class GamesController extends BaseController {
true,
);
const chef = await this.chefService.getGameChefOrThrowAsync(game, user);
const actions = await this.gameService.availableTurnActions(game, chef);
const actions = this.gameService.availableTurnActions(game, chef);
res.status(200).json(actions);
} catch (e) {
if (e instanceof ValidationError) {
Expand Down
9 changes: 5 additions & 4 deletions chili-and-cilantro-api/src/controllers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export abstract class BaseController {
private activeResponse: Response | null = null;
public readonly getModel: GetModelFunction;

constructor(getModel: GetModelFunction) {
protected constructor(getModel: GetModelFunction) {
this.router = Router();
this.initializeRoutes();
this.getModel = getModel;
Expand Down Expand Up @@ -147,9 +147,10 @@ export abstract class BaseController {

/**
* Authenticates the request by checking the token. Also populates the request with the user object.
* @param req
* @param res
* @param next
* @param getModel Function to get models from the database
* @param req The request object
* @param res The response object
* @param next The next function
*/
protected authenticateRequest(
getModel: GetModelFunction,
Expand Down
6 changes: 6 additions & 0 deletions chili-and-cilantro-api/src/interfaces/bid-ingredient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { CardType } from '@chili-and-cilantro/chili-and-cilantro-lib';

Check failure on line 1 in chili-and-cilantro-api/src/interfaces/bid-ingredient.ts

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package

export interface IBidIngredient {
bid?: number;
ingredient?: CardType;
}
9 changes: 9 additions & 0 deletions chili-and-cilantro-api/src/interfaces/game-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {

Check failure on line 1 in chili-and-cilantro-api/src/interfaces/game-action.ts

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
IGameDocument,
IStartGameActionDocument,
} from '@chili-and-cilantro/chili-and-cilantro-lib';

export interface IGameAction {
game: IGameDocument;
action: IStartGameActionDocument;
}
9 changes: 9 additions & 0 deletions chili-and-cilantro-api/src/interfaces/game-chef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {

Check failure on line 1 in chili-and-cilantro-api/src/interfaces/game-chef.ts

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
IChefDocument,
IGameDocument,
} from '@chili-and-cilantro/chili-and-cilantro-lib';

export interface IGameChef {
game: IGameDocument;
chef: IChefDocument;
}
4 changes: 2 additions & 2 deletions chili-and-cilantro-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { validateEnvironment } from './interfaces/environment';

const app: App = App.getInstance();

validateEnvironment(environment, () => {
app.start();
validateEnvironment(environment, async () => {
await app.start();
});
3 changes: 2 additions & 1 deletion chili-and-cilantro-api/src/routers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export class AppRouter {

/**
* Initialize the application router
* @param app
* @param app The application
* @param debugRoutes Whether to log routes to the console
*/
public init(app: Application, debugRoutes: boolean) {
if (!AppRouter.distPath.includes('/dist/')) {
Expand Down
2 changes: 1 addition & 1 deletion chili-and-cilantro-api/src/routers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Router } from 'express';
export abstract class BaseRouter {
public readonly router: Router;
public readonly getModel: GetModelFunction;
constructor(getModel: GetModelFunction) {
protected constructor(getModel: GetModelFunction) {
this.router = Router();
this.getModel = getModel;
}
Expand Down
27 changes: 9 additions & 18 deletions chili-and-cilantro-api/src/services/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,73 +45,68 @@ export class ActionService {
}
public async getGameHistoryAsync(game: IGameDocument): Promise<IAction[]> {
const ActionModel = this.getModel<IActionDocument>(ModelName.Action);
const actions = await ActionModel.find({ gameId: game._id }).sort({
return ActionModel.find({ gameId: game._id }).sort({
createdAt: 1,
});
return actions;
}
public async createGameAsync(
game: IGameDocument,
chef: IChefDocument,
user: IUserDocument,
): Promise<ICreateGameActionDocument> {
const result = await ActionDiscriminatorsByActionType.CREATE_GAME.create({
return ActionDiscriminatorsByActionType.CREATE_GAME.create({
gameId: game._id,
chefId: chef._id,
userId: user._id,
type: ActionType.CREATE_GAME,
details: {} as ICreateGameDetails,
round: constants.NONE,
} as ICreateGameAction);
return result;
}
public async joinGameAsync(
game: IGameDocument,
chef: IChefDocument,
user: IUserDocument,
): Promise<IJoinGameActionDocument> {
const result = await ActionDiscriminatorsByActionType.JOIN_GAME.create({
return ActionDiscriminatorsByActionType.JOIN_GAME.create({
gameId: game._id,
chefId: chef._id,
userId: user._id,
type: ActionType.JOIN_GAME,
details: {} as IJoinGameDetails,
round: constants.NONE,
} as IJoinGameAction);
return result;
}
public async startGameAsync(
game: IGameDocument,
): Promise<IStartGameActionDocument> {
const result = await ActionDiscriminatorsByActionType.START_GAME.create({
return ActionDiscriminatorsByActionType.START_GAME.create({
gameId: game._id,
chefId: game.hostChefId,
userId: game.hostUserId,
type: ActionType.START_GAME,
details: {} as IStartGameDetails,
round: game.currentRound,
} as IStartGameAction);
return result;
}
public async expireGameAsync(
game: IGameDocument,
): Promise<IExpireGameActionDocument> {
const result = ActionDiscriminatorsByActionType.EXPIRE_GAME.create({
return ActionDiscriminatorsByActionType.EXPIRE_GAME.create({
gameId: game._id,
chefId: game.hostChefId,
userId: game.hostUserId,
type: ActionType.EXPIRE_GAME,
details: {} as IExpireGameDetails,
round: game.currentRound,
} as IExpireGameAction);
return result;
}
public async sendMessageAsync(
game: IGameDocument,
chef: IChefDocument,
message: string,
): Promise<IMessageActionDocument> {
const result = await ActionDiscriminatorsByActionType.MESSAGE.create({
return ActionDiscriminatorsByActionType.MESSAGE.create({
gameId: game._id,
chefId: chef._id,
userId: chef.userId,
Expand All @@ -121,14 +116,13 @@ export class ActionService {
} as IMessageDetails,
round: game.currentRound,
} as IMessageAction);
return result;
}
public async startBiddingAsync(
game: IGameDocument,
chef: IChefDocument,
bid: number,
): Promise<IStartBiddingActionDocument> {
const result = await ActionDiscriminatorsByActionType.START_BIDDING.create({
return ActionDiscriminatorsByActionType.START_BIDDING.create({
gameId: game._id,
chefId: chef._id,
userId: chef.userId,
Expand All @@ -138,29 +132,27 @@ export class ActionService {
} as IStartBiddingDetails,
round: game.currentRound,
} as IStartBiddingAction);
return result;
}
public async passAsync(
game: IGameDocument,
chef: IChefDocument,
): Promise<IPassActionDocument> {
const result = await ActionDiscriminatorsByActionType.PASS.create({
return ActionDiscriminatorsByActionType.PASS.create({
gameId: game._id,
chefId: chef._id,
userId: chef.userId,
type: ActionType.PASS,
details: {} as IPassDetails,
round: game.currentRound,
} as IPassAction);
return result;
}
public async placeCardAsync(
game: IGameDocument,
chef: IChefDocument,
cardType: CardType,
position: number,
): Promise<IPlaceCardActionDocument> {
const result = await ActionDiscriminatorsByActionType.PLACE_CARD.create({
return ActionDiscriminatorsByActionType.PLACE_CARD.create({
gameId: game._id,
chefId: chef._id,
userId: chef.userId,
Expand All @@ -171,6 +163,5 @@ export class ActionService {
} as IPlaceCardDetails,
round: game.currentRound,
} as IPlaceCardAction);
return result;
}
}
9 changes: 3 additions & 6 deletions chili-and-cilantro-api/src/services/chef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ChefService {
chefId?: Types.ObjectId,
): Promise<IChefDocument> {
const ChefModel = this.getModel<IChefDocument>(ModelName.Chef);
const chef = await ChefModel.create({
return ChefModel.create({
_id: chefId ?? new Types.ObjectId(),
gameId: game._id,
name: userName,
Expand All @@ -46,7 +46,6 @@ export class ChefService {
state: ChefState.LOBBY,
host: host,
});
return chef;
}

/**
Expand All @@ -62,7 +61,7 @@ export class ChefService {
newChefId?: Types.ObjectId,
): Promise<IChefDocument> {
const ChefModel = this.getModel<IChefDocument>(ModelName.Chef);
const newChef = await ChefModel.create({
return ChefModel.create({
_id: newChefId ?? new Types.ObjectId(),
gameId: newGame._id,
name: existingChef.name,
Expand All @@ -73,7 +72,6 @@ export class ChefService {
state: ChefState.LOBBY,
host: existingChef.host,
});
return newChef;
}

/**
Expand Down Expand Up @@ -111,7 +109,6 @@ export class ChefService {
return obj._id !== undefined;
};
const gameId = hasId(gameOrId) ? gameOrId._id.toString() : gameOrId;
const chefs = await ChefModel.find({ gameId: gameId });
return chefs;
return ChefModel.find({ gameId: gameId });
}
}
Loading

0 comments on commit cea88c5

Please sign in to comment.