Testing menu button
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
"dependencies": {
|
||||
"@azure/data-tables": "^13.2.2",
|
||||
"@azure/functions": "^1.0.3",
|
||||
"@nestjs/axios": "^3.0.3",
|
||||
"@nestjs/azure-database": "^3.0.0",
|
||||
"@nestjs/azure-func-http": "^0.10.0",
|
||||
"@nestjs/common": "^10.0.0",
|
||||
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { APP_GUARD } from '@nestjs/core';
|
||||
import { PilotModule } from './pilot/pilot.module';
|
||||
import { APP_FILTER } from '@nestjs/core';
|
||||
import { HttpExceptionFilter } from './filters/http-exception.filter';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -38,6 +40,10 @@ import { PilotModule } from './pilot/pilot.module';
|
||||
provide: APP_GUARD,
|
||||
useClass: AuthGuard
|
||||
},
|
||||
{
|
||||
provide: APP_FILTER,
|
||||
useClass: HttpExceptionFilter
|
||||
},
|
||||
AppService
|
||||
]
|
||||
})
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { HttpExceptionFilter } from './filters/http-exception.filter';
|
||||
import { InternalServerErrorException } from '@nestjs/common';
|
||||
|
||||
async function bootstrap() {
|
||||
const httpService = new HttpService();
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
app.useGlobalFilters(new HttpExceptionFilter());
|
||||
httpService.axiosRef.interceptors.response.use(
|
||||
(response) => {
|
||||
return response;
|
||||
},
|
||||
(error) => {
|
||||
console.error('Internal server error exception', error);
|
||||
|
||||
throw new InternalServerErrorException();
|
||||
}
|
||||
);
|
||||
|
||||
await app.listen(3000);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { HttpException, Injectable } from '@nestjs/common';
|
||||
// import { Repository, InjectRepository } from '@nestjs/azure-database';
|
||||
import { PilotInfoDto } from './pilot-info.dto';
|
||||
import { PilotInfoEntity } from './pilot-info.entity';
|
||||
import { TableClient, TableService } from '@noahspan/noahspan-modules';
|
||||
import { RestError, TableInsertEntityHeaders } from '@azure/data-tables';
|
||||
import { CustomError } from '../../customError/CustomError';
|
||||
|
||||
@Injectable()
|
||||
export class PilotInfoService {
|
||||
@@ -22,7 +24,7 @@ export class PilotInfoService {
|
||||
// return await this.pilotInfoRepository.findAll();
|
||||
// }
|
||||
|
||||
async create(pilotInfoData: PilotInfoDto): Promise<void> {
|
||||
async create(pilotInfoData: PilotInfoDto): Promise<TableInsertEntityHeaders> {
|
||||
const client: TableClient =
|
||||
await this.tableService.getTableClient('Pilots');
|
||||
const pilotInfo: PilotInfoEntity = new PilotInfoEntity();
|
||||
@@ -30,11 +32,17 @@ export class PilotInfoService {
|
||||
Object.assign(pilotInfo, pilotInfoData);
|
||||
pilotInfo.partitionKey = 'pilot';
|
||||
pilotInfo.rowKey = pilotInfo.id;
|
||||
console.log(pilotInfo);
|
||||
|
||||
try {
|
||||
await client.createEntity(pilotInfo);
|
||||
return await client.createEntity(pilotInfo);
|
||||
} catch (error) {
|
||||
return error;
|
||||
const restError: RestError = error as RestError;
|
||||
|
||||
throw new CustomError(
|
||||
restError.details['odataError']['message']['value'],
|
||||
restError.details['odataError']['code'],
|
||||
restError.statusCode
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
UnprocessableEntityException
|
||||
} from '@nestjs/common';
|
||||
import { Body, Controller, HttpException, Post } from '@nestjs/common';
|
||||
import { PilotInfoService } from './info/pilot-info.service';
|
||||
import { PilotInfoDto } from './info/pilot-info.dto';
|
||||
import { TableInsertEntityHeaders } from '@azure/data-tables';
|
||||
import { CustomError } from '../customError/CustomError';
|
||||
|
||||
@Controller('pilots')
|
||||
export class PilotController {
|
||||
@@ -17,9 +11,23 @@ export class PilotController {
|
||||
@Post()
|
||||
async createPilot(@Body() pilotInfoData: PilotInfoDto): Promise<void> {
|
||||
try {
|
||||
return await this.pilotInfoService.create(pilotInfoData);
|
||||
const response: TableInsertEntityHeaders =
|
||||
await this.pilotInfoService.create(pilotInfoData);
|
||||
|
||||
console.log(`Not Broken: ${response}`);
|
||||
} catch (error) {
|
||||
throw new UnprocessableEntityException(error);
|
||||
const customError = error as CustomError;
|
||||
console.log(customError.name);
|
||||
throw new HttpException(customError.message, customError.statusCode, {
|
||||
cause: customError.name
|
||||
});
|
||||
|
||||
// throw new HttpException({
|
||||
// status: customError.statusCode,
|
||||
// error: customError.message
|
||||
// }, customError.statusCode, {
|
||||
// cause: customError.name
|
||||
// });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user