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

#36 get apps endpoint #38

Merged
merged 3 commits into from
Oct 28, 2024
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
3 changes: 2 additions & 1 deletion apps/backend/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

Check warning on line 2 in apps/backend/src/app/app.module.ts

View workflow job for this annotation

GitHub Actions / pre-deploy

'TypeOrmModule' is defined but never used
import { UserModule } from '../user/user.module'

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SiteModule } from '../site/site.module';
import { ApplicationsModule } from '../applications/applications.module';
import { DynamoDbService } from '../dynamodb';


@Module({
imports: [SiteModule,UserModule],
imports: [SiteModule,UserModule, ApplicationsModule],
controllers: [AppController],
providers: [AppService, DynamoDbService],
})
Expand Down
13 changes: 13 additions & 0 deletions apps/backend/src/applications/applications.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller, Get } from '@nestjs/common';
import { ApplicationsService } from './applications.service';
import { ApplicationsModel } from './applications.model';

@Controller('applications')
export class ApplicationsController {
constructor(private applicationsService: ApplicationsService) {}

@Get('applicationsInfo')
public async getApplications(): Promise<ApplicationsModel[]> {
return this.applicationsService.getApplications();
}
}
19 changes: 19 additions & 0 deletions apps/backend/src/applications/applications.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Represents the model schema of an application
*/

export type ApplicationsModel = {
appId: number;
userId: number;
siteId: number;
names: Array<string>;
status: ApplicationStatus;
dateApplied: Date;
isFirstApplication: boolean;
};

export enum ApplicationStatus {
APPROVED = 'Approved',
PENDING = 'Pending',
REJECTED = 'Rejected',
}
12 changes: 12 additions & 0 deletions apps/backend/src/applications/applications.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { ApplicationsService } from './applications.service';
import { ApplicationsController } from './applications.controller';
import { DynamoDbService } from '../dynamodb';

@Module({
imports: [],
providers: [ApplicationsService, DynamoDbService],
controllers: [ApplicationsController],
exports: [ApplicationsService],
})
export class ApplicationsModule {}
38 changes: 38 additions & 0 deletions apps/backend/src/applications/applications.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Injectable } from '@nestjs/common';
import { ApplicationsModel } from './applications.model';
import { DynamoDbService } from '../dynamodb';
import { ApplicationStatus } from './applications.model';

@Injectable()
export class ApplicationsService {
private readonly tableName = 'gibostonApplications';
constructor(private readonly dynamoDbService: DynamoDbService) {}

/**
* Gets all applications.
*
* @returns a list of all applications as ApplicationsModel objects.
*/
public async getApplications(): Promise<ApplicationsModel[]> {
try {
const data = await this.dynamoDbService.scanTable(this.tableName);
return data.map(this.mapDynamoDBItemToApplication);
} catch (e) {
throw new Error('Unable to retrieve applications: ' + e);
}
}

private mapDynamoDBItemToApplication = (item: {
[key: string]: any;

Check warning on line 26 in apps/backend/src/applications/applications.service.ts

View workflow job for this annotation

GitHub Actions / pre-deploy

Unexpected any. Specify a different type
}): ApplicationsModel => {
return {
appId: item['appId'].N,
dateApplied: new Date(item['dateApplied'].S),
isFirstApplication: item['isFirstApplication'].BOOL,
names: item['names'].SS,
siteId: item['siteId'].N,
status: item['status'].S as ApplicationStatus,
userId: item['userId'].N,
};
};
}
Loading