admin/modules/setting.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 commonSQL = require('../../common/sql').default
  18. const mysqclass = require('./mysqli').default
  19. /**
  20. * @class class to handle settings functions
  21. */
  22. class adminSettingModule {
  23. /**
  24. * All Configurations
  25. * @param {object} req request data
  26. * @param {string} count count for the pagination
  27. * @returns {object} sql response
  28. */
  29. static async allConfiguration(req, count) {
  30. const mysql = {}
  31. req.body.action = typeof req.body.action === 'undefined' ? 'email' : req.body.action
  32. mysql.where = ''
  33. const { action } = req.body
  34. const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
  35. mysql.order = 'order by id desc'
  36. const order = req.body.order === '' ? 'asc' : req.body.order
  37. const orderby = req.body.orderby === '' && !req.body.orderby ? '' : req.body.orderby
  38. if (orderby !== '') {
  39. mysql.order = ` order by ${orderby} ${order}`
  40. }
  41. if (req.body.searchterm !== '' && req.body.searchterm !== undefined) {
  42. let changed = req.body.searchterm.replace(/\\/g, '\\\\\\\\')
  43. changed = changed.replace(/"/g, '\\"')
  44. mysql.where += `and (name like "%${changed}%" or id like "%${changed}%")`
  45. }
  46. let row = ''
  47. const pagen = (req.body.page - 1) * req.body.limit
  48. const limitf = ` limit ${pagen},${req.body.limit}`
  49. mysql.limit = limitf
  50. mysql.dateNow = dateNow
  51. const escapeData = [action]
  52. if (count === 1) {
  53. row = 'get_all_setting_configuration_limit'
  54. } else {
  55. row = 'get_all_setting_configuration'
  56. }
  57. const strQuery = await mysqclass.mysqli(mysql, row)
  58. const dataReturn = await global.mysql.query(strQuery, escapeData)
  59. return dataReturn
  60. }
  61. /**
  62. * All Single Configuration
  63. * @param {number} id ID which the configuration has to be fetched
  64. * @returns {object} sql response
  65. */
  66. static async getConfigurationbyId(id) {
  67. const mysql = {}
  68. const escapeData = [id]
  69. const strQuery = await mysqclass.mysqli(mysql, 'get_single_setting_configuration')
  70. const dataReturn = await global.mysql.query(strQuery, escapeData)
  71. return dataReturn
  72. }
  73. /**
  74. * All Single Configuration
  75. * @param {object} req req object
  76. * @returns {object} sql response
  77. */
  78. static async configurationOperation(req) {
  79. const mysql = {}
  80. const postData = req.body
  81. const acceptedObjects = ['value', 'variable', 'question', 'enabled', 'type']
  82. let escapeData = []
  83. let row = ''
  84. if (req.body.id) {
  85. const defaultKeys = []
  86. const defaultValues = []
  87. const valueInsert = commonSQL.updateSQLFunction(
  88. postData,
  89. acceptedObjects,
  90. defaultKeys,
  91. defaultValues,
  92. )
  93. mysql.keys = valueInsert.keys
  94. escapeData = valueInsert.escapeData
  95. row = 'update_on_setting_configuration'
  96. mysql.static_page_id = req.body.id
  97. } else {
  98. const defaultKeys = []
  99. const defaultValues = []
  100. const valueInsert = commonSQL.InsertSQLFunction(
  101. postData,
  102. acceptedObjects,
  103. defaultKeys,
  104. defaultValues,
  105. )
  106. mysql.keys = valueInsert.keys
  107. mysql.values = valueInsert.values
  108. escapeData = valueInsert.escapeData
  109. row = 'insert_into_setting_configuration'
  110. }
  111. const strQuery = await mysqclass.mysqli(mysql, row)
  112. const data = await global.mysql.query(strQuery, escapeData)
  113. return data
  114. }
  115. /**
  116. * Get All Bid Increment Values
  117. * @param {object} req request data
  118. * @param {string} count count for the pagination
  119. * @returns {object} sql response
  120. */
  121. static async getAllBidIncrements(req, count) {
  122. const mysql = {}
  123. mysql.where = ''
  124. mysql.order = 'order by id asc'
  125. const order = req.body.order === '' ? 'asc' : req.body.order
  126. const orderby = req.body.orderby === '' && !req.body.orderby ? '' : req.body.orderby
  127. if (orderby !== '') {
  128. mysql.order = ` order by ${orderby} ${order}`
  129. }
  130. let row = ''
  131. const pagen = (req.body.page - 1) * req.body.limit
  132. const limitf = ` limit ${pagen},${req.body.limit}`
  133. mysql.limit = limitf
  134. const escapeData = []
  135. if (count === 1) {
  136. row = 'get_all_bid_increments_limit'
  137. } else {
  138. row = 'get_all_bid_increments'
  139. }
  140. const strQuery = await mysqclass.mysqli(mysql, row)
  141. const dataReturn = await global.mysql.query(strQuery, escapeData)
  142. return dataReturn
  143. }
  144. /**
  145. * Get Single Bid Increment
  146. * @param {number} id ID in bid_increment table
  147. * @returns {object} sql response
  148. */
  149. static async getBidIncrementById(id) {
  150. const mysql = {}
  151. const escapeData = [id]
  152. const strQuery = await mysqclass.mysqli(mysql, 'get_single_bid_increment')
  153. const dataReturn = await global.mysql.query(strQuery, escapeData)
  154. return dataReturn
  155. }
  156. /**
  157. * Bid Increment Change Operation
  158. * @param {object} req req object
  159. * @returns {object} sql response
  160. */
  161. static async bidIncrementOperation(req) {
  162. const mysql = {}
  163. const postData = req.body
  164. const acceptedObjects = ['increment', 'from_amount', 'to_amount']
  165. let escapeData = []
  166. let row = ''
  167. if (req.body.id) {
  168. const defaultKeys = []
  169. const defaultValues = []
  170. const valueInsert = commonSQL.updateSQLFunction(
  171. postData,
  172. acceptedObjects,
  173. defaultKeys,
  174. defaultValues,
  175. )
  176. mysql.keys = valueInsert.keys
  177. escapeData = valueInsert.escapeData
  178. row = 'update_bid_increment'
  179. mysql.id = req.body.id
  180. } else {
  181. const defaultKeys = []
  182. const defaultValues = []
  183. const valueInsert = commonSQL.InsertSQLFunction(
  184. postData,
  185. acceptedObjects,
  186. defaultKeys,
  187. defaultValues,
  188. )
  189. mysql.keys = valueInsert.keys
  190. mysql.values = valueInsert.values
  191. escapeData = valueInsert.escapeData
  192. row = 'insert_bid_increment'
  193. }
  194. const strQuery = await mysqclass.mysqli(mysql, row)
  195. const data = await global.mysql.query(strQuery, escapeData)
  196. return data
  197. }
  198. /**
  199. * Delete Bid Increment
  200. * @param {number} id ID in bid_increment table
  201. * @returns {object} sql response
  202. */
  203. static async deleteBidIncrement(id) {
  204. const mysql = {}
  205. const escapeData = [id]
  206. const strQuery = await mysqclass.mysqli(mysql, 'delete_bid_increment')
  207. const dataReturn = await global.mysql.query(strQuery, escapeData)
  208. return dataReturn
  209. }
  210. /**
  211. * Get All buyer premium Values
  212. * @param {object} req request data
  213. * @param {string} count count for the pagination
  214. * @returns {object} sql response
  215. */
  216. static async getAllBuyerPremium(req, count) {
  217. const mysql = {}
  218. mysql.where = ''
  219. mysql.order = 'order by id asc'
  220. const order = req.body.order === '' ? 'asc' : req.body.order
  221. const orderby = req.body.orderby === '' && !req.body.orderby ? '' : req.body.orderby
  222. if (orderby !== '') {
  223. mysql.order = ` order by ${orderby} ${order}`
  224. }
  225. let row = ''
  226. const pagen = (req.body.page - 1) * req.body.limit
  227. const limitf = ` limit ${pagen},${req.body.limit}`
  228. mysql.limit = limitf
  229. const escapeData = []
  230. if (count === 1) {
  231. row = 'get_all_buyer_premiums_limit'
  232. } else {
  233. row = 'get_all_buyer_premiums'
  234. }
  235. const strQuery = await mysqclass.mysqli(mysql, row)
  236. const dataReturn = await global.mysql.query(strQuery, escapeData)
  237. return dataReturn
  238. }
  239. /**
  240. * Get Single Buyer Premium
  241. * @param {number} id ID in config_buyer_premium table
  242. * @returns {object} sql response
  243. */
  244. static async getBuyerPremiumById(id) {
  245. const mysql = {}
  246. const escapeData = [id]
  247. const strQuery = await mysqclass.mysqli(mysql, 'get_single_buyer_premium')
  248. const dataReturn = await global.mysql.query(strQuery, escapeData)
  249. return dataReturn
  250. }
  251. /**
  252. * Buyer Premium Change Operation
  253. * @param {object} req req object
  254. * @returns {object} sql response
  255. */
  256. static async buyerPremiumOperation(req) {
  257. const mysql = {}
  258. const postData = req.body
  259. const acceptedObjects = ['increment', 'from_amount', 'to_amount']
  260. let escapeData = []
  261. let row = ''
  262. if (req.body.id) {
  263. const defaultKeys = []
  264. const defaultValues = []
  265. const valueInsert = commonSQL.updateSQLFunction(
  266. postData,
  267. acceptedObjects,
  268. defaultKeys,
  269. defaultValues,
  270. )
  271. mysql.keys = valueInsert.keys
  272. escapeData = valueInsert.escapeData
  273. row = 'update_buyer_premium'
  274. mysql.id = req.body.id
  275. } else {
  276. const defaultKeys = []
  277. const defaultValues = []
  278. const valueInsert = commonSQL.InsertSQLFunction(
  279. postData,
  280. acceptedObjects,
  281. defaultKeys,
  282. defaultValues,
  283. )
  284. mysql.keys = valueInsert.keys
  285. mysql.values = valueInsert.values
  286. escapeData = valueInsert.escapeData
  287. row = 'insert_buyer_premium'
  288. }
  289. const strQuery = await mysqclass.mysqli(mysql, row)
  290. const data = await global.mysql.query(strQuery, escapeData)
  291. return data
  292. }
  293. /**
  294. * Delete Buyer Premium
  295. * @param {number} id ID in buyer_premium table
  296. * @returns {object} sql response
  297. */
  298. static async deleteBuyerPremium(id) {
  299. const mysql = {}
  300. const escapeData = [id]
  301. const strQuery = await mysqclass.mysqli(mysql, 'delete_buyer_premiumt')
  302. const dataReturn = await global.mysql.query(strQuery, escapeData)
  303. return dataReturn
  304. }
  305. /**
  306. * Delete Buyer Premium
  307. * @param {object} req request data
  308. * @param {Object} data data to de inseted
  309. * @returns {object} sql response
  310. */
  311. static async insertDataTable(req, data) {
  312. const mysqli = {}
  313. let escapeData = []
  314. const tableUsed = req.body.tableName
  315. const postData = data.columns
  316. const acceptedObjects = global.configColumns[tableUsed].array_columns
  317. const defaultKeys = []
  318. const defaultValues = []
  319. /* if(global.configColumns[tableUsed].default_values.length > 0) {
  320. defaultValues = global.configColumns[tableUsed].default_values
  321. defaultKeys = global.configColumns[tableUsed].default_columns
  322. } */
  323. const valueInsert = commonSQL.InsertSQLFunction(
  324. postData,
  325. acceptedObjects,
  326. defaultKeys,
  327. defaultValues,
  328. )
  329. mysqli.keys = valueInsert.keys
  330. escapeData = valueInsert.escapeData
  331. mysqli.values = valueInsert.values
  332. mysqli.tables = tableUsed
  333. const strQuery = await mysqclass.mysqli(mysqli, 'insert_tables')
  334. const dataPromise = await global.mysql.query(strQuery, escapeData)
  335. return dataPromise
  336. }
  337. /**
  338. * update data table
  339. * @param {object} req
  340. * @param {number} id data to be updated
  341. * @returns {object} sql response
  342. */
  343. static async updateDataTable(req, data) {
  344. const mysqli = {}
  345. let escapeData = []
  346. const tableUsed = req.body.tableName
  347. const postData = data.columns
  348. const acceptedObjects = global.configColumns[tableUsed].array_columns
  349. const defaultKeys = []
  350. const defaultValues = []
  351. const valueInsert = commonSQL.updateSQLFunction(
  352. postData,
  353. acceptedObjects,
  354. defaultKeys,
  355. defaultValues,
  356. )
  357. mysqli.keys = valueInsert.keys
  358. escapeData = valueInsert.escapeData
  359. let whereCond = _.map(req.body.where, (key, val) => {
  360. return ` \`${val}\` = '${key}' `
  361. })
  362. whereCond = whereCond.join(' AND ')
  363. // mysqli.values = ` id=${req.body.where.id}`
  364. mysqli.values = whereCond
  365. mysqli.tables = tableUsed
  366. console.log(valueInsert)
  367. const strQuery = await mysqclass.mysqli(mysqli, 'update_tables')
  368. console.log(strQuery)
  369. const dataPromise = await global.mysql.query(strQuery, escapeData)
  370. return dataPromise
  371. }
  372. }
  373. module.exports.default = adminSettingModule