Skip to content

Commit

Permalink
Changed the type error in decision
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnfikd7 committed Mar 12, 2024
1 parent 6da21ab commit 7139655
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ApplicationsModule } from './applications/applications.module';
imports: [
TypeOrmModule.forRoot({
type: 'postgres',
database: 'c4c-ops',
host: process.env.NX_DB_HOST,
port: 5432,
username: process.env.NX_DB_USERNAME,
Expand Down
10 changes: 8 additions & 2 deletions apps/backend/src/applications/applications.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
NotFoundException,
UnauthorizedException,
} from '@nestjs/common';
import { Response } from './types';
import { Decision, Response } from './types';
import { ApplicationsService } from './applications.service';
import { CurrentUserInterceptor } from '../interceptors/current-user.interceptor';
import { AuthGuard } from '@nestjs/passport';
Expand Down Expand Up @@ -51,6 +51,12 @@ export class ApplicationsController {
throw new UnauthorizedException();
}

//Check if the string decision matches with the Decision enum
const decisionEnum: Decision = Decision[decision as keyof typeof Decision];
if (!decisionEnum) {
throw new BadRequestException('Invalid decision value');
}

//Check if the user exists and if the user has an application for the current cycle
const applicant = await this.applicationsService.findCurrent(applicantId);
if (!applicant) {
Expand All @@ -60,7 +66,7 @@ export class ApplicationsController {
}

//Delegate the decision making to the service.
await this.applicationsService.processDecision(applicantId, decision);
await this.applicationsService.processDecision(applicantId, decisionEnum);
}

@Get('/:userId')
Expand Down
10 changes: 5 additions & 5 deletions apps/backend/src/applications/applications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MongoRepository } from 'typeorm';
import { UsersService } from '../users/users.service';
import { Application } from './application.entity';
import { getAppForCurrentCycle, getCurrentCycle } from './utils';
import { Response } from './types';
import { Decision, Response } from './types';
import * as crypto from 'crypto';
import { User } from '../users/user.entity';
import { Position, ApplicationStage, ApplicationStep } from './types';
Expand Down Expand Up @@ -98,27 +98,27 @@ export class ApplicationsService {
*/
async processDecision(
applicantId: number,
decision: 'ACCEPT' | 'REJECT',
decision: Decision,
): Promise<void> {
const applicant = await this.findCurrent(applicantId);

let newStage: ApplicationStage;
switch (applicant.stage) {
case ApplicationStage.RESUME:
newStage =
decision === 'ACCEPT'
decision === Decision.ACCEPT
? ApplicationStage.TECHNICAL_CHALLENGE
: ApplicationStage.REJECTED;
break;
case ApplicationStage.TECHNICAL_CHALLENGE:
newStage =
decision === 'ACCEPT'
decision === Decision.ACCEPT
? ApplicationStage.INTERVIEW
: ApplicationStage.REJECTED;
break;
case ApplicationStage.INTERVIEW:
newStage =
decision === 'ACCEPT'
decision === Decision.ACCEPT
? ApplicationStage.ACCEPTED
: ApplicationStage.REJECTED;
break;
Expand Down
5 changes: 5 additions & 0 deletions apps/backend/src/applications/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ export enum Position {
PM = 'PRODUCT_MANAGER',
DESIGNER = 'DESIGNER',
}

export enum Decision {
ACCEPT = 'ACCEPT',
REJECT = 'REJECT',
}

0 comments on commit 7139655

Please sign in to comment.