add: crud notif error user
This commit is contained in:
71
controllers/notification_error_user.controller.js
Normal file
71
controllers/notification_error_user.controller.js
Normal file
@@ -0,0 +1,71 @@
|
||||
const NotificationErrorUserService = require('../services/notification_error_user.service');
|
||||
const { setResponse, setResponsePaging, checkValidate } = require('../helpers/utils');
|
||||
const { insertNotificationErrorUserSchema, updateNotificationErrorUserSchema } = require('../validate/notification_error_user.schema');
|
||||
|
||||
class NotificationErrorUserController {
|
||||
// Get all NotificationErrorUser
|
||||
static async getAll(req, res) {
|
||||
const queryParams = req.query;
|
||||
|
||||
const results = await NotificationErrorUserService.getAllNotificationErrorUser(queryParams);
|
||||
const response = await setResponsePaging(queryParams, results, 'Notification Error User found')
|
||||
|
||||
res.status(response.statusCode).json(response);
|
||||
}
|
||||
|
||||
// Get NotificationErrorUser by ID
|
||||
static async getById(req, res) {
|
||||
const { id } = req.params;
|
||||
|
||||
const results = await NotificationErrorUserService.getNotificationErrorUserById(id);
|
||||
const response = await setResponse(results, 'Notification Error User found')
|
||||
|
||||
res.status(response.statusCode).json(response);
|
||||
}
|
||||
|
||||
// Create NotificationErrorUser
|
||||
static async create(req, res) {
|
||||
const { error, value } = await checkValidate(insertNotificationErrorUserSchema, req)
|
||||
|
||||
if (error) {
|
||||
return res.status(400).json(setResponse(error, 'Validation failed', 400));
|
||||
}
|
||||
|
||||
value.userId = req.user.user_id
|
||||
|
||||
const results = await NotificationErrorUserService.createNotificationErrorUser(value);
|
||||
const response = await setResponse(results, 'Notification Error User created successfully')
|
||||
|
||||
return res.status(response.statusCode).json(response);
|
||||
}
|
||||
|
||||
// Update NotificationErrorUser
|
||||
static async update(req, res) {
|
||||
const { id } = req.params;
|
||||
|
||||
const { error, value } = checkValidate(updateNotificationErrorUserSchema, req)
|
||||
|
||||
if (error) {
|
||||
return res.status(400).json(setResponse(error, 'Validation failed', 400));
|
||||
}
|
||||
|
||||
value.userId = req.user.user_id
|
||||
|
||||
const results = await NotificationErrorUserService.updateNotificationErrorUser(id, value);
|
||||
const response = await setResponse(results, 'Contact updated successfully')
|
||||
|
||||
res.status(response.statusCode).json(response);
|
||||
}
|
||||
|
||||
// Soft delete contact
|
||||
static async delete(req, res) {
|
||||
const { id } = req.params;
|
||||
|
||||
const results = await NotificationErrorUserService.deleteNotificationErrorUser(id, req.user.user_id);
|
||||
const response = await setResponse(results, 'Contact deleted successfully')
|
||||
|
||||
res.status(response.statusCode).json(response);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NotificationErrorUserController;
|
||||
Reference in New Issue
Block a user