Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/bases/base.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BaseRepository } from "src/repositories/base.repository";

export class BaseService<T, CreateDto extends Partial<T>, UpdateDto extends Partial<T>> {
constructor(protected readonly repository: BaseRepository<T>) {}

async findAll(): Promise<T[]> {
return this.repository.findAll();
}

async findById(id: number): Promise<T | null> {
return this.repository.findById(id);
}

async create(createDto: CreateDto): Promise<T> {
return this.repository.create(createDto);
}

async update(id: number, updateDto: UpdateDto): Promise<T> {
return this.repository.update(id, updateDto);
}

async delete(id: number): Promise<void> {
return this.repository.delete(id);
}
}
36 changes: 11 additions & 25 deletions src/cw_device_locations/cw_device_locations.service.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
// src/cw_device_locations/cw_device_locations.service.ts
import { Injectable } from '@nestjs/common';
import { CreateDeviceLocationDto } from './dto/create-device-location.dto';
import { UpdateDeviceLocationDto } from './dto/update-device-location.dto';
import { DeviceLocationRepository } from 'src/repositories/cw_device_locations.repository';
import { Database } from 'database.types';
import { BaseService } from 'src/bases/base.service';
import { CreateDeviceOwnerDto } from 'src/cw_device_owners/dto/create-device-owner.dto';
import { UpdateDeviceOwnerDto } from 'src/cw_device_owners/dto/update-device-owner.dto';
import { DeviceOwnerRepository } from 'src/repositories/cw_device_owners';

@Injectable()
export class CwDeviceLocationsService {
constructor(private readonly deviceLocationRepository: DeviceLocationRepository) {}

async findAll() {
return this.deviceLocationRepository.findAll();
}

async findById(id: number) {
return this.deviceLocationRepository.findById(id);
}
type DeviceOwnerRow = Database['public']['Tables']['cw_device_owners']['Row'];

async create(createDeviceLocationDto: CreateDeviceLocationDto) {
return this.deviceLocationRepository.create(createDeviceLocationDto);
}

async update(id: number, updateDeviceLocationDto: UpdateDeviceLocationDto) {
return this.deviceLocationRepository.update(id, updateDeviceLocationDto);
}

async delete(id: number) {
return this.deviceLocationRepository.delete(id);
@Injectable()
export class CwDeviceOwnersService extends BaseService<DeviceOwnerRow, CreateDeviceOwnerDto, UpdateDeviceOwnerDto> {
constructor(deviceOwnerRepository: DeviceOwnerRepository) {
super(deviceOwnerRepository);
}
}
}
30 changes: 8 additions & 22 deletions src/cw_device_owners/cw_device_owners.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,14 @@ import { Injectable } from '@nestjs/common';
import { CreateDeviceOwnerDto } from './dto/create-device-owner.dto';
import { UpdateDeviceOwnerDto } from './dto/update-device-owner.dto';
import { DeviceOwnerRepository } from 'src/repositories/cw_device_owners';
import { Database } from 'database.types';
import { BaseService } from 'src/bases/base.service';

@Injectable()
export class CwDeviceOwnersService {
constructor(private readonly deviceOwnerRepository: DeviceOwnerRepository) {}

async findAll() {
return this.deviceOwnerRepository.findAll();
}

async findById(id: number) {
return this.deviceOwnerRepository.findById(id);
}
type DeviceOwnerRow = Database['public']['Tables']['cw_device_owners']['Row'];

async create(createDeviceOwnerDto: CreateDeviceOwnerDto) {
return this.deviceOwnerRepository.create(createDeviceOwnerDto);
}

async update(id: number, updateDeviceOwnerDto: UpdateDeviceOwnerDto) {
return this.deviceOwnerRepository.update(id, updateDeviceOwnerDto);
}

async delete(id: number) {
return this.deviceOwnerRepository.delete(id);
@Injectable()
export class CwDeviceOwnersService extends BaseService<DeviceOwnerRow, CreateDeviceOwnerDto, UpdateDeviceOwnerDto> {
constructor(deviceOwnerRepository: DeviceOwnerRepository) {
super(deviceOwnerRepository);
}
}
}