feature/4-pilots---add
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
7
api/src/pilot/certificate/certificate.entity.ts
Normal file
7
api/src/pilot/certificate/certificate.entity.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export class Certificate {
|
||||
partitionKey: string;
|
||||
rowKey: string;
|
||||
type: string;
|
||||
issueDate: Date;
|
||||
number?: string;
|
||||
}
|
||||
37
api/src/pilot/certificate/certificate.service.ts
Normal file
37
api/src/pilot/certificate/certificate.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
6
api/src/pilot/endorsement/endorsement.entity.ts
Normal file
6
api/src/pilot/endorsement/endorsement.entity.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export class Endorsement {
|
||||
partitionkey: string;
|
||||
rowKey: string;
|
||||
type: string;
|
||||
issueDate: Date;
|
||||
}
|
||||
37
api/src/pilot/endorsement/endosement.service.ts
Normal file
37
api/src/pilot/endorsement/endosement.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
6
api/src/pilot/medical/medical.entity.ts
Normal file
6
api/src/pilot/medical/medical.entity.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export class Medical {
|
||||
partitionKey: string;
|
||||
rowKey: string;
|
||||
certificateClass: string;
|
||||
certificateExpiration: Date;
|
||||
}
|
||||
33
api/src/pilot/medical/medical.service.ts
Normal file
33
api/src/pilot/medical/medical.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
18
api/src/pilot/pilot.controller.ts
Normal file
18
api/src/pilot/pilot.controller.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
11
api/src/pilot/pilot.dto.ts
Normal file
11
api/src/pilot/pilot.dto.ts
Normal 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;
|
||||
}
|
||||
11
api/src/pilot/pilot.entity.ts
Normal file
11
api/src/pilot/pilot.entity.ts
Normal 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;
|
||||
}
|
||||
17
api/src/pilot/pilot.module.ts
Normal file
17
api/src/pilot/pilot.module.ts
Normal 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 {}
|
||||
17
api/src/pilot/pilot.service.ts
Normal file
17
api/src/pilot/pilot.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
11
api/src/pilot/profile/profile.entity.ts
Normal file
11
api/src/pilot/profile/profile.entity.ts
Normal 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;
|
||||
}
|
||||
37
api/src/pilot/profile/profile.service.ts
Normal file
37
api/src/pilot/profile/profile.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user