/* ============================================================================ *\
|| ########################################################################## ||
|| # 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 # ||
|| # ---------------------------------------------------------------------- # ||
|| ########################################################################## ||
\* ============================================================================ */
const dateFormat = require('dateformat')
const md5 = require('md5')
const _ = require('underscore')
const mysqclass = require('./mysqli').default
const commonProduct = require('../../common/products').default
/**
* @class class to handle cart functions
*/
class returnModule {
/**
* Get all Cart Items
* @param {object} req request data
* @param {string} data data is the req.body
* @param {number} count Count for pagination or all data
* @returns {object} sql response
*/
static async allCartItems(req, data, count) {
const baseTableUsed = global.configColumns.projects
const customTableUsed = global.configColumns.custom_projects
const mysql = {}
let row = ''
let where = ''
const order = 'p.date_closed asc'
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
where +=
count === 1 ? `and b.returncart_id = ${req.body.cart_id}` : ' and b.returncart_id = 0'
const generatedData = commonProduct.generateJoinWithColum(baseTableUsed, customTableUsed, [
'id',
])
row = 'return_cart_all_item'
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
const escapeData = [req.body.invoice_id]
const ordergor = order === '' ? '' : `order by ${order}`
mysql.customTableJoin = generatedData.customTableJoin
mysql.columns = generatedData.rowstoFetch
mysql.where = where
mysql.order = ordergor
mysql.dateNow = dateNow
mysql.userid = uidc
const strQuery = await mysqclass.mysqli(mysql, row)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Get all Carts
* @param {object} req request data
* @returns {object} sql response
*/
static async getAllCarts(req) {
let mysql = ''
let row = ''
let where = ''
const order = 'rc.id asc'
where += ``
row = 'return_cart_all_cartid'
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
const escapeData = [uidc]
const ordergor = order === '' ? '' : `order by ${order}`
mysql = {
where,
order: ordergor,
userid: uidc,
}
const strQuery = await mysqclass.mysqli(mysql, row)
const dataReturn = await global.mysql.query(strQuery, escapeData)
console.log('strQuery', strQuery)
return dataReturn
}
/**
* Get all Appointments available for return
* @param {object} req request data
* @returns {object} sql response
*/
static async getAllAvailableAppointments(req) {
let mysql = ''
let row = ''
let where = ''
const order = 'a.id asc'
where += ``
row = 'get_all_available_appointments'
let uidc = 0
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
let betweenDate = new Date(new Date().getTime() + 3 * 24 * 60 * 60 * 1000)
betweenDate = dateFormat(betweenDate, 'yyyy-mm-dd HH:MM:ss')
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
const escapeData = [dateNow, betweenDate, uidc]
const ordergor = order === '' ? '' : `order by ${order}`
mysql = {
where,
order: ordergor,
userid: uidc,
}
const strQuery = await mysqclass.mysqli(mysql, row)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Get all Sort and Search Categories
* @param {object} req request data
* @returns {object} sql response
*/
static async getSearchSortCategories(req, data) {
const mysql = {}
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
mysql.where = ''
mysql.where += ` and p.market_status = "open" and p.date_closed >= "${dateNow}" `
const strQuery = await mysqclass.mysqli(mysql, 'ig_571')
const dataReturn = await global.mysql.query(strQuery)
return dataReturn
}
/**
* Get all Product exists for the user
* @param {object} req request data
* @param {string} id request data
* @returns {object} sql response
*/
static async checkUserProductExists(req, id) {
const mysql = {}
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
const escapeData = [uidc, id]
const strQuery = await mysqclass.mysqli(mysql, 'check_cart_user')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Check cart exists for the user
* @param {object} req request data
* @param {string} locationID locationID to which the cart is to be checked
* @returns {object} sql response
*/
static async checkUserCartExists(req, locationID) {
const mysql = {}
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
const escapeData = [uidc, locationID]
const strQuery = await mysqclass.mysqli(mysql, 'return_check_cart_user_exists')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Check User unpaid cart exists
* @param {object} req request data
* @returns {object} sql response
*/
static async checkUserUnPaidExists(req) {
const mysql = {}
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
const escapeData = [uidc]
const strQuery = await mysqclass.mysqli(mysql, 'check_cart_user_exists')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Get one cart details
* @param {object} cartID cartID for which the details has to be fetched
* @returns {object} sql response
*/
static async getCartDetails(cartID) {
const mysql = {}
const escapeData = [cartID]
const strQuery = await mysqclass.mysqli(mysql, 'return_get_cart_all_data')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Get cart location details
* @param {object} cartID cartID for which the location details has to be fetched
* @returns {object} sql response
*/
static async cartLocationDetails(cartID) {
const mysql = {}
const escapeData = [cartID]
const strQuery = await mysqclass.mysqli(mysql, 'return_get_cart_location_data')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Change Cart Status
* @param {object} req req object
* @param {object} cartChange status of the cart item
* @param {object} id cartID to which the status has to be changed
* @returns {object} sql response
*/
static async changeCartStatus(req, cartChange, id) {
const mysql = {}
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
const escapeData = [cartChange, uidc, id]
const strQuery = await mysqclass.mysqli(mysql, 'return_add_cart_to_user')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Add new cart entry
* @param {object} req req object
* @param {object} userDetails User Details for adding new cart
* @param {object} locationID locationID to which the cart is to be added
* @returns {object} sql response
*/
static async addNewCartEntry(req, userDetails, locationID) {
const mysql = {}
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
// const escapeData = [
// req.user.id,
// userDetails.first_name,
// userDetails.last_name,
// userDetails.address1,
// userDetails.address2,
// userDetails.city,
// userDetails.state,
// userDetails.zip,
// locationID,
// dateNow,
// ]
const escapeData = [req.user.id, locationID, dateNow]
const strQuery = await mysqclass.mysqli(mysql, 'return_insert_new_cart_user')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Update Cart Data
* @param {object} data req body object
* @param {number} id id to which the cart is to be updated
* @returns {object} sql response
*/
static async updateCartData(data, id) {
let postData = data
const mysqli = {}
const acceptedObjects = [
'per_total',
'total_items',
'tax_percent',
'total_tax',
'buyer_premium',
'total_premium',
'total_shipping',
'total_amount',
'paid',
]
postData = _.omit(postData, (value, key) => {
if (
_.isNull(value) ||
_.isUndefined(value) ||
value === '' ||
!_.contains(acceptedObjects, key)
) {
return true
}
return false
})
let escapeData = []
const defaultKeys = ['updated_at']
const defaultValues = [dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')]
const keyswithescape = defaultKeys.concat(_.keys(postData))
escapeData = defaultValues.concat(_.values(postData))
mysqli.keys = _.map(keyswithescape, (val) => {
return `${val} = ?`
})
mysqli.cart_id = id
const strQuery = await mysqclass.mysqli(mysqli, 'return_update_cart_details')
const dataPromise = await global.mysql.query(strQuery, escapeData)
return dataPromise
}
/**
* Relist Item
* @param {number} pID Project ID which has to be relisted
* @returns {object} sql response
*/
static async IMrelistall(pID) {
const mysql = {}
const extHours = global.configurations.variables.project_close_date
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
const minutesaddition = parseInt(extHours, 10) * 3600000 // *60000; from minutes to milli seconds
let dateClose = new Date(new Date().getTime() + minutesaddition)
dateClose = dateFormat(dateClose, 'yyyy-mm-dd HH:MM:ss')
const escapeData = [dateNow, dateClose, 'open', pID]
const strQuery = await mysqclass.mysqli(mysql, 'im_809')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Update the relisted item
* @param {number} pID Project ID which has to be relisted
* @param {number} status Status of the project on relist
* @returns {object} sql response
*/
static async updateRelisted(pID, status) {
const mysql = {}
const escapeData = [status, pID]
const strQuery = await mysqclass.mysqli(mysql, 'im_810')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Update the relisted item as returned
* @param {number} pID Project ID which has to be relisted
* @param {number} status Status of the project on relist
* @returns {object} sql response
*/
static async updateReturned(pID, status) {
const mysql = {}
const escapeData = [status, pID]
const strQuery = await mysqclass.mysqli(mysql, 'im_810_return')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Attachment of the relisted item
* @param {number} pID Project ID which has to be relisted
* @param {number} newID New Relisted Project ID to be added
* @returns {object} sql response
*/
static async IMrelistallAttach(pID, newID) {
const mysql = {}
const escapeData = [newID, pID]
const strQuery = await mysqclass.mysqli(mysql, 'im_809a')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Re assign avatar image
* @param {number} pID Project ID which has to be relisted
* @param {number} newID New Relisted Project ID to be added
* @returns {object} sql response
*/
static async reassignavatar(pID, newID) {
const mysql = {}
const escapeData = [pID, newID]
const strQuery = await mysqclass.mysqli(mysql, 'im_817')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
}
module.exports.default = returnModule