Files
LocationHub/server/src/repositories/wifiLocationRepository.ts

40 lines
1012 B
TypeScript

import { Attributes, FindOptions } from "sequelize";
import { injectable } from "tsyringe";
import { WifiLocation } from "../models/wifiLocation";
@injectable()
export class WifiLocationRepository {
public async findAll(options?: FindOptions<Attributes<WifiLocation>>) {
return await WifiLocation.findAll(options);
}
public async findById(id: string) {
return await WifiLocation.findByPk(id);
}
public async create(data: Partial<WifiLocation>) {
return await WifiLocation.create(data);
}
public async createMany(data: Partial<WifiLocation>[]) {
return await WifiLocation.bulkCreate(data);
}
public async update(id: string, data: Partial<WifiLocation>) {
const wifiScan = await this.findById(id);
if (wifiScan) {
return await wifiScan.update(data);
}
return null;
}
public async delete(id: string) {
const wifiScan = await this.findById(id);
if (wifiScan) {
await wifiScan.destroy();
return true;
}
return false;
}
}