adding logbook entry delete (#31)
This commit was merged in pull request #31.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
Param,
|
||||
@@ -79,4 +80,17 @@ export class LogbookController {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Delete(':rowKey')
|
||||
async delete(@Param() params: any): Promise<void> {
|
||||
try {
|
||||
await this.logbookService.delete(params.rowKey);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode, {
|
||||
cause: customError.name
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,19 +10,19 @@ export class LogbookEntity {
|
||||
routeTo: string;
|
||||
durationOfFlight: number | null;
|
||||
singleEngineLand: number | null;
|
||||
simulatorAtd: number | null;
|
||||
landingsDay: number | null;
|
||||
landingsNight: number | null;
|
||||
groundTrainingReceived: number;
|
||||
flightTrainingReceived: number;
|
||||
crossCountry: number | null;
|
||||
night: number | null;
|
||||
solo: number | null;
|
||||
pilotInCommand: number | null;
|
||||
instrumentActual: number | null;
|
||||
instrumentSimulated: number | null;
|
||||
instrumentApproaches: number | null;
|
||||
instrumentHolds: number | null;
|
||||
instrumentNavTrack: number | null;
|
||||
notes: string;
|
||||
simulatorAtd?: number | null;
|
||||
landingsDay?: number | null;
|
||||
landingsNight?: number | null;
|
||||
groundTrainingReceived?: number;
|
||||
flightTrainingReceived?: number;
|
||||
crossCountry?: number | null;
|
||||
night?: number | null;
|
||||
solo?: number | null;
|
||||
pilotInCommand?: number | null;
|
||||
instrumentActual?: number | null;
|
||||
instrumentSimulated?: number | null;
|
||||
instrumentApproaches?: number | null;
|
||||
instrumentHolds?: number | null;
|
||||
instrumentNavTrack?: number | null;
|
||||
notes?: string;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ export class LogbookService {
|
||||
instrumentNavTrack: entity.instrumentNavTrack
|
||||
? Number(entity.instrumentNavTrack)
|
||||
: null,
|
||||
notes: entity.notes.toString()
|
||||
notes: entity.notes ? entity.notes.toString() : ''
|
||||
};
|
||||
|
||||
logbookEntries.push(logbookEntry);
|
||||
@@ -143,14 +143,14 @@ export class LogbookService {
|
||||
}
|
||||
|
||||
async update(logbookData: LogbookDto): Promise<void> {
|
||||
const client: TableClient = await this.tableService.getTableClient(
|
||||
this.tableName
|
||||
);
|
||||
const logbook: LogbookEntity = new LogbookEntity();
|
||||
|
||||
Object.assign(logbook, logbookData);
|
||||
|
||||
try {
|
||||
const client: TableClient = await this.tableService.getTableClient(
|
||||
this.tableName
|
||||
);
|
||||
const logbook: LogbookEntity = new LogbookEntity();
|
||||
|
||||
Object.assign(logbook, logbookData);
|
||||
|
||||
await client.upsertEntity(logbook, 'Replace');
|
||||
} catch (error) {
|
||||
const restError: RestError = error as RestError;
|
||||
@@ -162,4 +162,22 @@ export class LogbookService {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async delete(rowKey: string): Promise<void> {
|
||||
try {
|
||||
const client: TableClient = await this.tableService.getTableClient(
|
||||
this.tableName
|
||||
);
|
||||
|
||||
await client.deleteEntity('entry', rowKey);
|
||||
} catch (error) {
|
||||
const restError: RestError = error as RestError;
|
||||
|
||||
throw new CustomError(
|
||||
restError.details['odataError']['message']['value'],
|
||||
restError.details['odataError']['code'],
|
||||
restError.statusCode
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user