adding pilot

This commit is contained in:
2024-08-16 19:23:54 -05:00
parent 0d7f6b850d
commit 9e1e69d996
14 changed files with 284 additions and 272 deletions

View File

@@ -20,6 +20,7 @@
"start:azure": "npm run build && func host start"
},
"dependencies": {
"@azure/data-tables": "^13.2.2",
"@azure/functions": "^1.0.3",
"@nestjs/azure-database": "^3.0.0",
"@nestjs/azure-func-http": "^0.10.0",
@@ -28,7 +29,7 @@
"@nestjs/core": "^10.0.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@noahspan/noahspan-modules": "^0.3.5",
"@noahspan/noahspan-modules": "^0.3.9",
"@schematics/angular": "^17.3.7",
"dotenv": "^16.4.5",
"reflect-metadata": "0.1.13",

View File

@@ -1,12 +1,4 @@
import {
Body,
Controller,
Get,
Headers,
Post,
Query,
UnprocessableEntityException
} from '@nestjs/common';
import { Controller, Get, Headers, Query } from '@nestjs/common';
import {
AppConfigService,
MsGraphService,
@@ -16,8 +8,6 @@ import { FeatureFlagValue } from '@azure/app-configuration';
import { Public } from '@noahspan/noahspan-modules';
import { Person } from '@microsoft/microsoft-graph-types';
import { AppService } from './app.service';
import { PilotDTO } from './pilot/pilot.dto';
import { PilotService } from './pilot/pilot.service';
@Controller()
export class AppController {

View File

@@ -10,7 +10,6 @@ import {
import { ConfigModule } from '@nestjs/config';
import { APP_GUARD } from '@nestjs/core';
import { PilotModule } from './pilot/pilot.module';
import { PilotController } from './pilot/pilot.controller';
@Module({
imports: [
@@ -33,7 +32,7 @@ import { PilotController } from './pilot/pilot.controller';
}),
PilotModule
],
controllers: [AppController, PilotController],
controllers: [AppController],
providers: [
{
provide: APP_GUARD,

View File

@@ -1,18 +1,25 @@
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
import { Public } from '@noahspan/noahspan-modules';
import { PilotDTO } from './pilot.dto';
import { Pilot } from './pilot.entity';
import {
Body,
Controller,
Get,
Post,
Put,
Query,
UnprocessableEntityException
} from '@nestjs/common';
import { PilotInfoService } from './info/pilot-info.service';
import { PilotInfoDto } from './info/pilot-info.dto';
@Controller('pilots')
export class PilotController {
constructor() {}
constructor(private readonly pilotInfoService: PilotInfoService) {}
@Public()
@Post()
async createPilot(@Body() pilotDto: PilotDTO) {
const pilot = new Pilot();
Object.assign(pilot, pilotDto);
console.log(pilot);
async createPilot(@Body() pilotInfoData: PilotInfoDto): Promise<void> {
try {
return await this.pilotInfoService.create(pilotInfoData);
} catch (error) {
throw new UnprocessableEntityException(error);
}
}
}

View File

@@ -1,11 +0,0 @@
import { Certificate } from './certificate/certificate.entity';
import { Endorsement } from './endorsement/endorsement.entity';
import { Medical } from './medical/medical.entity';
import { Profile } from './profile/profile.entity';
export class PilotDTO {
profile?: Profile;
medical?: Medical;
certificate?: Certificate;
endosement?: Endorsement;
}

View File

@@ -1,11 +0,0 @@
import { Certificate } from './certificate/certificate.entity';
import { Endorsement } from './endorsement/endorsement.entity';
import { Medical } from './medical/medical.entity';
import { Profile } from './profile/profile.entity';
export class Pilot {
profile: Profile;
medical: Medical;
certificates: Certificate;
endorsements: Endorsement;
}

View File

@@ -1,17 +1,16 @@
import { Module } from '@nestjs/common';
import { PilotController } from './pilot.controller';
import { PilotService } from './pilot.service';
import { AzureTableStorageModule } from '@nestjs/azure-database';
import { Pilot } from './pilot.entity';
import { TableModule } from '@noahspan/noahspan-modules';
import { PilotInfoService } from './info/pilot-info.service';
@Module({
imports: [
AzureTableStorageModule.forFeature(Pilot, {
table: 'Pilot',
createTableIfNotExists: true
TableModule.register({
accountName: process.env.AZURE_STORAGE_ACCOUNT_NAME,
accountKey: process.env.AZURE_STORAGE_ACCOUNT_KEY
})
],
controllers: [PilotController],
providers: [PilotService]
providers: [PilotInfoService]
})
export class PilotModule {}

View File

@@ -1,17 +0,0 @@
import { Inject, Injectable } from '@nestjs/common';
import { Repository, InjectRepository } from '@nestjs/azure-database';
import { Medical } from './medical/medical.entity';
import { Profile } from './profile/profile.entity';
import { ProfileService } from './profile/profile.service';
import { Pilot } from './pilot.entity';
@Injectable()
export class PilotService {
constructor(
@InjectRepository(Pilot) private readonly pilotRepository: Repository<Pilot>
) {}
async create(pilot: Pilot): Promise<Pilot> {
return await this.pilotRepository.create(pilot);
}
}

View File

@@ -1,18 +0,0 @@
import {
EntityDateTime,
EntityPartitionKey,
EntityRowKey,
EntityString
} from '@nestjs/azure-database';
@EntityPartitionKey('pilot')
@EntityRowKey('id')
export class Profile {
@EntityString() firstName: string;
@EntityString() lastName: string;
@EntityString() address: string;
@EntityString() city: string;
@EntityString() state: string;
@EntityString() postalCode: string;
@EntityDateTime() lastFlightReview: Date;
}

View File

@@ -1,37 +0,0 @@
import { Injectable } from '@nestjs/common';
import { Repository, InjectRepository } from '@nestjs/azure-database';
import { Profile } from './profile.entity';
@Injectable()
export class ProfileService {
private readonly partitionKey: string = 'profile';
constructor(
@InjectRepository(Profile)
private readonly profileRepository: Repository<Profile>
) {}
async find(rowKey: string): Promise<Profile> {
return await this.profileRepository.find(this.partitionKey, rowKey);
}
async findAll(): Promise<Profile[]> {
return await this.profileRepository.findAll();
}
async create(profile: Profile): Promise<Profile> {
return await this.profileRepository.create(profile);
}
async update(rowKey: string, profile: Profile): Promise<Profile> {
return await this.profileRepository.update(
this.partitionKey,
rowKey,
profile
);
}
async delete(rowKey: string): Promise<void> {
await this.profileRepository.delete(this.partitionKey, rowKey);
}
}