diff --git a/controllers/notification_error_log.controller.js b/controllers/notification_error_log.controller.js index 64b6670..d928a77 100644 --- a/controllers/notification_error_log.controller.js +++ b/controllers/notification_error_log.controller.js @@ -55,7 +55,18 @@ class NotificationErrorLogController { return res.status(400).json(setResponse(error, 'Validation failed', 400)); } - value.created_by = req.user.user_id; + let createdBy, contactPhone; + + if (!isNaN(req.user.userId) && Number(req.user.userId) > 0) { + createdBy = Number(req.user.userId); + contactPhone = value.contact_phone || null; + } else { + createdBy = null; + contactPhone = req.user.userId; + } + + value.created_by = createdBy; + value.contact_phone = contactPhone; const results = await NotificationErrorLogService.createNotificationErrorLog(value); const response = await setResponse(results, 'Notification Error Log created successfully') diff --git a/services/notification_error_log.service.js b/services/notification_error_log.service.js index 45d9f58..b36a5b8 100644 --- a/services/notification_error_log.service.js +++ b/services/notification_error_log.service.js @@ -46,7 +46,7 @@ class NotificationErrorLogService { const store = { notification_error_id: data.notification_error_id, - contact_id: data.contact_id, + contact_phone: data.contact_phone, notification_error_log_description: data.notification_error_log_description, created_by: data.created_by }; diff --git a/validate/notification_error_log.schema.js b/validate/notification_error_log.schema.js index ed740b4..1083e9a 100644 --- a/validate/notification_error_log.schema.js +++ b/validate/notification_error_log.schema.js @@ -2,7 +2,7 @@ const Joi = require("joi"); const insertNotificationErrorLogSchema = Joi.object({ notification_error_id: Joi.number().integer().required(), - contact_id: Joi.number().integer().required(), + contact_phone: Joi.string().optional(), notification_error_log_description: Joi.string().required() });