feat: db tables and repo and service written
This commit is contained in:
38
server/src/repositories/wifiLocationRepository.ts
Normal file
38
server/src/repositories/wifiLocationRepository.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { injectable } from "tsyringe";
|
||||
import { WifiLocation } from "../models/wifiLocation";
|
||||
|
||||
@injectable()
|
||||
export class WifiLocationRepository {
|
||||
public async findAll() {
|
||||
return await WifiLocation.findAll();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user