feat: db tables and repo and service written
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import { inject, injectable } from "tsyringe";
|
||||
import { getLocationForWifiMemoized } from "../proxy/wigle";
|
||||
import { WifiScanRepository } from "../repositories/wifiScanRepository";
|
||||
|
||||
interface CreateWifiScanParams {
|
||||
@ -12,8 +11,6 @@ interface UpdateWifiScanParams {
|
||||
wifi_scan_id: string;
|
||||
mac?: string;
|
||||
rssi?: number;
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
}
|
||||
|
||||
@injectable()
|
||||
@ -31,23 +28,11 @@ export class WifiScanService {
|
||||
}
|
||||
|
||||
public async createWifiScan(data: CreateWifiScanParams) {
|
||||
const apiResponse = await getLocationForWifiMemoized(data.mac);
|
||||
|
||||
if (apiResponse !== undefined && apiResponse.results.length > 0)
|
||||
return this.repository.create({
|
||||
...data,
|
||||
latitude: apiResponse.results[0].trilat,
|
||||
longitude: apiResponse.results[0].trilong,
|
||||
});
|
||||
return this.repository.create(data);
|
||||
}
|
||||
|
||||
public async createWifiScans(data: CreateWifiScanParams[]) {
|
||||
let wifiScans = await Promise.all(
|
||||
data.map(async (wifi) => {
|
||||
return await this.createWifiScan(wifi);
|
||||
})
|
||||
);
|
||||
return wifiScans.filter((wifi) => wifi !== undefined);
|
||||
return await this.repository.createMany(data);
|
||||
}
|
||||
|
||||
public async updateWifiScan(data: UpdateWifiScanParams) {
|
||||
|
Reference in New Issue
Block a user