admin/modules/product.js

  1. /* ============================================================================ *\
  2. || ########################################################################## ||
  3. || # Auction Software Marketplace Release: 0.6 Build 0.7 # ||
  4. || # ---------------------------------------------------------------------- # ||
  5. || # License # 35YAHCNR9344X6O666C123AB # ||
  6. || # ---------------------------------------------------------------------- # ||
  7. || # Copyright ©2014–2021 Develop Scripts LLC. All Rights Reserved # ||
  8. || # This file may not be redistributed in whole or significant part. # ||
  9. || # ------------- AUCTION SOFTWARE IS NOT FREE SOFTWARE ------------------ # ||
  10. || # http://www.auctionsoftwaremarketplace.com|support@auctionsoftware.com # ||
  11. || # ---------------------------------------------------------------------- # ||
  12. || ########################################################################## ||
  13. \* ============================================================================ */
  14. const dateFormat = require('dateformat')
  15. const md5 = require('md5')
  16. const _ = require('underscore')
  17. const moment = require('moment')
  18. const mysqclass = require('./mysqli').default
  19. /**
  20. * @class class to handle product functions
  21. */
  22. class adminProductModule {
  23. /**
  24. * Get all products
  25. * @param {object} req request data
  26. * @param {string} count count for the pagination
  27. * @returns {object} sql response
  28. */
  29. static async fetchProductsAll(req, count) {
  30. const mysql = {}
  31. mysql.where = ''
  32. const { action } = req.body
  33. const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
  34. if (action === 'unsold') {
  35. mysql.where += ' and (p.market_status = "unsold" or p.market_status = "closed") '
  36. } else {
  37. mysql.where += ` and p.market_status = "${action}"`
  38. }
  39. mysql.order = 'order by p.id desc'
  40. const order = req.body.order === '' ? 'asc' : req.body.order
  41. const orderby = req.body.orderby === '' && !req.body.orderby ? '' : req.body.orderby
  42. if (orderby !== '') {
  43. mysql.order = ` order by ${orderby} ${order}`
  44. }
  45. if (req.body.searchterm !== '' && req.body.searchterm !== undefined) {
  46. let changed = req.body.searchterm.replace(/\\/g, '\\\\\\\\')
  47. changed = changed.replace(/"/g, '\\"')
  48. mysql.where += `and (p.title like "%${changed}%" or p.id like "%${changed}%")`
  49. }
  50. const dateSortValue = req.body.fielddate ? req.body.fielddate : 'p.date_added'
  51. if (req.body.fromdate !== '' && req.body.fromdate !== undefined) {
  52. const date1 = dateFormat(
  53. new Date(
  54. moment(req.body.fromdate, global.configurations.variables.time_format).format(),
  55. ),
  56. 'yyyy-mm-dd',
  57. )
  58. mysql.where += ` and ${dateSortValue} >= "${date1} 00:00:00"`
  59. }
  60. if (req.body.todate !== '' && req.body.todate !== undefined) {
  61. const date2 = dateFormat(
  62. new Date(
  63. moment(req.body.todate, global.configurations.variables.time_format).format(),
  64. ),
  65. 'yyyy-mm-dd',
  66. )
  67. mysql.where += ` and ${dateSortValue} <= "${date2} 23:59:59"`
  68. }
  69. let row = ''
  70. const pagen = (req.body.page - 1) * req.body.limit
  71. const limitf = ` limit ${pagen},${req.body.limit}`
  72. mysql.limit = limitf
  73. mysql.dateNow = dateNow
  74. const escapeData = []
  75. if (count === 1) {
  76. row = 'get_all_products_limit'
  77. } else {
  78. row = 'get_all_products'
  79. }
  80. const strQuery = await mysqclass.mysqli(mysql, row)
  81. const dataReturn = await global.mysql.query(strQuery, escapeData)
  82. return dataReturn
  83. }
  84. /**
  85. * Get all active Auctions
  86. * @returns {object} sql response
  87. */
  88. static async fetchActiveAuctions() {
  89. const mysql = {}
  90. const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
  91. const escapeData = [dateNow, dateNow]
  92. const strQuery = await mysqclass.mysqli(mysql, 'get_all_auct_active')
  93. const dataReturn = await global.mysql.query(strQuery, escapeData)
  94. return dataReturn
  95. }
  96. /**
  97. * Update Project status
  98. * @param {string} status Status which has to be updated
  99. * @param {number} pid Project ID which status has to be updated
  100. * @returns {object} sql response
  101. */
  102. static async marketStatusUpdate(status, pid) {
  103. const mysql = {}
  104. const escapeData = [status, pid]
  105. const strQuery = await mysqclass.mysqli(mysql, 'prod_change_market_status')
  106. const dataReturn = await global.mysql.query(strQuery, escapeData)
  107. console.log('dataReturn', strQuery, escapeData)
  108. return dataReturn
  109. }
  110. }
  111. module.exports.default = adminProductModule