/var/www/greso.tech/server/nsm/services
Edit: /var/www/greso.tech/server/nsm/services/lead.service.js (1518B)
const logger = require('../logger')({ service: 'OrderService' })
const { Op } = require('sequelize')
const { isSet, isArray } = require('../utils/validator.util')
module.exports = class LeadService {
constructor({ db, config }) {
this.db = db
this.ld = VARS.ld
this.next = 0
this.config = config
logger.child({ service: 'LeadService', method: 'Constructor' }).info('Success')
}
async Run() {
// load ld
this.ld = await this.db.leadDistribution.findAll()
var ldCount = this.ld.length;
logger.child({ service: 'LeadService', method: 'Run' }).info('Success. Sales representative: ' + ldCount)
console.log('LeadService Run Success. Sales representative: ' + ldCount)
}
async Reload() {
this.ld = await this.db.leadDistribution.findAll()
var ldCount = this.ld.length;
if (this.next > ldCount - 1) {
this.next = 0
}
logger.child({ service: 'LeadService', method: 'Reload' }).info('Success')
console.log('LeadService Reload Success. Sales representative: ' + ldCount)
}
async Stop() {
logger.child({ service: 'LeadService', method: 'Stop' }).info('Success')
}
////////////////////////////////////////////////////////////////////////////////////////
async GetNextLD(companyId) {
// list ld by company
var list = []
var res
for (let val of this.ld) {
if (val.companyId != companyId) continue
list.push(val)
}
if (list.length > 0) {
res = list[this.next]
this.next++
if (this.next == list.length) {
this.next = 0
}
}
return res
}
}