add: CRUD user schedule
This commit is contained in:
71
controllers/user_schedule.controller.js
Normal file
71
controllers/user_schedule.controller.js
Normal file
@@ -0,0 +1,71 @@
|
||||
const UserScheduleService = require('../services/user_schedule.service');
|
||||
const { setResponse, setResponsePaging, checkValidate } = require('../helpers/utils');
|
||||
const { insertUserScheduleSchema, updateUserScheduleSchema } = require('../validate/user_schedule.schema');
|
||||
|
||||
class UserScheduleController {
|
||||
// Get all User Schedule
|
||||
static async getAll(req, res) {
|
||||
const queryParams = req.query;
|
||||
|
||||
const results = await UserScheduleService.getAllUserScheduleDb(queryParams);
|
||||
const response = await setResponsePaging(queryParams, results, 'User Schedule found')
|
||||
|
||||
res.status(response.statusCode).json(response);
|
||||
}
|
||||
|
||||
// Get User Schedule by ID
|
||||
static async getById(req, res) {
|
||||
const { id } = req.params;
|
||||
|
||||
const results = await UserScheduleService.getUserScheduleByID(id);
|
||||
const response = await setResponse(results, 'User Schedule found')
|
||||
|
||||
res.status(response.statusCode).json(response);
|
||||
}
|
||||
|
||||
// Create User Schedule
|
||||
static async create(req, res) {
|
||||
const { error, value } = await checkValidate(insertUserScheduleSchema, req)
|
||||
|
||||
if (error) {
|
||||
return res.status(400).json(setResponse(error, 'Validation failed', 400));
|
||||
}
|
||||
|
||||
value.userId = req.user.user_id
|
||||
|
||||
const results = await UserScheduleService.createUserSchedules(value);
|
||||
const response = await setResponse(results, 'User Schedule created successfully')
|
||||
|
||||
return res.status(response.statusCode).json(response);
|
||||
}
|
||||
|
||||
// Update User Schedule
|
||||
static async update(req, res) {
|
||||
const { id } = req.params;
|
||||
|
||||
const { error, value } = checkValidate(updateUserScheduleSchema, req)
|
||||
|
||||
if (error) {
|
||||
return res.status(400).json(setResponse(error, 'Validation failed', 400));
|
||||
}
|
||||
|
||||
value.userId = req.user.user_id
|
||||
|
||||
const results = await UserScheduleService.updateUserSchedules(id, value);
|
||||
const response = await setResponse(results, 'User Schedule updated successfully')
|
||||
|
||||
res.status(response.statusCode).json(response);
|
||||
}
|
||||
|
||||
// Soft delete User Schedule
|
||||
static async delete(req, res) {
|
||||
const { id } = req.params;
|
||||
|
||||
const results = await UserScheduleService.deleteUserSchedules(id, req.user.user_id);
|
||||
const response = await setResponse(results, 'User Schedule deleted successfully')
|
||||
|
||||
res.status(response.statusCode).json(response);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserScheduleController;
|
||||
Reference in New Issue
Block a user