/* ============================================================================ *\
|| ########################################################################## ||
|| # Auction Software Marketplace Release: 0.6 Build 0.7 # ||
|| # ---------------------------------------------------------------------- # ||
|| # License # 35YAHCNR9344X6O666C123AB # ||
|| # ---------------------------------------------------------------------- # ||
|| # Copyright ©2014–2021 Develop Scripts LLC. All Rights Reserved # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ------------- AUCTION SOFTWARE IS NOT FREE SOFTWARE ------------------ # ||
|| # http://www.auctionsoftwaremarketplace.com|support@auctionsoftware.com # ||
|| # ---------------------------------------------------------------------- # ||
|| ########################################################################## ||
\* ============================================================================ */
/* eslint-disable prefer-destructuring */
/* eslint-disable no-param-reassign */
const dateFormat = require('dateformat')
const commonFunction = require('../../../common/function').default
const appointmentModule = require('../../modules/appointment').default
const { jsonResponse } = require('../logger')
/**
* Appointment check
*
* @memberOf frontend.appointment
* @param {commonFunction.getValidID} module
* @param {commonFunction.tableFunction} module
*/
const appointmentCheck = async (payLog, userID, req) => {
let appointmentID = 0
if (typeof global.configurations.variables.schedule_appointment !== 'undefined') {
if (global.configurations.variables.schedule_appointment) {
payLog.payment_object = payLog.payment_object ? payLog.payment_object : ''
if (payLog.payment_object !== '') {
const appointmentData = {
body: JSON.parse(payLog.payment_object),
}
appointmentData.body.id = commonFunction.getValidID(appointmentData.body.id)
if (appointmentData.body.id) {
appointmentID = appointmentData.body.id.toString()
} else {
const baseTableUsed = global.configColumns.appointments
const customTableUsed = { enabled: 0 }
if (appointmentData.body.appointmentTime) {
appointmentData.body.appointmentTime = dateFormat(
new Date(appointmentData.body.appointmentTime),
'yyyy-mm-dd HH:MM:ss',
)
}
appointmentData.body.userId = userID
appointmentData.body.createdAt = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
console.log('appointmentData', appointmentData)
const [resultsappointment] = await Promise.all([
commonFunction.tableFunction(
appointmentData,
baseTableUsed,
customTableUsed,
),
])
console.log('resultsappointment', resultsappointment)
appointmentID = resultsappointment[0].insertId.toString()
}
}
}
}
return appointmentID
}
/**
* Get Appointment deatils
*
* @memberOf frontend.getAppointmentDetails
* @param {commonFunction.getValidID} module
* @param {commonFunction.tableFunction} module
*/
const getAppointmentDetails = async (appointmentID, req) => {
let record = ''
if (typeof global.configurations.variables.schedule_appointment !== 'undefined') {
if (global.configurations.variables.schedule_appointment) {
req.body.id = commonFunction.getValidID(appointmentID)
const baseTableUsed = global.configColumns.appointments
const customTableUsed = { enabled: 0 }
const [records] = await Promise.all([
commonFunction.fetchTableFunction(req, baseTableUsed, customTableUsed),
])
record = records[0]
}
}
return record
}
module.exports = {
appointmentCheck,
getAppointmentDetails,
/**
* Get Appointment deatils
*
* @memberOf frontend.checkAppointments
* @param {appointmentModule.getAllAvailableAppointments} module
*/
checkAppointments: async (req, res) => {
try {
const [records] = await Promise.all([
appointmentModule.getAllAvailableAppointments(req),
])
const responseData = {
records,
}
jsonResponse(res, 'success', {
responseType: 1,
message: 'Details successfully retrieved!',
responseData,
})
} catch (e) {
console.error(e)
jsonResponse(res, 'error', {
responseType: 3,
message: 'Internal Server error!',
})
}
},
}