Files
cod-api/controllers/notification_error_user.controller.js

90 lines
3.0 KiB
JavaScript

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, 'Notification Error User updated successfully')
res.status(response.statusCode).json(response);
}
// Soft delete Notification Error User
static async delete(req, res) {
const { id } = req.params;
const results = await NotificationErrorUserService.deleteNotificationErrorUser(id, req.user.user_id);
const response = await setResponse(results, 'Notification Error User deleted successfully')
res.status(response.statusCode).json(response);
}
static async resend(req, res) {
try {
const { id, contact_phone } = req.params;
const results = await NotificationErrorUserService.resendNotification(id, contact_phone);
const response = await setResponse(
results.data,
results.message,
);
res.status(response.statusCode).json(response);
} catch (error) {
const response = setResponse(null, error.message, error.statusCode || 500);
res.status(response.statusCode).json(response);
}
}
}
module.exports = NotificationErrorUserController;