Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: getAllApplications #50

Merged
merged 7 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions apps/backend/src/applications/applications.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
UseGuards,
BadRequestException,
NotFoundException,
UnauthorizedException,
} from '@nestjs/common';
import { CurrentUserInterceptor } from '../interceptors/current-user.interceptor';
import { AuthGuard } from '@nestjs/passport';
Expand All @@ -22,6 +23,22 @@ import { UserStatus } from '../users/types';
export class ApplicationsController {
constructor(private readonly applicationsService: ApplicationsService) {}

@Get('/')
async getApplications(@Request() req): Promise<GetApplicationResponseDTO[]> {
if (
!(
req.user.status === UserStatus.RECRUITER ||
req.user.status === UserStatus.ADMIN
)
) {
throw new UnauthorizedException(
'calling user is not a recruiter or admin',
ojn03 marked this conversation as resolved.
Show resolved Hide resolved
);
}

return this.applicationsService.findAllCurrentApplications();
}

@Get('/:userId')
async getApplication(
@Param('userId', ParseIntPipe) userId: number,
Expand Down
24 changes: 23 additions & 1 deletion apps/backend/src/applications/applications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { InjectRepository } from '@nestjs/typeorm';
import { MongoRepository } from 'typeorm';
import { UsersService } from '../users/users.service';
import { Application } from './application.entity';
import { getAppForCurrentCycle } from './utils';
import { getAppForCurrentCycle, getCurrentCycle } from './utils';
import { GetApplicationResponseDTO } from './dto/get-application.response.dto';
import { Cycle } from './dto/cycle';

@Injectable()
export class ApplicationsService {
Expand All @@ -22,6 +24,26 @@ export class ApplicationsService {
return apps;
}

async findAllCurrentApplications(): Promise<GetApplicationResponseDTO[]> {
const currentCycle: Cycle = getCurrentCycle();
const applications = await this.applicationsRepository.find({
where: {
//TODO q: I had to change Cycle definition to make year and semester public. Is there a reason it was private?
ojn03 marked this conversation as resolved.
Show resolved Hide resolved
year: currentCycle.year,
semester: currentCycle.semester,
},
});

const dtos: GetApplicationResponseDTO[] = [];

applications.forEach((app) =>
//TODO q: what is the numApps parameter? I just passed 0 in
chromium-52 marked this conversation as resolved.
Show resolved Hide resolved
dtos.push(app.toGetApplicationResponseDTO(0)),
);

return dtos;
}

async findCurrent(userId: number): Promise<Application> {
const apps = await this.findAll(userId);
const currentApp = getAppForCurrentCycle(apps);
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/applications/dto/cycle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Semester } from '../types';

export class Cycle {
constructor(private year: number, private semester: Semester) {}
ojn03 marked this conversation as resolved.
Show resolved Hide resolved
constructor(public year: number, public semester: Semester) {}

public isCurrentCycle(cycle: Cycle): boolean {
return this.year === cycle.year && this.semester === cycle.semester;
Expand Down