/* ============================================================================ *\
|| ########################################################################## ||
|| # 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
/**
* @class class to handle auction functions
*/
class auctionModule {
/**
* Search all the search auction
* @param {object} req req object
* @param {object} data req.body object
* @param {number} count count for the pagination
* @returns {object} sql response
*/
static async searchAuctions(req, data, count) {
let mysql = ''
let row = ''
let order = ''
const sortorder = data.orderby
let where = ''
let limitf = ''
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
if (sortorder === 1) {
order = 'a.date_closed asc'
} else if (sortorder === 2) {
order = 'a.id desc '
}
where += ` and a.market_status = "open" and a.date_closed >= "${dateNow}" `
if (req.body.searchbar !== '' && req.body.searchbar) {
let changed = req.body.searchbar.replace(/\\/g, '\\\\\\\\')
changed = changed.replace(/"/g, '\\"')
where = ` and (a.title like "%${changed}%")${where}`
}
row = count === 1 ? 'get_all_auction_search_limit' : 'get_all_auction_search'
const limitrg = req.body.limit
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
let escapeData = []
if (count === 1) {
let pagen = (req.body.page - 1) * limitrg
if (parseInt(pagen, 10) < 0) {
pagen = 0
}
limitf = ` limit ${pagen},${limitrg}`
escapeData = [uidc]
} else {
escapeData = [uidc]
}
const ordergor = order === '' ? '' : `order by ${order}`
mysql = {
where,
order: ordergor,
limitf,
dateNow,
}
const strQuery = await mysqclass.mysqli(mysql, row)
const dataReturn = await global.mysql.query(strQuery, escapeData)
console.log('totalRecords', strQuery, escapeData)
return dataReturn
}
}
module.exports.default = auctionModule