63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
import { inject, injectable } from "tsyringe";
|
|
import { TtnGatewayReceptionRepository } from "../repositories/ttnGatewayReceptionRepository";
|
|
|
|
interface CreateTtnGatewayReceptionParams {
|
|
lp_ttn_end_device_uplinks_id: string;
|
|
gateway_id: string;
|
|
eui?: string;
|
|
rssi?: number;
|
|
latitude?: number;
|
|
longitude?: number;
|
|
altitude?: number;
|
|
}
|
|
|
|
interface UpdateTtnGatewayReceptionParams {
|
|
ttn_gateway_reception_id: string;
|
|
gateway_id?: string;
|
|
eui?: string;
|
|
rssi?: number;
|
|
latitude?: number;
|
|
longitude?: number;
|
|
altitude?: number;
|
|
}
|
|
|
|
@injectable()
|
|
export class TtnGatewayReceptionService {
|
|
constructor(
|
|
@inject(TtnGatewayReceptionRepository)
|
|
private repository: TtnGatewayReceptionRepository
|
|
) {}
|
|
|
|
public async getAllGatewayReceptions() {
|
|
return this.repository.findAll();
|
|
}
|
|
|
|
public async getGatewayReceptionById(id: string) {
|
|
return this.repository.findById(id);
|
|
}
|
|
|
|
public async createTtnGatewayReception(
|
|
data: CreateTtnGatewayReceptionParams
|
|
) {
|
|
if (data.latitude !== undefined && data.longitude !== undefined)
|
|
return this.repository.create(data);
|
|
}
|
|
|
|
public async filterAndInsertGatewayReception(
|
|
data: CreateTtnGatewayReceptionParams[]
|
|
) {
|
|
const result = await Promise.all(
|
|
data.map(async (gateway) => await this.createTtnGatewayReception(gateway))
|
|
);
|
|
return result.filter((gateway) => gateway !== undefined);
|
|
}
|
|
|
|
public async updateGatewayReception(data: UpdateTtnGatewayReceptionParams) {
|
|
return this.repository.update(data.ttn_gateway_reception_id, data);
|
|
}
|
|
|
|
public async deleteGatewayReception(id: string) {
|
|
return this.repository.delete(id);
|
|
}
|
|
}
|