feature/4-pilots---add

This commit is contained in:
2024-06-22 07:14:30 -05:00
parent 7bcddf9d13
commit 9d5a6f7d09
35 changed files with 1430 additions and 3201 deletions

View File

@@ -28,7 +28,7 @@
"@nestjs/core": "^10.0.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@noahspan/noahspan-modules": "^0.2.7",
"@noahspan/noahspan-modules": "^0.3.4",
"@schematics/angular": "^17.3.7",
"dotenv": "^16.4.5",
"reflect-metadata": "0.1.13",

View File

@@ -1,4 +1,4 @@
import { Controller, Get, Query } from '@nestjs/common';
import { Controller, Get, Headers, Query } from '@nestjs/common';
import {
AppConfigService,
MsGraphService,
@@ -42,12 +42,14 @@ export class AppController {
async getProfilePhoto(@Query() query: any): Promise<any> {}
@Get('userProfile')
async getUserProfile(@Query() query: any) {
async getUserProfile(@Headers() headers: any) {
try {
const username: string = query.username;
const graphToken: string = await this.msGraphService.getMsGraphAuth(
headers.authorization.replace('Bearer ', '')
);
const client: MsGraphClient =
await this.msGraphService.getMsGraphClient();
const userProfile = await client.api(`users/${username}`).get();
await this.msGraphService.getMsGraphClientDelegated(graphToken);
const userProfile = await client.api(`me`).get();
return userProfile;
} catch (error) {

View File

@@ -9,6 +9,8 @@ import {
} from '@noahspan/noahspan-modules';
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: [
@@ -28,9 +30,10 @@ import { APP_GUARD } from '@nestjs/core';
tenantId: process.env.TENANT_ID,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET
})
}),
PilotModule
],
controllers: [AppController],
controllers: [AppController, PilotController],
providers: [
{
provide: APP_GUARD,

View File

@@ -0,0 +1,7 @@
export class Certificate {
partitionKey: string;
rowKey: string;
type: string;
issueDate: Date;
number?: string;
}

View File

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

View File

@@ -0,0 +1,6 @@
export class Endorsement {
partitionkey: string;
rowKey: string;
type: string;
issueDate: Date;
}

View File

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

View File

@@ -0,0 +1,6 @@
export class Medical {
partitionKey: string;
rowKey: string;
certificateClass: string;
certificateExpiration: Date;
}

View File

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

View File

@@ -0,0 +1,18 @@
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';
@Controller('pilots')
export class PilotController {
constructor() {}
@Public()
@Post()
async createPilot(@Body() pilotDto: PilotDTO) {
const pilot = new Pilot();
Object.assign(pilot, pilotDto);
console.log(pilot);
}
}

View File

@@ -0,0 +1,11 @@
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

@@ -0,0 +1,11 @@
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

@@ -0,0 +1,17 @@
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';
@Module({
imports: [
AzureTableStorageModule.forFeature(Pilot, {
table: 'Pilot',
createTableIfNotExists: true
})
],
controllers: [PilotController],
providers: [PilotService]
})
export class PilotModule {}

View File

@@ -0,0 +1,17 @@
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

@@ -0,0 +1,11 @@
export class Profile {
partitionKey: string;
rowKey: string;
firstName: string;
lastName: string;
address: string;
city: string;
state: string;
postalCode: string;
lastFlightReview: Date;
}

View File

@@ -0,0 +1,37 @@
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);
}
}