add: CRUD user schedule
This commit is contained in:
89
services/user_schedule.service.js
Normal file
89
services/user_schedule.service.js
Normal file
@@ -0,0 +1,89 @@
|
||||
const {
|
||||
getAllUserScheduleDb,
|
||||
getUserScheduleByIdDb,
|
||||
insertUserScheduleDb,
|
||||
updateUserScheduleDb,
|
||||
deleteUserScheduleDb
|
||||
} = require('../db/user_schedule.db');
|
||||
const { ErrorHandler } = require('../helpers/error');
|
||||
|
||||
class UserScheduleService {
|
||||
// Get all devices
|
||||
static async getAllUserScheduleDb(param) {
|
||||
try {
|
||||
const results = await getAllUserScheduleDb(param);
|
||||
|
||||
results.data.map(element => {
|
||||
});
|
||||
|
||||
return results
|
||||
} catch (error) {
|
||||
throw new ErrorHandler(error.statusCode, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Get device by ID
|
||||
static async getUserScheduleByID(id) {
|
||||
try {
|
||||
const result = await getUserScheduleByIdDb(id);
|
||||
|
||||
if (result.length < 1) throw new ErrorHandler(404, 'User Schedule not found');
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw new ErrorHandler(error.statusCode, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Create device
|
||||
static async createUserSchedules(data) {
|
||||
try {
|
||||
if (!data || typeof data !== 'object') data = {};
|
||||
|
||||
const result = await insertUserScheduleDb(data);
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw new ErrorHandler(error.statusCode, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Update device
|
||||
static async updateUserSchedules(id, data) {
|
||||
try {
|
||||
if (!data || typeof data !== 'object') data = {};
|
||||
|
||||
const dataExist = await getUserScheduleByIdDb(id);
|
||||
|
||||
if (dataExist.length < 1) {
|
||||
throw new ErrorHandler(404, 'UserSchedules not found');
|
||||
}
|
||||
|
||||
const result = await updateUserScheduleDb(id, data);
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw new ErrorHandler(error.statusCode, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Soft delete device
|
||||
static async deleteUserSchedules(id, userId) {
|
||||
try {
|
||||
const dataExist = await getUserScheduleByIdDb(id);
|
||||
|
||||
if (dataExist.length < 1) {
|
||||
throw new ErrorHandler(404, 'UserSchedules not found');
|
||||
}
|
||||
|
||||
const result = await deleteUserScheduleDb(id, userId);
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw new ErrorHandler(error.statusCode, error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserScheduleService;
|
||||
|
||||
Reference in New Issue
Block a user