62 行
1.6 KiB
TypeScript
62 行
1.6 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectModel } from '@nestjs/mongoose';
|
|
import { Model } from 'mongoose';
|
|
import { Inbound, InboundDocument } from './models/inbound.model';
|
|
|
|
@Injectable()
|
|
export class InboundService {
|
|
constructor(
|
|
@InjectModel('inbound')
|
|
private readonly inboundModel: Model<InboundDocument>,
|
|
) {}
|
|
|
|
async callsignKnown(callsign: string): Promise<boolean> {
|
|
return this.inboundModel
|
|
.findOne({ callsign })
|
|
.then((inbound) => inbound !== null);
|
|
}
|
|
|
|
async add(inbound: Inbound): Promise<boolean> {
|
|
return this.callsignKnown(inbound.callsign).then(async (known) => {
|
|
if (known) return false;
|
|
|
|
// modify the inbound data
|
|
inbound.plan = undefined;
|
|
inbound.controllerData.reportedTime = new Date().toUTCString();
|
|
|
|
await this.inboundModel.create(inbound);
|
|
|
|
return true;
|
|
});
|
|
}
|
|
|
|
async remove(callsign: string): Promise<boolean> {
|
|
return this.callsignKnown(callsign).then(async (known) => {
|
|
if (!known) return false;
|
|
await this.inboundModel.deleteOne({ callsign });
|
|
return true;
|
|
});
|
|
}
|
|
|
|
async update(inbound: Inbound): Promise<boolean> {
|
|
return this.callsignKnown(inbound.callsign).then(async (known) => {
|
|
if (!known) return false;
|
|
|
|
// modify the inbound data
|
|
inbound.plan = undefined;
|
|
inbound.controllerData.reportedTime = new Date().toUTCString();
|
|
|
|
await this.inboundModel.findOneAndUpdate(
|
|
{ callsign: inbound.callsign },
|
|
inbound,
|
|
);
|
|
|
|
return true;
|
|
});
|
|
}
|
|
|
|
async airportInbounds(icao: string): Promise<Inbound[]> {
|
|
return this.inboundModel.find({ destination: icao });
|
|
}
|
|
}
|