fix: get all device
This commit is contained in:
@@ -4,23 +4,24 @@ const {
|
||||
getDeviceByCodeDb,
|
||||
createDeviceDb,
|
||||
updateDeviceDb,
|
||||
softDeleteDeviceDb
|
||||
softDeleteDeviceDb,
|
||||
searchDevicesDb
|
||||
} = require('../db/device.db');
|
||||
const { ErrorHandler } = require('../helpers/error');
|
||||
|
||||
class DeviceService {
|
||||
// Get all devices
|
||||
static async getAllDevices() {
|
||||
const devices = await getAllDevicesDb();
|
||||
return devices;
|
||||
static async getAllDevices(search) {
|
||||
if (!search || search.trim() === '') {
|
||||
return await getAllDevicesDb();
|
||||
}
|
||||
return await searchDevicesDb(search);
|
||||
}
|
||||
|
||||
// Get device by ID
|
||||
static async getDeviceById(id) {
|
||||
const device = await getDeviceByIdDb(id);
|
||||
if (!device) {
|
||||
throw new ErrorHandler(404, 'Device not found');
|
||||
}
|
||||
if (!device) throw new ErrorHandler(404, 'Device not found');
|
||||
return device;
|
||||
}
|
||||
|
||||
@@ -38,7 +39,6 @@ class DeviceService {
|
||||
if (!data || typeof data !== 'object') data = {};
|
||||
|
||||
data.created_by = userId;
|
||||
data.is_active = 1;
|
||||
|
||||
// cek kode unik
|
||||
const existingDevice = await getDeviceByCodeDb(data.device_code);
|
||||
@@ -60,10 +60,15 @@ class DeviceService {
|
||||
}
|
||||
|
||||
data.updated_by = userId;
|
||||
data.updated_at = new Date();
|
||||
|
||||
const updatedDevice = await updateDeviceDb(id, data);
|
||||
|
||||
|
||||
await updateDeviceDb(id, data);
|
||||
return { message: 'Device updated successfully' };
|
||||
return {
|
||||
message: 'Device updated successfully',
|
||||
data: updatedDevice,
|
||||
};
|
||||
}
|
||||
|
||||
// Soft delete device
|
||||
|
||||
Reference in New Issue
Block a user