/* ============================================================================ *\
|| ########################################################################## ||
|| # 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 commonSQL = require('../../common/sql').default
const commonProduct = require('../../common/products').default
const commonFunction = require('../../common/function').default
/**
* @class class to handle product functions
*/
class productModule {
/**
* Search all the search products
* @param {object} req req object
* @param {object} data req.body object
* @param {number} count count for the pagination
* @returns {object} sql response
*/
static async searchProducts(req, data, count) {
const mysql = {}
const baseTableUsed = global.configColumns.projects
const customTableUsed = global.configColumns.custom_projects
let row = ''
let where = ''
let limitf = ''
let order = ''
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
order = `p.id desc`
if (req.body.orderby || req.body.order) {
const sortReturn = commonProduct.sortOrderData(req, where)
if (sortReturn.order) {
order = sortReturn.order
}
if (sortReturn.where) {
where += sortReturn.where
}
}
if (req.body.similars) {
where += commonProduct.similarData(req)
}
if (req.body.filters) {
where += commonProduct.filterData(req)
}
where += `and p.market_status = "open" and p.date_closed >= "${dateNow}" `
if (data.type === 'live') {
where += ` and p.date_added <= "${dateNow}" `
}
const generatedData = commonProduct.generateJoinWithColum(baseTableUsed, customTableUsed, [
'id',
])
mysql.customTableJoin = generatedData.customTableJoin
mysql.columns = generatedData.rowstoFetch
row = count === 1 ? 'ingram_13' : 'ingram_13a'
const limitrg = req.body.limit
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
const escapeData = []
if (count === 1) {
let pagen = (req.body.page - 1) * limitrg
if (parseInt(pagen, 10) < 0) {
pagen = 0
}
limitf = ` limit ${pagen},${limitrg}`
}
mysql.userid = uidc
mysql.order = order
mysql.where = where
mysql.limitf = limitf
mysql.dateNow = dateNow
const strQuery = await mysqclass.mysqli(mysql, row)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Search all the dashboard products
* @param {object} req req object
* @param {object} data req.body object
* @param {number} count count for the pagination
* @returns {object} sql response
*/
static async searchDashboardProducts(req, data, count) {
const actionValue = data.action
const mysql = {}
const baseTableUsed = global.configColumns.projects
const customTableUsed = global.configColumns.custom_projects
let row = ''
let where = ''
let limitf = ''
let order = ''
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
order = `p.id desc`
if (req.body.orderby || req.body.order) {
const sortReturn = commonProduct.sortOrderData(req, where)
if (sortReturn.order) {
order = sortReturn.order
}
if (sortReturn.where) {
where += sortReturn.where
}
}
if (req.body.similars) {
where += commonProduct.similarData(req)
}
if (req.body.filters) {
where += commonProduct.filterData(req)
}
if (actionValue !== '') {
if (
actionValue === 'auction' ||
actionValue === 'winning' ||
actionValue === 'outbid'
) {
row = count === 1 ? 'dash_auction_item' : 'dash_auction_item_count'
if (actionValue === 'winning') {
where += ` and p.market_status = "open"`
where += ` and p.date_closed >= "${dateNow}" `
where += `and (select IFNULL(bb.user_id,0) as latestbiduser_id from bids AS bb where bb.project_id = p.id and bb.proposal != "tie_bid" order by bb.proposed_amount desc limit 1) = "${uidc}"`
} else if (actionValue === 'outbid') {
where += ` and p.market_status = "open"`
where += ` and p.date_closed >= "${dateNow}" `
where += `and (select IFNULL(bb.user_id,0) as latestbiduser_id from bids AS bb where bb.project_id = p.id and bb.proposal != "tie_bid" order by bb.proposed_amount desc limit 1) != "${uidc}"`
} else {
where += ` and (p.market_status = "open" or p.market_status = "sold")`
}
} else if (actionValue === 'watchlist') {
where += ` and p.market_status = "open" and p.date_closed >= "${dateNow}" `
row = count === 1 ? 'dash_watchlist_item' : 'dash_watchlist_item_count'
} else if (actionValue === 'won') {
where += ' and p.market_status = "sold" '
row = count === 1 ? 'dash_won_item' : 'dash_won_item_count'
}
}
const generatedData = commonProduct.generateJoinWithColum(baseTableUsed, customTableUsed, [
'id',
])
mysql.customTableJoin = generatedData.customTableJoin
mysql.columns = generatedData.rowstoFetch
const limitrg = req.body.limit
const escapeData = []
if (count === 1) {
let pagen = (req.body.page - 1) * limitrg
if (parseInt(pagen, 10) < 0) {
pagen = 0
}
limitf = ` limit ${pagen},${limitrg}`
}
mysql.order = order
mysql.where = where
mysql.limitf = limitf
mysql.dateNow = dateNow
mysql.userid = uidc
const strQuery = await mysqclass.mysqli(mysql, row)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Search all the invoice products
* @param {object} req req object
* @param {object} data req.body object
* @param {number} count count for the pagination
* @returns {object} sql response
*/
static async searchInvoiceProducts(req, data, count) {
let mysql = ''
let row = ''
let order = ''
const sortorder = data.orderby
const actionValue = data.action
let where = ''
let limitf = ''
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
if (req.body.paid) {
where += ` and pc.cart_paid = 1`
}
if (req.body.checkout) {
where += ` and pc.cart_checkout = 1`
}
if (req.body.unpaid) {
where += ` and pc.cart_paid = 0`
}
order = 'pc.cart_paiddate desc'
row = count === 1 ? 'invoice_item' : 'invoice_item_count'
const limitrg = req.body.limit
const escapeData = []
if (count === 1) {
let pagen = (req.body.page - 1) * limitrg
if (parseInt(pagen, 10) < 0) {
pagen = 0
}
limitf = ` limit ${pagen},${limitrg}`
}
const ordergor = order === '' ? '' : `order by ${order}`
mysql = {
where,
order: ordergor,
limitf,
userid: uidc,
}
const strQuery = await mysqclass.mysqli(mysql, row)
console.log('row', strQuery)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Search all the return products
* @param {object} req req object
* @param {object} data req.body object
* @param {number} count count for the pagination
* @returns {object} sql response
*/
static async searchReturnProducts(req, data, count) {
let mysql = ''
let row = ''
let order = ''
const sortorder = data.orderby
const actionValue = data.action
let where = ''
let limitf = ''
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
if (req.body.paid) {
where += ` and rc.paid = 1`
}
if (req.body.checkout) {
where += ` and rc.checkout = 1`
}
if (req.body.unpaid) {
where += ` and rc.paid = 0`
}
order = 'rc.paiddate desc'
row = count === 1 ? 'return_item' : 'return_item_count'
const limitrg = req.body.limit
const escapeData = []
if (count === 1) {
let pagen = (req.body.page - 1) * limitrg
if (parseInt(pagen, 10) < 0) {
pagen = 0
}
limitf = ` limit ${pagen},${limitrg}`
}
const ordergor = order === '' ? '' : `order by ${order}`
mysql = {
where,
order: ordergor,
limitf,
userid: uidc,
}
const strQuery = await mysqclass.mysqli(mysql, row)
console.log('row', strQuery)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Search all the attachments for products
* @param {object} req req object
* @param {object} data req.body object
* @param {number} count count for the pagination
* @returns {object} sql response
*/
static async fetchAllAttachments(pid) {
const mysql = {}
const escapeData = [pid]
const strQuery = await mysqclass.mysqli(mysql, 'im_26')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async checkbidPlacedwhoutlogin(pid) {
const mysql = {}
const escapeData = [pid]
const strQuery = await mysqclass.mysqli(mysql, 'im_818')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getProxyDetails(pid, type) {
const mysql = {}
let escapeData = []
if (type === 'get_highest_biduser') {
escapeData = [pid, 0]
} else if (type === 'second_highest_biduser') {
escapeData = [pid, 1]
}
const strQuery = await mysqclass.mysqli(mysql, 'get_proxy_details')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async bidsnotifyall(pid, uid) {
const mysql = {}
mysql.where = ''
const escapeData = [pid, uid]
const strQuery = await mysqclass.mysqli(mysql, 'im_822')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async bidsawarded(pid, uid) {
const mysql = {}
const escapeData = [pid, uid]
const strQuery = await mysqclass.mysqli(mysql, 'im_823')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getUserProxyAmt(pid, uid) {
const mysql = {}
const escapeData = [pid, uid]
const strQuery = await mysqclass.mysqli(mysql, 'im_824')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Fetch All Bid history
* @param {object} id project id
* @param {number} cnt count for the pagination
* @returns {object} sql response
*/
static async isbuyerbidstarted(pid, uid) {
const mysql = {}
const escapeData = [pid, uid]
const strQuery = await mysqclass.mysqli(mysql, 'im_821')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Fetch All Bid history
* @param {object} id project id
* @param {number} cnt count for the pagination
* @returns {object} sql response
*/
static async bidHistory(id, cnt) {
const mysql = {}
let row = ''
if (cnt === 1) {
row = 'im_45'
} else {
row = 'im_44'
}
const escapeData = [id]
const strQuery = await mysqclass.mysqli(mysql, row)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Fetch Bid history
* @param {object} req req.body
* @param {number} count count for the pagination
* @returns {object} sql response
*/
static async bidHistoryViewPage(req, count) {
const mysql = {}
mysql.where = ''
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
mysql.order = 'order by bh.id desc'
const order = req.body.order === '' ? 'asc' : req.body.order
const orderby = req.body.orderby === '' && !req.body.orderby ? '' : req.body.orderby
if (orderby !== '') {
mysql.order = ` order by ${orderby} ${order}`
}
// if (req.body.searchterm !== '' && req.body.searchterm !== undefined) {
// let changed = req.body.searchterm.replace(/\\/g, '\\\\\\\\')
// changed = changed.replace(/"/g, '\\"')
// mysql.where += `and (u.first_name like "%${changed}%" or p.id like "%${changed}%")`
// }
let row = ''
const pagen = (req.body.page - 1) * req.body.limit
const limitf = ` limit ${pagen},${req.body.limit}`
mysql.limit = limitf
mysql.dateNow = dateNow
const escapeData = [req.body.id]
if (count === 1) {
row = 'get_all_bid_history_limit'
} else {
row = 'get_all_bid_history'
}
const strQuery = await mysqclass.mysqli(mysql, row)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getSearchSortCategories(req, data) {
const mysql = {}
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
mysql.where = ''
const selectQuery = []
const processAllItems = async (items) => {
const tableValue = global.configColumns[items]
if (tableValue.search && tableValue.enabled) {
selectQuery.push(
`GROUP_CONCAT(DISTINCT ${tableValue.foreign_key} ORDER BY ${tableValue.foreign_key}) as sort${tableValue.ext_name}`,
)
}
}
await commonFunction.asyncForEach(Object.keys(global.configColumns), async (element) => {
await processAllItems(element)
})
mysql.where += ` and p.market_status = "open" and p.date_closed >= "${dateNow}" `
mysql.selectQuery = selectQuery.toString()
const strQuery = await mysqclass.mysqli(mysql, 'ig_571')
const dataReturn = await global.mysql.query(strQuery)
return dataReturn
}
// For Invoice
static async allInvoiceItems(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 += `and b.common_invoice = ${req.body.invoice_id}`
row = 'invoice_all_item'
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}`
const generatedData = commonProduct.generateJoinWithColum(baseTableUsed, customTableUsed, [
'id',
])
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)
console.log('strQuery', strQuery, escapeData)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getInvoiceCartDetails(cartID) {
const mysql = {}
const escapeData = [cartID]
const strQuery = await mysqclass.mysqli(mysql, 'get_cart_invoice_all_data')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getAllTransactions(cartID) {
const mysql = {}
const escapeData = [cartID]
const strQuery = await mysqclass.mysqli(mysql, 'get_cart_invoice_transactions_data')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getAppointmentDetails(cartID) {
const mysql = {}
const escapeData = [cartID]
const strQuery = await mysqclass.mysqli(mysql, 'get_cart_invoice_appointment_data')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getLocationDetails(cartID) {
const mysql = {}
const escapeData = [cartID]
const strQuery = await mysqclass.mysqli(mysql, 'get_cart_invoice_location_data')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
// For Invoice
static async allReturnInvoiceItems(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 += `and b.return_invoice = ${req.body.invoice_id}`
row = 'returninvoice_all_item'
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}`
const generatedData = commonProduct.generateJoinWithColum(baseTableUsed, customTableUsed, [
'id',
])
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)
console.log('strQuery', strQuery, escapeData)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getReturnInvoiceCartDetails(cartID) {
const mysql = {}
const escapeData = [cartID]
const strQuery = await mysqclass.mysqli(mysql, 'get_cart_returninvoice_all_data')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getAllReturnTransactions(cartID) {
const mysql = {}
const escapeData = [cartID]
const strQuery = await mysqclass.mysqli(mysql, 'get_cart_returninvoice_transactions_data')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getReturnAppointmentDetails(cartID) {
const mysql = {}
const escapeData = [cartID]
const strQuery = await mysqclass.mysqli(mysql, 'get_cart_returninvoice_appointment_data')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getReturnLocationDetails(cartID) {
const mysql = {}
const escapeData = [cartID]
const strQuery = await mysqclass.mysqli(mysql, 'get_cart_returninvoice_location_data')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async postproduct(req, data) {
const mysqli = {}
let escapeData = []
const baseTableUsed = global.configColumns.projects
const postData = data
const acceptedObjects = baseTableUsed.array_columns
const defaultKeys = ['created_at', 'updated_at']
const defaultValues = [
dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss'),
dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss'),
]
const valueInsert = commonSQL.InsertSQLFunction(
postData,
acceptedObjects,
defaultKeys,
defaultValues,
)
mysqli.keys = valueInsert.keys
escapeData = valueInsert.escapeData
mysqli.values = valueInsert.values
mysqli.tables = baseTableUsed.ext_name
const strQuery = await mysqclass.mysqli(mysqli, 'insert_tables')
const dataPromise = await global.mysql.query(strQuery, escapeData)
return dataPromise
}
static async postlistingCustom(req, data, proID) {
const mysqli = {}
let escapeData = []
const customTableUsed = global.configColumns.custom_projects
const postData = data
postData.product_id = proID
const acceptedObjects = customTableUsed.array_columns
const defaultKeys = ['created_at']
const defaultValues = [dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')]
const valueInsert = commonSQL.InsertSQLFunction(
postData,
acceptedObjects,
defaultKeys,
defaultValues,
)
mysqli.keys = valueInsert.keys
escapeData = valueInsert.escapeData
mysqli.values = valueInsert.values
mysqli.tables = customTableUsed.ext_name
const strQuery = await mysqclass.mysqli(mysqli, 'insert_tables')
const dataPromise = await global.mysql.query(strQuery, escapeData)
return dataPromise
}
static async updateproduct(req, data) {
const mysqli = {}
let escapeData = []
const baseTableUsed = global.configColumns.projects
const postData = data
const acceptedObjects = baseTableUsed.array_columns
const defaultKeys = ['updated_at']
const defaultValues = [dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')]
const valueInsert = commonSQL.updateSQLFunction(
postData,
acceptedObjects,
defaultKeys,
defaultValues,
)
mysqli.keys = valueInsert.keys
escapeData = valueInsert.escapeData
mysqli.values = ` id=${req.body.id}`
mysqli.tables = baseTableUsed.ext_name
const strQuery = await mysqclass.mysqli(mysqli, 'update_tables')
const dataPromise = await global.mysql.query(strQuery, escapeData)
return dataPromise
}
static async updatelistingCustom(req, data, proID) {
const mysqli = {}
let escapeData = []
const customTableUsed = global.configColumns.custom_projects
const postData = data
const acceptedObjects = customTableUsed.array_columns
const defaultKeys = ['updated_at']
const defaultValues = [dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')]
const valueInsert = commonSQL.updateSQLFunction(
postData,
acceptedObjects,
defaultKeys,
defaultValues,
)
mysqli.keys = valueInsert.keys
escapeData = valueInsert.escapeData
mysqli.values = `product_id =${req.body.id}`
mysqli.tables = customTableUsed.ext_name
const strQuery = await mysqclass.mysqli(mysqli, 'update_tables')
const dataPromise = await global.mysql.query(strQuery, escapeData)
return dataPromise
}
static async addattachement(data, proid) {
const mysqli = {}
const escapeData = [
proid,
data.file_name,
1,
data.user_id,
data.orderby,
dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss'),
]
mysqli.keys = 'project_id,file_name,type,user_id,orderby,created_at'
mysqli.values = '?,?,?,?,?'
mysqli.tables = ' attachments '
const strQuery = await mysqclass.mysqli(mysqli, 'insert_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async commonselectparenttable(data, proid, baseTableUsed, baseid) {
const mysqli = {}
const proId = proid.split(',')
const escapeData = [proId]
mysqli.keys = data
mysqli.values = `${baseid} IN (?)`
mysqli.tables = baseTableUsed.ext_name
mysqli.group_by = ''
mysqli.order_by = ''
mysqli.limit_by = ''
const strQuery = await mysqclass.mysqli(mysqli, 'select_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async addcategory(req, data) {
const mysqli = {}
let escapeData = []
const tableUsed = 'categories'
const postData = data
const acceptedObjects = global.configColumns[tableUsed].array_columns
const defaultKeys = ['created_at']
const defaultValues = [dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')]
const valueInsert = commonSQL.InsertSQLFunction(
postData,
acceptedObjects,
defaultKeys,
defaultValues,
)
mysqli.keys = valueInsert.keys
escapeData = valueInsert.escapeData
mysqli.values = valueInsert.values
mysqli.tables = tableUsed
const strQuery = await mysqclass.mysqli(mysqli, 'insert_tables')
const dataPromise = await global.mysql.query(strQuery, escapeData)
return dataPromise
}
static async updatecategory(req, data) {
const mysqli = {}
let escapeData = []
const tableUsed = 'categories'
const postData = data
const acceptedObjects = global.configColumns[tableUsed].array_columns
const defaultKeys = ['created_at']
const defaultValues = [dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')]
const valueInsert = commonSQL.updateSQLFunction(
postData,
acceptedObjects,
defaultKeys,
defaultValues,
)
mysqli.keys = valueInsert.keys
escapeData = valueInsert.escapeData
mysqli.values = ` id=${req.body.id}`
mysqli.tables = tableUsed
const strQuery = await mysqclass.mysqli(mysqli, 'update_tables')
const dataPromise = await global.mysql.query(strQuery, escapeData)
return dataPromise
}
static async addattachementtoproduct(data, proid) {
const mysqli = {}
const escapeData = [data, proid]
mysqli.keys = ' avatar=?'
mysqli.values = ' id=?'
mysqli.tables = ' projects '
const strQuery = await mysqclass.mysqli(mysqli, 'update_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async deleteattachement(req, proid) {
const mysqli = {}
const escapeData = [proid]
mysqli.keys = ''
mysqli.values = ' project_id=?'
mysqli.tables = ' attachments '
const strQuery = await mysqclass.mysqli(mysqli, 'delete_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async postalltypeoflisting(req, data, baseTableUsed) {
const mysqli = {}
let escapeData = []
const postData = data
const acceptedObjects = baseTableUsed.array_columns
const defaultKeys = ['created_at', 'updated_at']
const defaultValues = [
dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss'),
dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss'),
]
const valueInsert = commonSQL.InsertSQLFunction(
postData,
acceptedObjects,
defaultKeys,
defaultValues,
)
mysqli.keys = valueInsert.keys
escapeData = valueInsert.escapeData
mysqli.values = valueInsert.values
mysqli.tables = baseTableUsed.ext_name
const strQuery = await mysqclass.mysqli(mysqli, 'insert_tables')
const dataPromise = await global.mysql.query(strQuery, escapeData)
return dataPromise
}
static async updatealltypeofproduct(req, data, proid, typeoffield, baseTableUsed) {
const mysqli = {}
let escapeData = []
const postData = data
const postID = proid
const fieldType = typeoffield
const acceptedObjects = baseTableUsed.array_columns
const defaultKeys = ['updated_at']
const defaultValues = [dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')]
const valueInsert = commonSQL.updateSQLFunction(
postData,
acceptedObjects,
defaultKeys,
defaultValues,
)
mysqli.keys = valueInsert.keys
escapeData = valueInsert.escapeData
mysqli.values = ` ${fieldType}=${postID}`
mysqli.tables = baseTableUsed.ext_name
const strQuery = await mysqclass.mysqli(mysqli, 'update_tables')
const dataPromise = await global.mysql.query(strQuery, escapeData)
return dataPromise
}
static async auctionProjectUpdateexist(req) {
const mysqli = {}
let projectId = []
if (req.body.project_id instanceof Array) {
projectId = req.body.project_id
} else {
projectId = req.body.project_id.split(',')
}
const escapeData = [req.body.auction_id, projectId]
mysqli.keys = ' auctionid=?'
mysqli.values = ' id IN (?)'
mysqli.tables = ' projects '
const strQuery = await mysqclass.mysqli(mysqli, 'update_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async auctionProjectUpdateexistrest(req) {
const mysqli = {}
const escapeData = [0, req.body.id]
mysqli.keys = ' auctionid=?'
mysqli.values = ' auctionid=?'
mysqli.tables = ' projects '
const strQuery = await mysqclass.mysqli(mysqli, 'update_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getlotdetails(data, proid, baseTableUsed) {
const mysqli = {}
const proId = proid.split(',')
const escapeData = [proId]
mysqli.keys = data
mysqli.values = ' id IN (?) '
mysqli.tables = baseTableUsed.ext_name
mysqli.group_by = ''
mysqli.order_by = ''
mysqli.limit_by = ''
const strQuery = await mysqclass.mysqli(mysqli, 'select_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getCommonInvoiceNo(data, proid, baseTableUsed) {
const mysqli = {}
const escapeData = []
mysqli.keys = data
mysqli.values = ' id>0 '
mysqli.tables = baseTableUsed.ext_name
mysqli.group_by = ''
mysqli.order_by = 'order by common_invoice desc'
mysqli.limit_by = 'limit 1'
const strQuery = await mysqclass.mysqli(mysqli, 'select_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getlotcartsdetails(data, proid, userid, baseTableUsed) {
const mysqli = {}
const escapeData = [proid, userid]
mysqli.keys = data
mysqli.values = ' project_id=? and user_id=? and paid=0'
mysqli.tables = baseTableUsed.ext_name
mysqli.group_by = ''
mysqli.order_by = ''
mysqli.limit_by = ' limit 1'
const strQuery = await mysqclass.mysqli(mysqli, 'select_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async cartqtyproductsub(data, proid) {
const mysqli = {}
const proId = proid.split(',')
const escapeData = [data, proId]
mysqli.keys = ' booked = booked - ?'
mysqli.values = ' id IN (?) '
mysqli.tables = ' projects '
const strQuery = await mysqclass.mysqli(mysqli, 'update_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async productstatusupdate(data, proid) {
const mysqli = {}
const proId = proid.split(',')
const escapeData = [data, proId]
mysqli.keys = ' market_status = ?'
mysqli.values = ' id IN (?) '
mysqli.tables = ' projects '
const strQuery = await mysqclass.mysqli(mysqli, 'update_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async cartqtyproductsoldvalue(data, proid) {
const mysqli = {}
const proId = proid.split(',')
const escapeData = [data, proId]
mysqli.keys = ' sold = sold + ?'
mysqli.values = ' id IN (?) '
mysqli.tables = ' projects '
const strQuery = await mysqclass.mysqli(mysqli, 'update_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async cartqtyproduct(data, proid) {
const mysqli = {}
const proId = proid.split(',')
const escapeData = [data, proId]
mysqli.keys = ' booked = booked + ?'
mysqli.values = ' id IN (?) '
mysqli.tables = ' projects '
const strQuery = await mysqclass.mysqli(mysqli, 'update_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async updatecartsbuynow(req, data, baseTableUsed) {
const mysqli = {}
let escapeData = []
const postData = data
const acceptedObjects = baseTableUsed.array_columns
const defaultKeys = ['date_added', 'paid_date']
const defaultValues = [
dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss'),
dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss'),
]
const valueInsert = commonSQL.InsertSQLFunction(
postData,
acceptedObjects,
defaultKeys,
defaultValues,
)
mysqli.keys = valueInsert.keys
escapeData = valueInsert.escapeData
mysqli.values = valueInsert.values
mysqli.tables = baseTableUsed.ext_name
const strQuery = await mysqclass.mysqli(mysqli, 'insert_tables')
const dataPromise = await global.mysql.query(strQuery, escapeData)
return dataPromise
}
static async getcartsdetails(data, userID, sellID, baseTableUsed, baseTableUsed2) {
const mysqli = {}
let escapeData = []
if (sellID === 0) {
escapeData = [userID]
mysqli.values = ' c.user_id IN (?) '
} else {
escapeData = [userID, sellID]
mysqli.values = ' c.user_id IN (?) and c.seller_id (?) '
}
mysqli.keys = data
mysqli.tables = `${baseTableUsed.ext_name} as p inner join ${baseTableUsed2.ext_name}as c on (p.id=c.product_id)`
mysqli.group_by = ''
mysqli.order_by = ' order by c.id desc'
mysqli.limit_by = ''
const strQuery = await mysqclass.mysqli(mysqli, 'select_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async fetchAuctionbyID(pid) {
const mysql = {}
const escapeData = [pid]
const strQuery = await mysqclass.mysqli(mysql, 'get_single_auctions')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async updateAllCloseDates(dateAdded, dateClosed, id) {
const mysql = {}
const escapeData = [dateAdded, dateClosed, id]
const strQuery = await mysqclass.mysqli(mysql, 'update_all_auct_closedate')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async getAllSubLotsnew(id) {
const mysql = {}
const escapeData = [id]
const strQuery = await mysqclass.mysqli(mysql, 'getAllSubLots')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async updatelofdetails(id, date) {
const mysql = {}
const closeData = commonSQL.dateTimeConvert(date)
const escapeData = [closeData, id]
const strQuery = await mysqclass.mysqli(mysql, 'updatelotnew')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
static async commondeleteparenttable(proid, baseTableUsed, baseid) {
const mysqli = {}
const proId = proid.split(',')
const escapeData = [proId]
mysqli.values = `${baseid} IN (?)`
mysqli.tables = baseTableUsed.ext_name
const strQuery = await mysqclass.mysqli(mysqli, 'delete_tables')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
}
module.exports.default = productModule