Initial commit
This commit is contained in:
85
.env
Executable file
85
.env
Executable file
@ -0,0 +1,85 @@
|
||||
# APP CONFIG
|
||||
PORT=6014
|
||||
PORT_EXPRESS=3400
|
||||
PORT_UDP=20203
|
||||
# NODE_ENV=development
|
||||
NODE_ENV=production
|
||||
API_VERSION=1
|
||||
PATH_URL=/tracking
|
||||
TZ=Asia/Jakarta
|
||||
|
||||
# DATABASE CONFIG
|
||||
# CONNECTIONLIMIT=10
|
||||
# # DBHOST=149.129.214.64
|
||||
# DBHOST=8.215.31.239
|
||||
# DBUSER=root
|
||||
# DBPASSWORD=vYR/+QHD4lJ8y/v2
|
||||
# DATABASE=db_trucking
|
||||
# ACQRTIMEOUT=10000
|
||||
|
||||
# DATABASE CONFIG BONCENG(mariadb)
|
||||
# CONNECTIONLIMIT=10
|
||||
# DBHOST=147.139.133.230
|
||||
# DBUSER=boncengdball
|
||||
# DBPASSWORD=rtzL8NI4TchNNwu7
|
||||
# DATABASE=db_trucking
|
||||
# ACQRTIMEOUT=10000
|
||||
|
||||
# DATABASE CONFIG BONCENG(mariadb 10.7)
|
||||
CONNECTIONLIMIT=10
|
||||
DBHOST=127.0.0.1
|
||||
DBUSER=root
|
||||
DBPASSWORD=root
|
||||
DATABASE=db_fleet
|
||||
ACQRTIMEOUT=10000
|
||||
|
||||
# REDIS CONFIG
|
||||
# if using local system
|
||||
# REDIS_HOST=localhost
|
||||
# if using docker
|
||||
REDIS_HOST=redis
|
||||
REDIS_PORT=6379
|
||||
REDIS_SCHEDULER_REVERSE_GEO=scheduleReverseGeocode
|
||||
REDIS_QUEUE_BLAST_ORDER=queueBlastOrder
|
||||
REDIS_SCHEDULER_DRV_UP_LOC=scheduleDrvUpLoc
|
||||
REDIS_SCHEDULER_DRV_UP_PHOTO=scheduleDrvUpPhoto
|
||||
REDIS_SCHEDULER_DRV_UP_LOC_IDLE=scheduleDrvUpLocIdle
|
||||
REDIS_SCHEDULER_DRV_BLAST_NOTIF=schedulerDrvBlastNotif
|
||||
REDIS_SCHEDULER_GPS_TRACKER_WAKEUP=schedulerGpsTrackerWakeUp
|
||||
|
||||
# SMTP MAILTRAP RAFIF
|
||||
SMTP_HOST=smtp.mailtrap.io
|
||||
SMTP_PORT=2525
|
||||
SMTP_USER=e9aace0ebb3398
|
||||
SMTP_PASW=c8f9ccee5122d6
|
||||
SMTP_FROM=rafifrest@gmail.com
|
||||
|
||||
# SMTP BONCENG NO REPLY
|
||||
# SMTP_HOST=bagaspati.iixcp.rumahweb.com
|
||||
# SMTP_PORT=465
|
||||
# SMTP_USER=non-reply@bonceng-indonesia.com
|
||||
# SMTP_PASW=eGgKSpJAuv1p
|
||||
# SMTP_FROM=non-reply@bonceng-indonesia.com
|
||||
|
||||
# SCHEDULER BULLMQ CONFIG (CUSTOM)
|
||||
# sekali jalan maximal looping
|
||||
SCHEDULE_REVERSE_GEO_MAX_LOOP=10
|
||||
SCHEDULE_REVERSE_GEO_TIME=*/2 * * * *
|
||||
SCHEDULE_DRV_UP_LOC_MAX_LOOP=1
|
||||
SCHEDULE_DRV_UP_LOC_TIME=*/1 * * * *
|
||||
SCHEDULE_DRV_UP_PHOTO_MAX_LOOP=1
|
||||
SCHEDULE_DRV_UP_PHOTO_TIME=0 */1 * * *
|
||||
SCHEDULE_DRV_UP_LOC_IDLE_MAX_LOOP=1
|
||||
SCHEDULE_DRV_UP_LOC_IDLE_TIME=0 */5 * * *
|
||||
SCHEDULE_DRV_BLAST_NOTIF_MAX_LOOP=1
|
||||
SCHEDULE_DRV_BLAST_NOTIF_TIME=0 */6 * * *
|
||||
SCHEDULE_GPS_TRACKER_WAKEUP_MAX_LOOP=1
|
||||
SCHEDULE_GPS_TRACKER_WAKEUP_TIME=*/1 * * * *
|
||||
|
||||
CS_MAIL=customer-service@bonceng-indonesia.com
|
||||
CS_PHONE=082123622686
|
||||
CS_ADDR='Jalan RC Veteran 11A, Rempoa, Bintaro, Pesanggrahan, Kota Jakarta Selatan 12330'
|
||||
MAIL_ASSET=http://149.129.214.64/fms_dev/mails/v0/assets/
|
||||
|
||||
FMS_URL=http://149.129.214.64/fms_dev/
|
||||
API_DANA_BINGCORP=http://api.simerahputih.com/dana_bingcorp/
|
||||
92
.env.dev
Executable file
92
.env.dev
Executable file
@ -0,0 +1,92 @@
|
||||
# APP CONFIG
|
||||
PORT=6014
|
||||
PORT_EXPRESS=3200
|
||||
PORT_UDP=20203
|
||||
NODE_ENV=development
|
||||
# NODE_ENV=production
|
||||
API_VERSION=1
|
||||
PATH_URL=/tracking_dev
|
||||
TZ=Asia/Jakarta
|
||||
|
||||
# DATABASE CONFIG
|
||||
# GAJADI DIPAKE, St_Distance_Sphere gaada diversion maria db server dev
|
||||
# CONNECTIONLIMIT=10
|
||||
# DBHOST=117.53.46.186
|
||||
# DBUSER=development
|
||||
# DBPASSWORD=MAN[7Dpzn[
|
||||
# DATABASE=db_trucking
|
||||
# ACQRTIMEOUT=10000
|
||||
# CONNECTIONLIMIT=10
|
||||
# # DBHOST=149.129.214.64
|
||||
# DBHOST=8.215.31.239
|
||||
# DBUSER=root
|
||||
# DBPASSWORD=vYR/+QHD4lJ8y/v2
|
||||
# DATABASE=db_trucking_dev
|
||||
# ACQRTIMEOUT=10000
|
||||
|
||||
# DATABASE CONFIG BONCENG(mariadb)
|
||||
# CONNECTIONLIMIT=10
|
||||
# DBHOST=147.139.133.230
|
||||
# DBUSER=boncengdball
|
||||
# DBPASSWORD=rtzL8NI4TchNNwu7
|
||||
# DATABASE=db_trucking_dev
|
||||
# ACQRTIMEOUT=10000
|
||||
|
||||
# DATABASE CONFIG BONCENG(mariadb 10.7)
|
||||
CONNECTIONLIMIT=10
|
||||
DBHOST=149.129.244.66
|
||||
DBUSER=all
|
||||
DBPASSWORD=UC90vjAQG0w=
|
||||
DATABASE=db_trucking_dev
|
||||
ACQRTIMEOUT=10000
|
||||
|
||||
# REDIS CONFIG
|
||||
# if using local system
|
||||
REDIS_HOST=localhost
|
||||
# if using docker
|
||||
# REDIS_HOST=redis
|
||||
REDIS_PORT=6379
|
||||
REDIS_SCHEDULER_REVERSE_GEO=scheduleReverseGeocode_dev
|
||||
REDIS_QUEUE_BLAST_ORDER=queueBlastOrder_dev
|
||||
REDIS_SCHEDULER_DRV_UP_LOC=scheduleDrvUpLoc_dev
|
||||
REDIS_SCHEDULER_DRV_UP_PHOTO=scheduleDrvUpPhoto_dev
|
||||
REDIS_SCHEDULER_DRV_UP_LOC_IDLE=scheduleDrvUpLocIdle_dev
|
||||
REDIS_SCHEDULER_DRV_BLAST_NOTIF=schedulerDrvBlastNotif_dev
|
||||
REDIS_SCHEDULER_GPS_TRACKER_WAKEUP=schedulerGpsTrackerWakeUp_dev
|
||||
|
||||
# SMTP BONCENG NO REPLY
|
||||
# SMTP_HOST=bagaspati.iixcp.rumahweb.com
|
||||
# SMTP_PORT=465
|
||||
# SMTP_USER=non-reply@bonceng-indonesia.com
|
||||
# SMTP_PASW=eGgKSpJAuv1p
|
||||
# SMTP_FROM=non-reply@bonceng-indonesia.com
|
||||
|
||||
# SMTP MAILTRAP RAFIF
|
||||
SMTP_HOST=smtp.mailtrap.io
|
||||
SMTP_PORT=2525
|
||||
SMTP_USER=e9aace0ebb3398
|
||||
SMTP_PASW=c8f9ccee5122d6
|
||||
SMTP_FROM=rafifrest@gmail.com
|
||||
|
||||
# SCHEDULER BULLMQ CONFIG (CUSTOM)
|
||||
# sekali jalan maximal looping
|
||||
SCHEDULE_REVERSE_GEO_MAX_LOOP=10
|
||||
SCHEDULE_REVERSE_GEO_TIME=*/2 * * * *
|
||||
SCHEDULE_DRV_UP_LOC_MAX_LOOP=1
|
||||
SCHEDULE_DRV_UP_LOC_TIME=*/1 * * * *
|
||||
SCHEDULE_DRV_UP_PHOTO_MAX_LOOP=1
|
||||
SCHEDULE_DRV_UP_PHOTO_TIME=0 */1 * * *
|
||||
SCHEDULE_DRV_UP_LOC_IDLE_MAX_LOOP=1
|
||||
SCHEDULE_DRV_UP_LOC_IDLE_TIME=0 */5 * * *
|
||||
SCHEDULE_DRV_BLAST_NOTIF_MAX_LOOP=1
|
||||
SCHEDULE_DRV_BLAST_NOTIF_TIME=0 */1 * * *
|
||||
SCHEDULE_GPS_TRACKER_WAKEUP_MAX_LOOP=1
|
||||
SCHEDULE_GPS_TRACKER_WAKEUP_TIME=*/1 * * * *
|
||||
|
||||
CS_MAIL=customer-service@bonceng-indonesia.com
|
||||
CS_PHONE=082123622686
|
||||
CS_ADDR='Jalan RC Veteran 11A, Rempoa, Bintaro, Pesanggrahan, Kota Jakarta Selatan 12330'
|
||||
MAIL_ASSET=http://149.129.214.64/fms_dev/mails/v0/assets/
|
||||
|
||||
FMS_URL=http://149.129.214.64/fms_dev/
|
||||
API_DANA_BINGCORP=http://api.simerahputih.com/dana_bingcorp/
|
||||
22
.env.example
Normal file
22
.env.example
Normal file
@ -0,0 +1,22 @@
|
||||
# APP CONFIG
|
||||
PORT=6014
|
||||
PORT_EXPRESS=3400
|
||||
NODE_ENV=development
|
||||
# NODE_ENV=production
|
||||
API_VERSION=1
|
||||
TZ=Asia/Jakarta
|
||||
|
||||
# DATABASE CONFIG
|
||||
CONNECTIONLIMIT=10
|
||||
DBHOST=localhost
|
||||
DBUSER=local
|
||||
DBPASSWORD=
|
||||
DATABASE=db_trucking
|
||||
ACQRTIMEOUT=10000
|
||||
|
||||
# REDIS CONFIG
|
||||
# if using local system
|
||||
# REDIS_HOST=localhost
|
||||
# if using docker
|
||||
REDIS_HOST=redis
|
||||
REDIS_PORT=6379
|
||||
75
.env.local
Executable file
75
.env.local
Executable file
@ -0,0 +1,75 @@
|
||||
# APP CONFIG
|
||||
PORT=6014
|
||||
PORT_EXPRESS=3400
|
||||
PORT_UDP=20203
|
||||
NODE_ENV=development
|
||||
# NODE_ENV=production
|
||||
API_VERSION=1
|
||||
PATH_URL=/trucking
|
||||
TZ=Asia/Jakarta
|
||||
|
||||
# DATABASE CONFIG LOCAL
|
||||
# CONNECTIONLIMIT=10
|
||||
# # DBHOST=192.168.68.148
|
||||
# DBHOST=192.168.43.109
|
||||
# DBUSER=root
|
||||
# DBPASSWORD=root
|
||||
# DATABASE=db_trucking
|
||||
# ACQRTIMEOUT=10000
|
||||
# # DATABASE CONFIG DEV
|
||||
# # CONNECTIONLIMIT=10
|
||||
# # DBHOST=149.129.214.64
|
||||
# # DBUSER=root
|
||||
# # DBPASSWORD=vYR/+QHD4lJ8y/v2
|
||||
# # DATABASE=db_trucking_dev
|
||||
# # ACQRTIMEOUT=10000
|
||||
|
||||
# DATABASE CONFIG BONCENG(mariadb)
|
||||
CONNECTIONLIMIT=10
|
||||
DBHOST=147.139.133.230
|
||||
DBUSER=boncengdball
|
||||
DBPASSWORD=rtzL8NI4TchNNwu7
|
||||
DATABASE=db_trucking_dev
|
||||
ACQRTIMEOUT=10000
|
||||
|
||||
# REDIS CONFIG
|
||||
# if using local system
|
||||
# REDIS_HOST=localhost
|
||||
# if using docker
|
||||
REDIS_HOST=redis
|
||||
REDIS_PORT=6379
|
||||
REDIS_SCHEDULER_REVERSE_GEO=scheduleReverseGeocode
|
||||
REDIS_QUEUE_BLAST_ORDER=queueBlastOrder
|
||||
REDIS_SCHEDULER_DRV_UP_LOC=scheduleDrvUpLoc
|
||||
REDIS_SCHEDULER_DRV_UP_PHOTO=scheduleDrvUpPhoto
|
||||
REDIS_SCHEDULER_DRV_UP_LOC_IDLE=scheduleDrvUpLocIdle
|
||||
REDIS_SCHEDULER_GPS_TRACKER_WAKEUP=schedulerGpsTrackerWakeUp
|
||||
|
||||
# SMTP MAILTRAP RAFIF
|
||||
SMTP_HOST=smtp.mailtrap.io
|
||||
SMTP_PORT=2525
|
||||
SMTP_USER=e9aace0ebb3398
|
||||
SMTP_PASW=c8f9ccee5122d6
|
||||
SMTP_FROM=rafifrest@gmail.com
|
||||
|
||||
# SCHEDULER BULLMQ CONFIG (CUSTOM)
|
||||
# sekali jalan maximal looping
|
||||
SCHEDULE_REVERSE_GEO_MAX_LOOP=10
|
||||
SCHEDULE_REVERSE_GEO_TIME=*/2 * * * *
|
||||
SCHEDULE_DRV_UP_LOC_MAX_LOOP=1
|
||||
SCHEDULE_DRV_UP_LOC_TIME=*/5 * * * *
|
||||
SCHEDULE_DRV_UP_PHOTO_MAX_LOOP=1
|
||||
SCHEDULE_DRV_UP_PHOTO_TIME=0 */1 * * *
|
||||
SCHEDULE_DRV_UP_LOC_IDLE_MAX_LOOP=1
|
||||
SCHEDULE_DRV_UP_LOC_IDLE_TIME=0 */1 * * *
|
||||
SCHEDULE_GPS_TRACKER_WAKEUP_MAX_LOOP=1
|
||||
SCHEDULE_GPS_TRACKER_WAKEUP_TIME=*/1 * * * *
|
||||
|
||||
CS_MAIL=customer-service@bonceng-indonesia.com
|
||||
CS_PHONE=082123622686
|
||||
CS_ADDR='Jalan RC Veteran 11A, Rempoa, Bintaro, Pesanggrahan, Kota Jakarta Selatan 12330'
|
||||
MAIL_ASSET=http://117.53.46.186/trucking-app/mails/v0/assets/
|
||||
|
||||
# FMS_URL=http://149.129.214.64/fms_dev/
|
||||
FMS_URL=http://192.168.68.105:5000/trucking/
|
||||
API_DANA_BINGCORP=http://api.simerahputih.com/dana_bingcorp/
|
||||
78
.env.prod
Executable file
78
.env.prod
Executable file
@ -0,0 +1,78 @@
|
||||
# APP CONFIG
|
||||
PORT=6014
|
||||
PORT_EXPRESS=3400
|
||||
PORT_UDP=20203
|
||||
# NODE_ENV=development
|
||||
NODE_ENV=production
|
||||
API_VERSION=1
|
||||
PATH_URL=/tracking
|
||||
TZ=Asia/Jakarta
|
||||
|
||||
# DATABASE CONFIG
|
||||
# CONNECTIONLIMIT=10
|
||||
# # DBHOST=149.129.214.64
|
||||
# DBHOST=8.215.31.239
|
||||
# DBUSER=root
|
||||
# DBPASSWORD=vYR/+QHD4lJ8y/v2
|
||||
# DATABASE=db_trucking
|
||||
# ACQRTIMEOUT=10000
|
||||
|
||||
# DATABASE CONFIG BONCENG(mariadb)
|
||||
# CONNECTIONLIMIT=10
|
||||
# DBHOST=147.139.133.230
|
||||
# DBUSER=boncengdball
|
||||
# DBPASSWORD=rtzL8NI4TchNNwu7
|
||||
# DATABASE=db_trucking
|
||||
# ACQRTIMEOUT=10000
|
||||
|
||||
# DATABASE CONFIG BONCENG(mariadb 10.7)
|
||||
CONNECTIONLIMIT=10
|
||||
DBHOST=149.129.244.66
|
||||
DBUSER=all
|
||||
DBPASSWORD=UC90vjAQG0w=
|
||||
DATABASE=db_trucking
|
||||
ACQRTIMEOUT=10000
|
||||
|
||||
# REDIS CONFIG
|
||||
# if using local system
|
||||
REDIS_HOST=localhost
|
||||
# if using docker
|
||||
# REDIS_HOST=redis
|
||||
REDIS_PORT=6379
|
||||
REDIS_SCHEDULER_REVERSE_GEO=scheduleReverseGeocode
|
||||
REDIS_QUEUE_BLAST_ORDER=queueBlastOrder
|
||||
REDIS_SCHEDULER_DRV_UP_LOC=scheduleDrvUpLoc
|
||||
REDIS_SCHEDULER_DRV_UP_PHOTO=scheduleDrvUpPhoto
|
||||
REDIS_SCHEDULER_DRV_UP_LOC_IDLE=scheduleDrvUpLocIdle
|
||||
REDIS_SCHEDULER_DRV_BLAST_NOTIF=schedulerDrvBlastNotif
|
||||
REDIS_SCHEDULER_GPS_TRACKER_WAKEUP=schedulerGpsTrackerWakeUp
|
||||
|
||||
# SMTP BONCENG NO REPLY
|
||||
SMTP_HOST=bagaspati.iixcp.rumahweb.com
|
||||
SMTP_PORT=465
|
||||
SMTP_USER=non-reply@bonceng-indonesia.com
|
||||
SMTP_PASW=eGgKSpJAuv1p
|
||||
SMTP_FROM=non-reply@bonceng-indonesia.com
|
||||
|
||||
# SCHEDULER BULLMQ CONFIG (CUSTOM)
|
||||
# sekali jalan maximal looping
|
||||
SCHEDULE_REVERSE_GEO_MAX_LOOP=20
|
||||
SCHEDULE_REVERSE_GEO_TIME=*/2 * * * *
|
||||
SCHEDULE_DRV_UP_LOC_MAX_LOOP=1
|
||||
SCHEDULE_DRV_UP_LOC_TIME=*/1 * * * *
|
||||
SCHEDULE_DRV_UP_PHOTO_MAX_LOOP=1
|
||||
SCHEDULE_DRV_UP_PHOTO_TIME=0 */1 * * *
|
||||
SCHEDULE_DRV_UP_LOC_IDLE_MAX_LOOP=1
|
||||
SCHEDULE_DRV_UP_LOC_IDLE_TIME=0 */5 * * *
|
||||
SCHEDULE_DRV_BLAST_NOTIF_MAX_LOOP=1
|
||||
SCHEDULE_DRV_BLAST_NOTIF_TIME=0 */6 * * *
|
||||
SCHEDULE_GPS_TRACKER_WAKEUP_MAX_LOOP=1
|
||||
SCHEDULE_GPS_TRACKER_WAKEUP_TIME=*/1 * * * *
|
||||
|
||||
CS_MAIL=customer-service@bonceng-indonesia.com
|
||||
CS_PHONE=082123622686
|
||||
CS_ADDR='Jalan RC Veteran 11A, Rempoa, Bintaro, Pesanggrahan, Kota Jakarta Selatan 12330'
|
||||
MAIL_ASSET=https://bingkis-corporate.com/fms/mails/v0/assets/
|
||||
|
||||
FMS_URL=https://bingkis-corporate.com/fms/
|
||||
API_DANA_BINGCORP=http://api.simerahputih.com/dana_bingcorp/
|
||||
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
node_modules/
|
||||
logs/
|
||||
# .env
|
||||
# .env.*
|
||||
.vscode
|
||||
.DS_Store
|
||||
files/storage
|
||||
9
Dockerfile
Normal file
9
Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM node:12-alpine as base
|
||||
|
||||
WORKDIR /var/www/html/services/trucking
|
||||
|
||||
COPY ./ /var/www/html/services/trucking
|
||||
|
||||
RUN npm install -g nodemon
|
||||
|
||||
RUN npm install && mv /var/www/html/services/trucking/node_modules /node_modules
|
||||
BIN
Message Notifikasi Apps Driver Tracker.xlsx
Normal file
BIN
Message Notifikasi Apps Driver Tracker.xlsx
Normal file
Binary file not shown.
567
app.js
Normal file
567
app.js
Normal file
@ -0,0 +1,567 @@
|
||||
require('dotenv').config({ path: '.env' });
|
||||
require('events').EventEmitter.prototype._maxListeners = 30;
|
||||
// start for gps-tracking
|
||||
const net = require('net');
|
||||
const dgram = require('dgram');
|
||||
const crc = require('crc');
|
||||
const moment = require('moment');
|
||||
const LibDevice = require('./library/LibDevice');
|
||||
const GpsTracksModels = require('./models/GpsTracksModels');
|
||||
const ZoneModels = require('./models/ZoneModels');
|
||||
const VhcModels = require('./models/VhcModels');
|
||||
const LibMail = require('./library/LibMail');
|
||||
const LibHelper = require('./library/LibHelper');
|
||||
const nanoid = require('nanoid').nanoid;
|
||||
// end for gps-tracking
|
||||
|
||||
// start for normal http request
|
||||
const express = require('express');
|
||||
const LibBullAdapter = require('./library/LibBullAdapter');
|
||||
const routes = require('./routes/routes');
|
||||
// const routes = require('./routes/routes_without_scheduler');
|
||||
const app = express();
|
||||
// end for normal http request
|
||||
|
||||
// start for logging
|
||||
const LibWinston = require('./library/LibWinston');
|
||||
|
||||
const logName = 'libUdp';
|
||||
const Logger = LibWinston.initialize(logName);
|
||||
// end for logging
|
||||
|
||||
// start commit / log message from gps
|
||||
async function commitMessage(now, logDevice) {
|
||||
try {
|
||||
// don't log
|
||||
if (!logDevice.original_hex) {
|
||||
return false;
|
||||
}
|
||||
// in the future don't log to db if device_id not found in vhc
|
||||
const vhc = await VhcModels.getVhcByDeviceId(logDevice.device_id);
|
||||
const lastTrack = await GpsTracksModels.get2LastLocByDeviceId(logDevice.device_id);
|
||||
|
||||
if (['heartbeat', 'alarm'].includes(logDevice.action)) {
|
||||
// set engine stts moving,idling,stopped
|
||||
if (logDevice.ignition == GpsTracksModels.STTS_IGNITION_HIGH) {
|
||||
if (logDevice.speed) {
|
||||
logDevice.stts_engine = GpsTracksModels.STTS_EN_MOVING;
|
||||
} else {
|
||||
if (lastTrack.length > 0) {
|
||||
const checkLastHeartbeat = await GpsTracksModels.getLastHeartbeatToDeterminIdling(logDevice.device_id, lastTrack[0].crt, now);
|
||||
if (checkLastHeartbeat.length >= 3) {
|
||||
logDevice.stts_engine = GpsTracksModels.STTS_EN_IDLING;
|
||||
} else {
|
||||
logDevice.stts_engine = lastTrack[0].stts_engine;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logDevice.stts_engine = GpsTracksModels.STTS_EN_STOPING;
|
||||
}
|
||||
}
|
||||
// get last ignition, stts_engine, stts_alarm, stts_charge, stts_acc, stts_volt, stts_switch
|
||||
if (['location'].includes(logDevice.action)) {
|
||||
// get last ignition
|
||||
const lastHeartbeatOrAlarm = await GpsTracksModels.get2LastHeartbeatOrAlarm(logDevice.device_id);
|
||||
if (lastHeartbeatOrAlarm.length > 0) {
|
||||
logDevice.ignition = lastHeartbeatOrAlarm[0].ignition;
|
||||
logDevice.stts_gps = lastHeartbeatOrAlarm[0].stts_gps;
|
||||
logDevice.stts_gsm = lastHeartbeatOrAlarm[0].stts_gsm;
|
||||
} else {
|
||||
logDevice.ignition = lastHeartbeatOrAlarm[0].ignition;
|
||||
logDevice.stts_gps = lastHeartbeatOrAlarm[0].stts_gps;
|
||||
logDevice.stts_gsm = lastHeartbeatOrAlarm[0].stts_gsm;
|
||||
}
|
||||
// set engine stts moving,idling,stopped
|
||||
if (logDevice.ignition == GpsTracksModels.STTS_IGNITION_HIGH) {
|
||||
if (logDevice.speed) {
|
||||
logDevice.stts_engine = GpsTracksModels.STTS_EN_MOVING;
|
||||
} else {
|
||||
if (lastTrack.length > 0) {
|
||||
const checkLastHeartbeat = await GpsTracksModels.getLastHeartbeatToDeterminIdling(logDevice.device_id, lastTrack[0].crt, now);
|
||||
if (checkLastHeartbeat.length >= 3) {
|
||||
logDevice.stts_engine = GpsTracksModels.STTS_EN_IDLING;
|
||||
} else {
|
||||
logDevice.stts_engine = lastTrack[0].stts_engine;
|
||||
}
|
||||
}
|
||||
}
|
||||
// get stts_alarm, stts_charge, stts_acc, stts_volt, stts_switch
|
||||
} else {
|
||||
logDevice.stts_engine = GpsTracksModels.STTS_EN_STOPING;
|
||||
}
|
||||
logDevice.stts_oil_electricity = lastHeartbeatOrAlarm[0].stts_oil_electricity;
|
||||
logDevice.stts_alarm = lastHeartbeatOrAlarm[0].stts_alarm;
|
||||
logDevice.stts_charge = lastHeartbeatOrAlarm[0].stts_charge;
|
||||
logDevice.stts_acc = lastHeartbeatOrAlarm[0].stts_acc;
|
||||
logDevice.stts_volt = lastHeartbeatOrAlarm[0].stts_volt;
|
||||
logDevice.stts_switch = lastHeartbeatOrAlarm[0].stts_switch;
|
||||
}
|
||||
|
||||
// sekarang heartbeat diinject data lokasi juga dari lokasi terakhir
|
||||
if (['heartbeat'].includes(logDevice.action)) {
|
||||
if (lastTrack.length > 0) {
|
||||
logDevice.latitude = lastTrack[0].latitude;
|
||||
logDevice.longitude = lastTrack[0].longitude;
|
||||
logDevice.speed = lastTrack[0].speed;
|
||||
logDevice.orientation = lastTrack[0].orientation;
|
||||
if (logDevice.latitude) {
|
||||
logDevice.stts_reverse_geo = GpsTracksModels.STTS_REVERSE_GEO_NOT;
|
||||
}
|
||||
|
||||
logDevice.length_gps = lastTrack[0].length_gps;
|
||||
logDevice.pos_stlt_gps = lastTrack[0].pos_stlt_gps;
|
||||
logDevice.pos_type_gps = lastTrack[0].pos_type_gps;
|
||||
logDevice.is_pos_gps = lastTrack[0].is_pos_gps;
|
||||
|
||||
// jika gapengen dimunculin di last movement
|
||||
// logDevice.crt = lastTrack[0].crt;
|
||||
// logDevice.crt_format = lastTrack[0].crt_format;
|
||||
// logDevice.crt_d = lastTrack[0].crt_d;
|
||||
// logDevice.crt_d_format = lastTrack[0].crt_d_format;
|
||||
// jika pengen di munculin di last movement
|
||||
logDevice.crt = now;
|
||||
logDevice.crt_format = moment.unix(now).format('YYYY-MM-DD HH:mm:ss');
|
||||
logDevice.crt_d = now;
|
||||
logDevice.crt_d_format = moment.unix(now).format('YYYY-MM-DD HH:mm:ss');
|
||||
}
|
||||
}
|
||||
|
||||
// count milleage
|
||||
if (logDevice.latitude != null && logDevice.longitude != null && lastTrack.length > 0) {
|
||||
const distance = LibHelper.haversineGreatCircleDistance(lastTrack[0].latitude, lastTrack[0].longitude, logDevice.latitude, logDevice.longitude, LibHelper.EARTH_RADIUS_KM);
|
||||
const distance_km = LibHelper.kmToKm(distance, 100000000);
|
||||
// console.log(`GPS TRACKER UP LOCATION => device_id:${logDevice.device_id} vhc_id:${(vhc[0]) ? vhc[0].vid : 0}, distance_km:${distance_km}`);
|
||||
// validasi jika lebih dari 3km, ga disimpan
|
||||
if (distance_km >= 3) {
|
||||
GpsTracksModels.bundleCreate2(logDevice, logDevice); // jika tidak disimpan malah jadi bug, jadi akan update lokasi terus dengan kalkulasi jarak sebelumnya jadi makan lama makin lebar, mending disimpen terus milleagenya jadi 0 aja
|
||||
return false;
|
||||
}
|
||||
logDevice.pre_milleage = distance_km;
|
||||
logDevice.sum_milleage = (lastTrack[0].sum_milleage + logDevice.pre_milleage).toFixed(8);
|
||||
if (vhc.length > 0) {
|
||||
logDevice.vhc_id = (vhc[0]) ? vhc[0].vid : 0;
|
||||
if (lastTrack[0].vhc_id == logDevice.vhc_id) {
|
||||
logDevice.vhc_milleage = (lastTrack[0].vhc_milleage + logDevice.pre_milleage).toFixed(8);
|
||||
} else {
|
||||
logDevice.vhc_milleage = ((vhc[0]) ? vhc[0].sum_milleage : 0 + logDevice.pre_milleage).toFixed(8);
|
||||
}
|
||||
VhcModels.update((vhc[0]) ? vhc[0].vid : 0, { sum_milleage: logDevice.vhc_milleage });
|
||||
}
|
||||
}
|
||||
|
||||
// truck zoning spawn
|
||||
if (logDevice.latitude != null && logDevice.longitude != null) { // && vhc.length > 0
|
||||
// log tracking
|
||||
const currTrack = await GpsTracksModels.bundleCreate2(logDevice, logDevice);
|
||||
// console.log('GT06 HAS LOCATION AND CHECK ZONE');
|
||||
const inCircle = await ZoneModels.getInCircle(logDevice.latitude, logDevice.longitude);
|
||||
const inShape = await ZoneModels.getInShape(logDevice.latitude, logDevice.longitude);
|
||||
const insideSpawnZone = [];
|
||||
for (let zone of inCircle) {
|
||||
insideSpawnZone.push(zone);
|
||||
}
|
||||
for (let zone of inShape) {
|
||||
insideSpawnZone.push(zone);
|
||||
}
|
||||
|
||||
/**
|
||||
* get lastSpawn desc index 0, where leave_at = 0
|
||||
* kalo gaada create, dengan isi field enter_at aja, kalo ada didalam zona
|
||||
* kalo ada update, dengan isi field leave_at aja, kalo udah diluar zona
|
||||
*/
|
||||
const lastSpawn = await GpsTracksModels.listSpawnZone({
|
||||
source: GpsTracksModels.SOURCE_GPS_TRACKER,
|
||||
device_id: logDevice.device_id,
|
||||
vhc_id: (vhc[0]) ? vhc[0].vid : 0,
|
||||
leave_at_d: 0,
|
||||
order_by: 'ORDER BY id DESC',
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
if (lastSpawn.length > 0) {
|
||||
let is_leave_zone = 1;
|
||||
for (const insideZone of insideSpawnZone) {
|
||||
if (insideZone.zid === lastSpawn[0].zone_id) is_leave_zone = 0;
|
||||
}
|
||||
if (is_leave_zone === 1 && lastSpawn[0].device_id == logDevice.device_id) {
|
||||
GpsTracksModels.updt2SpawnZone({
|
||||
leave_lat: logDevice.latitude,
|
||||
leave_lng: logDevice.longitude,
|
||||
leave_at_d: logDevice.crt_d || now,
|
||||
leave_at_d_format: moment.unix(logDevice.crt_d || now).format('YYYY-MM-DD HH:mm:ss'),
|
||||
leave_at_s: now,
|
||||
leave_at_s_format: moment.unix(now).format('YYYY-MM-DD HH:mm:ss'),
|
||||
updt: now,
|
||||
updt_format: moment.unix(now).format('YYYY-MM-DD HH:mm:ss'),
|
||||
}, lastSpawn[0].id);
|
||||
}
|
||||
} else {
|
||||
for (let zone of insideSpawnZone) {
|
||||
let mailData = {
|
||||
pic_name: zone.pic_name,
|
||||
pic_mail: zone.pic_mail,
|
||||
z_name: zone.name,
|
||||
z_type_name: zone.type_name,
|
||||
z_workflow_name: zone.workflow_type_name,
|
||||
shiptocode: zone.shiptocode,
|
||||
z_fulladdress: zone.fulladdress,
|
||||
v_nopol: ((vhc[0]) ? vhc[0].nopol1 : 0 || '') + ((vhc[0]) ? vhc[0].nopol2 : 0 || '') + ((vhc[0]) ? vhc[0].nopol3 : 0 || ''),
|
||||
da_name: (vhc[0]) ? vhc[0].da_name : 0 || '',
|
||||
da_phone: '+' + ((vhc[0]) ? vhc[0].da_phone_code : 0 || '') + ((vhc[0]) ? vhc[0].da_phone : 0 || ''),
|
||||
};
|
||||
// LibMail.sendVhcSpawnZoneMail(`${(vhc[0]) ? vhc[0].nopol1 : 0 || ''}${(vhc[0]) ? vhc[0].nopol2 : 0 || ''}${(vhc[0]) ? vhc[0].nopol3 : 0 || ''} entering zone ${mailData.z_name}`, mailData.pic_mail, mailData);
|
||||
|
||||
if (logDevice.device_id === '0865784052395871') console.log(1234567890);
|
||||
GpsTracksModels.create2SpawnZone({
|
||||
device_id: logDevice.device_id,
|
||||
master_id: Number(currTrack.result.insertId),
|
||||
enter_lat: logDevice.latitude,
|
||||
enter_lng: logDevice.longitude,
|
||||
enter_at_d: logDevice.crt_d || now,
|
||||
enter_at_d_format: moment.unix(logDevice.crt_d || now).format('YYYY-MM-DD HH:mm:ss'),
|
||||
enter_at_s: now,
|
||||
enter_at_s_format: moment.unix(now).format('YYYY-MM-DD HH:mm:ss'),
|
||||
zone_id: zone.zid,
|
||||
zone_name: zone.name,
|
||||
vhc_id: (vhc[0]) ? vhc[0].vid : 0,
|
||||
source: GpsTracksModels.SOURCE_GPS_TRACKER,
|
||||
crt: now,
|
||||
crt_format: moment.unix(now).format('YYYY-MM-DD HH:mm:ss'),
|
||||
});
|
||||
if (logDevice.device_id === '0865784052395871') console.log('DISINI');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// log tracking
|
||||
GpsTracksModels.bundleCreate2(logDevice, logDevice);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
// end commit / log message from gps
|
||||
|
||||
// start for gps-tracking TCP ONLY
|
||||
const devices = [];
|
||||
const netConn = require('./config/netConn');
|
||||
/**
|
||||
* uniquely identify a socket with Node.js
|
||||
* https://stackoverflow.com/questions/6805432/how-to-uniquely-identify-a-socket-with-node-js
|
||||
*/
|
||||
net.createServer({
|
||||
allowHalfOpen: true,
|
||||
}, function (c) { // c mean connection
|
||||
|
||||
// save connections
|
||||
c.id = nanoid();
|
||||
|
||||
c.pipe(c);
|
||||
|
||||
c.on('data', async (buffer_req) => {
|
||||
const now = moment().unix();
|
||||
const me = LibDevice.identifyProtocolFromBuffer(buffer_req);
|
||||
// console.log('app ', buffer_req);
|
||||
|
||||
const logDevice = {
|
||||
original_hex: me.ori_string,
|
||||
protocol: (me.protocol_name == 'unknown') ? null : me.protocol_name,
|
||||
action: null,
|
||||
device_id: null,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
speed: null,
|
||||
orientation: 0,
|
||||
ignition: 0,
|
||||
stts_engine: 0,
|
||||
stts_gps: 0,
|
||||
length_gps: 0,
|
||||
pos_stlt_gps: 0,
|
||||
pos_type_gps: 0,
|
||||
is_pos_gps: 0,
|
||||
stts_gsm: 0,
|
||||
stts_oil_electricity: 0,
|
||||
stts_alarm: 0,
|
||||
stts_charge: 0,
|
||||
stts_acc: 0,
|
||||
stts_volt: 0,
|
||||
stts_switch: 0,
|
||||
stts_reverse_geo: 0,
|
||||
pre_milleage: 0,
|
||||
source: GpsTracksModels.SOURCE_GPS_TRACKER,
|
||||
vhc_id: 0,
|
||||
drv_id: 0,
|
||||
crt: now,
|
||||
crt_format: moment.unix(now).format('YYYY-MM-DD HH:mm:ss'),
|
||||
crt_d: 0,
|
||||
crt_d_format: null,
|
||||
crt_s: now,
|
||||
crt_s_format: moment.unix(now).format('YYYY-MM-DD HH:mm:ss'),
|
||||
};
|
||||
|
||||
if (me.protocol_name == 'gt06') {
|
||||
// const act = LibDevice.gt06Action(me, device.device_id || null);
|
||||
let dvc_id = devices[c.id];
|
||||
const act = LibDevice.gt06Action(me, dvc_id || null);
|
||||
|
||||
if (act.action_type == 'login') {
|
||||
logDevice.action = act.action_type;
|
||||
logDevice.device_id = act.device_id;
|
||||
|
||||
devices[c.id] = act.device_id;
|
||||
netConn[act.device_id] = c;
|
||||
if (typeof act.buffer_resp != 'undefined') {
|
||||
c.write(act.buffer_resp);
|
||||
}
|
||||
}
|
||||
else if (act.action_type == 'location') {
|
||||
logDevice.action = act.action_type;
|
||||
logDevice.device_id = act.device_id;
|
||||
|
||||
logDevice.latitude = act.gps_data.latitude || null;
|
||||
logDevice.longitude = act.gps_data.longitude || null;
|
||||
logDevice.speed = act.gps_data.speed;
|
||||
logDevice.orientation = act.gps_data.orientation;
|
||||
if (logDevice.latitude) {
|
||||
logDevice.stts_reverse_geo = GpsTracksModels.STTS_REVERSE_GEO_NOT;
|
||||
}
|
||||
|
||||
logDevice.length_gps = act.gps_data.quantity_pos_satellites_c;
|
||||
logDevice.pos_stlt_gps = act.gps_data.quantity_pos_satellites_b;
|
||||
logDevice.pos_type_gps = (Number(act.gps_data.realtime_dif_gps) === 0) ? GpsTracksModels.STTS_POS_TYPE_GPS_RLTM : GpsTracksModels.STTS_POS_TYPE_GPS_DIFF;
|
||||
logDevice.is_pos_gps = (Number(act.gps_data.positioning_gps)) ? GpsTracksModels.STTS_IS_POS_GPS_HAS : GpsTracksModels.STTS_IS_POS_GPS_NOT;
|
||||
|
||||
logDevice.crt = moment(act.gps_data.date).unix();
|
||||
logDevice.crt_format = moment(act.gps_data.date).format('YYYY-MM-DD HH:mm:ss');
|
||||
logDevice.crt_d = moment(act.gps_data.date).unix();
|
||||
logDevice.crt_d_format = moment(act.gps_data.date).format('YYYY-MM-DD HH:mm:ss');
|
||||
}
|
||||
else if (act.action_type == 'heartbeat') {
|
||||
logDevice.action = act.action_type;
|
||||
logDevice.device_id = act.device_id;
|
||||
|
||||
logDevice.ignition = Number(act.stts_data.terminal_info.acc) ? GpsTracksModels.STTS_IGNITION_HIGH : GpsTracksModels.STTS_IGNITION_LOW;
|
||||
logDevice.stts_gps = (act.stts_data.terminal_info.gps_tracking) ? GpsTracksModels.STTS_GPS_ON : GpsTracksModels.STTS_GPS_OFF; // 1=>on, 2=>off
|
||||
logDevice.stts_gsm = Number(act.stts_data.gsm_signal_strength) + 1; // 1=>no signal, n>1=>get signal
|
||||
|
||||
logDevice.stts_oil_electricity = (Number(act.stts_data.terminal_info.oil_electricity) === 0) ? GpsTracksModels.STTS_OIL_ELECTRIC_ON : GpsTracksModels.STTS_OIL_ELECTRIC_OFF; // 1=>on, 2=>off
|
||||
|
||||
let stts_alarm = Number(act.stts_data.terminal_info.stts);
|
||||
if (stts_alarm == 0) {
|
||||
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_NORMAL;
|
||||
} else if (stts_alarm == 1) {
|
||||
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_SHOCK;
|
||||
} else if (stts_alarm == 2) {
|
||||
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_POWER_CUT;
|
||||
} else if (stts_alarm == 3) {
|
||||
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_LOW_BATTERY;
|
||||
} else if (stts_alarm == 4) {
|
||||
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_SOS;
|
||||
}
|
||||
|
||||
logDevice.stts_charge = Number(act.stts_data.terminal_info.charge) ? GpsTracksModels.STTS_CHARGE_ON : GpsTracksModels.STTS_CHARGE_OFF;
|
||||
logDevice.stts_acc = Number(act.stts_data.terminal_info.acc) ? GpsTracksModels.STTS_ACC_HIGH : GpsTracksModels.STTS_ACC_LOW;
|
||||
logDevice.stts_switch = Number(act.stts_data.terminal_info.is_active) ? GpsTracksModels.STTS_SWITCH_ON : GpsTracksModels.STTS_SWITCH_OFF;
|
||||
logDevice.stts_volt = Number(act.stts_data.voltage_level) + 1;
|
||||
|
||||
if (typeof act.buffer_resp != 'undefined') {
|
||||
c.write(act.buffer_resp);
|
||||
}
|
||||
}
|
||||
else if (act.action_type == 'alarm') {
|
||||
logDevice.action = act.action_type;
|
||||
logDevice.device_id = act.device_id;
|
||||
|
||||
logDevice.latitude = act.gps_data.latitude || null;
|
||||
logDevice.longitude = act.gps_data.longitude || null;
|
||||
logDevice.speed = act.gps_data.speed;
|
||||
logDevice.orientation = act.gps_data.orientation;
|
||||
if (logDevice.latitude) {
|
||||
logDevice.stts_reverse_geo = GpsTracksModels.STTS_REVERSE_GEO_NOT;
|
||||
}
|
||||
|
||||
logDevice.length_gps = act.gps_data.quantity_pos_satellites_c;
|
||||
logDevice.pos_stlt_gps = act.gps_data.quantity_pos_satellites_b;
|
||||
logDevice.pos_type_gps = (Number(act.gps_data.realtime_dif_gps) === 0) ? GpsTracksModels.STTS_POS_TYPE_GPS_RLTM : GpsTracksModels.STTS_POS_TYPE_GPS_DIFF;
|
||||
logDevice.is_pos_gps = (Number(act.gps_data.positioning_gps)) ? GpsTracksModels.STTS_IS_POS_GPS_HAS : GpsTracksModels.STTS_IS_POS_GPS_NOT;
|
||||
|
||||
logDevice.ignition = Number(act.stts_data.terminal_info.acc) ? GpsTracksModels.STTS_IGNITION_HIGH : GpsTracksModels.STTS_IGNITION_LOW;
|
||||
logDevice.stts_gps = (act.stts_data.terminal_info.gps_tracking) ? GpsTracksModels.STTS_GPS_ON : GpsTracksModels.STTS_GPS_OFF; // 1=>on, 2=>off
|
||||
logDevice.stts_gsm = Number(act.stts_data.gsm_signal_strength) + 1; // 1=>no signal, n>1=>get signal
|
||||
|
||||
logDevice.stts_oil_electricity = (Number(act.stts_data.terminal_info.oil_electricity) === 0) ? GpsTracksModels.STTS_OIL_ELECTRIC_ON : GpsTracksModels.STTS_OIL_ELECTRIC_OFF; // 1=>on, 2=>off
|
||||
|
||||
let stts_alarm = Number(act.stts_data.terminal_info.stts);
|
||||
if (stts_alarm == 0) {
|
||||
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_NORMAL;
|
||||
} else if (stts_alarm == 1) {
|
||||
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_SHOCK;
|
||||
} else if (stts_alarm == 2) {
|
||||
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_POWER_CUT;
|
||||
} else if (stts_alarm == 3) {
|
||||
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_LOW_BATTERY;
|
||||
} else if (stts_alarm == 4) {
|
||||
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_SOS;
|
||||
}
|
||||
|
||||
logDevice.stts_charge = Number(act.stts_data.terminal_info.charge) ? GpsTracksModels.STTS_CHARGE_ON : GpsTracksModels.STTS_CHARGE_OFF;
|
||||
logDevice.stts_acc = Number(act.stts_data.terminal_info.acc) ? GpsTracksModels.STTS_ACC_HIGH : GpsTracksModels.STTS_ACC_LOW;
|
||||
logDevice.stts_switch = Number(act.stts_data.terminal_info.is_active) ? GpsTracksModels.STTS_SWITCH_ON : GpsTracksModels.STTS_SWITCH_OFF;
|
||||
logDevice.stts_volt = Number(act.stts_data.voltage_level) + 1;
|
||||
|
||||
logDevice.crt = moment(act.gps_data.date).unix();
|
||||
logDevice.crt_format = moment(act.gps_data.date).format('YYYY-MM-DD HH:mm:ss');
|
||||
logDevice.crt_d = moment(act.gps_data.date).unix();
|
||||
logDevice.crt_d_format = moment(act.gps_data.date).format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
if (typeof act.buffer_resp != 'undefined') {
|
||||
c.write(act.buffer_resp);
|
||||
}
|
||||
}
|
||||
// act.action_type == 'other'
|
||||
else {
|
||||
logDevice.action = act.action_type;
|
||||
logDevice.device_id = act.device_id;
|
||||
}
|
||||
}
|
||||
|
||||
commitMessage(now, logDevice);
|
||||
});
|
||||
c.on('end', () => {
|
||||
});
|
||||
c.on('close', () => {
|
||||
});
|
||||
|
||||
// unused
|
||||
c.on('drain', (a) => {
|
||||
console.log('client drain', a);
|
||||
});
|
||||
c.on('error', (a) => {
|
||||
console.error('client error', a);
|
||||
});
|
||||
c.on('lookup', (a) => {
|
||||
console.log('client lookup', a);
|
||||
});
|
||||
c.on('ready', (a) => {
|
||||
console.log('client ready', a);
|
||||
});
|
||||
c.on('timeout', (a) => {
|
||||
console.log('client timeout', a);
|
||||
});
|
||||
|
||||
// not work for gps tracker
|
||||
// https://stackoverflow.com/questions/17245881/how-do-i-debug-error-econnreset-in-node-js
|
||||
// c.write("<?xml version=\"1.0\"?>\n");
|
||||
// c.write("<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">\n");
|
||||
// c.write("<cross-domain-policy>\n");
|
||||
// c.write("<allow-access-from domain=\"*\" to-ports=\"*\"/>\n");
|
||||
// c.write("</cross-domain-policy>\n");
|
||||
// c.end();
|
||||
|
||||
c.pipe(c);
|
||||
}).listen(process.env.PORT, () => {
|
||||
console.log('Server gps tracker running at port ' + process.env.PORT);
|
||||
});
|
||||
// end for gps-tracking TCP ONLY
|
||||
|
||||
// start for normal http request
|
||||
app.use(express.json({ limit: '10mb' })); // parsing application/json
|
||||
app.use(express.urlencoded({ extended: true, limit: '10mb' })); // parsing application/x-www-form-urlencoded
|
||||
app.use(async function (req, res, next) {
|
||||
// set control allowed headers
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Methods', 'OPTIONS,GET,HEAD,PUT,PATCH,POST,DELETE');
|
||||
res.header('Access-Control-Allow-Headers', 'Accept, Authorization, Content-Type, X-Requested-With, Range, x-api-key, x-forwarded-for');
|
||||
next();
|
||||
});
|
||||
app.use(process.env.PATH_URL + '/bull/monitor', LibBullAdapter.getRouter());
|
||||
routes.use(app);
|
||||
app.listen(process.env.PORT_EXPRESS, () => {
|
||||
console.log('Express server running at port ' + process.env.PORT_EXPRESS);
|
||||
});
|
||||
// end for normal http request
|
||||
|
||||
// start for gps-tracking UDP ONLY
|
||||
const udp = dgram.createSocket('udp4');
|
||||
|
||||
const devices1 = [];
|
||||
udp.on('message', (msg, rinfo) => {
|
||||
const buffer_req = Buffer.from(msg, 'utf8');
|
||||
console.log('20203', buffer_req);
|
||||
console.log('20203', rinfo);
|
||||
Logger.log('info', buffer_req.toString('hex'));
|
||||
|
||||
const now = moment().unix();
|
||||
const me = LibDevice.identifyProtocolFromBuffer(buffer_req, {isEelinkCustom: 1});
|
||||
console.log('port 20203 ', me);
|
||||
|
||||
const logDevice = {
|
||||
original_hex: me.ori_buffer,
|
||||
protocol: (me.protocol_name == 'unknown') ? null : me.protocol_name,
|
||||
action: null,
|
||||
device_id: null,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
speed: null,
|
||||
orientation: 0,
|
||||
ignition: 0,
|
||||
stts_engine: 0,
|
||||
stts_gps: 0,
|
||||
length_gps: 0,
|
||||
pos_stlt_gps: 0,
|
||||
pos_type_gps: 0,
|
||||
is_pos_gps: 0,
|
||||
stts_gsm: 0,
|
||||
stts_oil_electricity: 0,
|
||||
stts_alarm: 0,
|
||||
stts_charge: 0,
|
||||
stts_acc: 0,
|
||||
stts_volt: 0,
|
||||
stts_switch: 0,
|
||||
stts_reverse_geo: 0,
|
||||
pre_milleage: 0,
|
||||
source: GpsTracksModels.SOURCE_GPS_TRACKER,
|
||||
crt: now,
|
||||
crt_format: moment.unix(now).format('YYYY-MM-DD HH:mm:ss'),
|
||||
crt_d: 0,
|
||||
crt_d_format: null,
|
||||
crt_s: now,
|
||||
crt_s_format: moment.unix(now).format('YYYY-MM-DD HH:mm:ss'),
|
||||
};
|
||||
|
||||
if (me.protocol_name === 'eelinkCustom') {
|
||||
let dvc_id = devices1[`${rinfo.address}:${rinfo.port}`];
|
||||
const act = LibDevice.eelinkCustomAction(me, dvc_id || null);
|
||||
console.log('act 20203', act);
|
||||
|
||||
if (act.action_type == 'exist_data') {
|
||||
logDevice.action = act.action_type;
|
||||
logDevice.device_id = act.device_id;
|
||||
|
||||
devices1[`${rinfo.address}:${rinfo.port}`] = act.device_id;
|
||||
if (typeof act.buffer_resp != 'undefined') {
|
||||
udp.send(act.buffer_resp, 0, act.buffer_resp.length, rinfo.port, rinfo.address, function(err, bytes) {
|
||||
if (err) throw err;
|
||||
console.log('UDP message sent to ' + rinfo.address +':'+ rinfo.port);
|
||||
console.log('20203', bytes);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
udp.on('error', (err) => {
|
||||
console.log(`udp error:\n${err.stack}`);
|
||||
udp.close();
|
||||
});
|
||||
udp.on('close',function(){
|
||||
console.log('udp socket is closed !');
|
||||
});
|
||||
udp.on('listening', () => {
|
||||
const address = udp.address();
|
||||
console.log(`udp listening ${address.address}:${address.port}`);
|
||||
});
|
||||
|
||||
udp.bind(process.env.PORT_UDP);
|
||||
// end for gps-tracking UDP ONLY
|
||||
51
app.js.express
Normal file
51
app.js.express
Normal file
@ -0,0 +1,51 @@
|
||||
require('dotenv').config({ path: '.env' });
|
||||
const express = require('express');
|
||||
const formidable = require('formidable');
|
||||
const routes = require('./routes/routes');
|
||||
const MorganMiddleware = require('./middleware/MorganMiddleware');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(MorganMiddleware);
|
||||
|
||||
app.use(express.json({ limit: '10mb' })); // parsing application/json
|
||||
app.use(express.urlencoded({ extended: true })); // parsing application/x-www-form-urlencoded
|
||||
// parsing form-data
|
||||
app.use(async function (req, res, next) {
|
||||
try {
|
||||
let isMultipart = req.headers['content-type'].includes('multipart/form-data', 0);
|
||||
if (isMultipart) {
|
||||
let form = new formidable.IncomingForm();
|
||||
let parseFormData = async function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
form.parse(req, function (err, fields, files) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
req.body = fields;
|
||||
resolve(true);
|
||||
})
|
||||
})
|
||||
}
|
||||
await parseFormData();
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
app.use(async function (req, res, next) {
|
||||
// set control allowed headers
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Methods', 'OPTIONS,GET,HEAD,PUT,PATCH,POST,DELETE');
|
||||
res.header('Access-Control-Allow-Headers', 'Accept, Authorization, Content-Type, X-Requested-With, Range, x-api-key, x-forwarded-for');
|
||||
next();
|
||||
});
|
||||
|
||||
// api
|
||||
routes.use(app);
|
||||
|
||||
app.listen(process.env.PORT, () => {
|
||||
console.log('Service running at port ' + process.env.PORT);
|
||||
});
|
||||
98
app.js.gps
Normal file
98
app.js.gps
Normal file
@ -0,0 +1,98 @@
|
||||
require('dotenv').config({ path: '.env' });
|
||||
const gps = require('gps-tracking');
|
||||
const express = require('express');
|
||||
const LibBullAdapter = require('./library/LibBullAdapter');
|
||||
const routes = require('./routes/routes');
|
||||
const app = express();
|
||||
|
||||
// start for gps-tracking
|
||||
const options = {
|
||||
'debug': true,
|
||||
'port': process.env.PORT,
|
||||
'device_adapter': "ET200"
|
||||
}
|
||||
|
||||
const server = gps.server(options, function (device, connection) {
|
||||
|
||||
/* Available device variables:
|
||||
----------------------------
|
||||
device.uid -> Set when the first packet is parsed
|
||||
device.name -> You can set a custon name for this device.
|
||||
device.ip -> IP of the device
|
||||
device.port --> Device port
|
||||
*/
|
||||
|
||||
// console.log('start: 0');
|
||||
// console.log(device);
|
||||
// console.log('end: 0');
|
||||
|
||||
/****************************** LOGIN ******************************/
|
||||
device.on("login_request", function (device_id, msg_parts) {
|
||||
// console.log('start: login_request');
|
||||
// console.log({device_id, msg_parts});
|
||||
//Do some stuff before authenticate the device...
|
||||
// This way you can prevent from anyone to send their position without your consent
|
||||
this.login_authorized(true, msg_parts); //Accept the login request.
|
||||
// console.log('end: login_request');
|
||||
});
|
||||
|
||||
device.on("login", function () {
|
||||
// console.log('start: login');
|
||||
// console.log("Hi! i'm " + device.uid);
|
||||
// console.log('end: login');
|
||||
});
|
||||
|
||||
device.on("login_rejected", function () {
|
||||
console.log('start: login_rejected');
|
||||
console.log('end: login_rejected');
|
||||
});
|
||||
|
||||
|
||||
/****************************** PING - When the gps sends their position ******************************/
|
||||
device.on("ping", function (data) {
|
||||
// //After the ping is received
|
||||
// console.log('start: ping');
|
||||
// console.log(data);
|
||||
// // console.log("I'm here now: " + gps_data.latitude + ", " + gps_data.longitude);
|
||||
// console.log('end: ping');
|
||||
return data;
|
||||
});
|
||||
|
||||
|
||||
/****************************** ALARM - When the gps sends and alarm ******************************/
|
||||
device.on("alarm", function (alarm_code, alarm_data, msg_data) {
|
||||
// console.log('start: alarm');
|
||||
// console.log(msg_data);
|
||||
// console.log("Help! Something happend: " + alarm_code + " (" + alarm_data.msg + ")");
|
||||
// console.log('end: alarm');
|
||||
//call_me();
|
||||
});
|
||||
|
||||
|
||||
/****************************** MISC ******************************/
|
||||
device.on("handshake", function () {
|
||||
// console.log('start: handshake');
|
||||
// console.log('end: handshake');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
server.setDebug(true);
|
||||
// end for gps-tracking
|
||||
|
||||
// start for normal http request
|
||||
app.use(express.json({ limit: '1mb' })); // parsing application/json
|
||||
app.use(express.urlencoded({ extended: true })); // parsing application/x-www-form-urlencoded
|
||||
app.use(async function (req, res, next) {
|
||||
// set control allowed headers
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Methods', 'OPTIONS,GET,HEAD,PUT,PATCH,POST,DELETE');
|
||||
res.header('Access-Control-Allow-Headers', 'Accept, Authorization, Content-Type, X-Requested-With, Range, x-api-key, x-forwarded-for');
|
||||
next();
|
||||
});
|
||||
app.use(process.env.PATH_URL + '/bull/monitor', LibBullAdapter.getRouter());
|
||||
routes.use(app);
|
||||
app.listen(process.env.PORT_EXPRESS, () => {
|
||||
console.log('Express server running at port ' + process.env.PORT_EXPRESS);
|
||||
});
|
||||
// end for normal http request
|
||||
26
app_dev_restapi.js
Normal file
26
app_dev_restapi.js
Normal file
@ -0,0 +1,26 @@
|
||||
require('dotenv').config({ path: '.env' });
|
||||
require('events').EventEmitter.prototype._maxListeners = 30;
|
||||
|
||||
// start for normal http request
|
||||
const express = require('express');
|
||||
// const LibBullAdapter = require('./library/LibBullAdapter');
|
||||
const routes = require('./routes/routes_without_scheduler');
|
||||
const app = express();
|
||||
// end for normal http request
|
||||
|
||||
// start for normal http request
|
||||
app.use(express.json({ limit: '10mb' })); // parsing application/json
|
||||
app.use(express.urlencoded({ extended: true, limit: '10mb' })); // parsing application/x-www-form-urlencoded
|
||||
app.use(async function (req, res, next) {
|
||||
// set control allowed headers
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Methods', 'OPTIONS,GET,HEAD,PUT,PATCH,POST,DELETE');
|
||||
res.header('Access-Control-Allow-Headers', 'Accept, Authorization, Content-Type, X-Requested-With, Range, x-api-key, x-forwarded-for');
|
||||
next();
|
||||
});
|
||||
// app.use(process.env.PATH_URL + '/bull/monitor', LibBullAdapter.getRouter());
|
||||
routes.use(app);
|
||||
app.listen(process.env.PORT_EXPRESS, () => {
|
||||
console.log('Express server running at port ' + process.env.PORT_EXPRESS);
|
||||
});
|
||||
// end for normal http request
|
||||
33
app_scheduler.js
Normal file
33
app_scheduler.js
Normal file
@ -0,0 +1,33 @@
|
||||
require('dotenv').config({ path: '.env' });
|
||||
require('events').EventEmitter.prototype._maxListeners = 30;
|
||||
|
||||
// start for normal http request
|
||||
const express = require('express');
|
||||
const LibBullAdapter = require('./library/LibBullAdapter');
|
||||
const routes = require('./routes/routes');
|
||||
const app = express();
|
||||
// end for normal http request
|
||||
|
||||
// start for normal http request
|
||||
app.use(express.json({ limit: '10mb' })); // parsing application/json
|
||||
app.use(express.urlencoded({ extended: true, limit: '10mb' })); // parsing application/x-www-form-urlencoded
|
||||
app.use(async function (req, res, next) {
|
||||
// set control allowed headers
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Methods', 'OPTIONS,GET,HEAD,PUT,PATCH,POST,DELETE');
|
||||
res.header('Access-Control-Allow-Headers', 'Accept, Authorization, Content-Type, X-Requested-With, Range, x-api-key, x-forwarded-for');
|
||||
next();
|
||||
});
|
||||
app.use(process.env.PATH_URL + '/bull/monitor', LibBullAdapter.getRouter());
|
||||
routes.use(app);
|
||||
app.listen(process.env.PORT_EXPRESS, () => {
|
||||
console.log('Express server running at port ' + process.env.PORT_EXPRESS);
|
||||
});
|
||||
// end for normal http request
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* https://redis.io/commands/keys/ => keys *SCanvasing-InvoiceMails*
|
||||
* https://stackoverflow.com/questions/4006324/how-to-atomically-delete-keys-matching-a-pattern-using-redis => redis-cli KEYS *YOUR_KEY_PREFIX* | xargs redis-cli DEL
|
||||
*/
|
||||
1
backup/.gitignore
vendored
Normal file
1
backup/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
!node_modules/
|
||||
41
config/dbMysqlConn.js
Normal file
41
config/dbMysqlConn.js
Normal file
@ -0,0 +1,41 @@
|
||||
const mysql = require('mysql');
|
||||
|
||||
const pool = mysql.createPool({
|
||||
connectionLimit: process.env.CONNECTIONLIMIT,
|
||||
host: process.env.DBHOST,
|
||||
user: process.env.DBUSER,
|
||||
password: process.env.DBPASSWORD,
|
||||
database: process.env.DATABASE,
|
||||
acquireTimeout: Number(process.env.ACQRTIMEOUT), // in ms
|
||||
});
|
||||
|
||||
pool.getConnection((err, conn) => {
|
||||
if (err) {
|
||||
if (err.code === 'PROTOCOL_CONNECTION_LOST') {
|
||||
console.error('Koneksi database ditutup.');
|
||||
}
|
||||
if (err.code === 'ER_CON_COUNT_ERROR') {
|
||||
console.error('Basis data memiliki terlalu banyak koneksi.');
|
||||
}
|
||||
if (err.code === 'ECONNREFUSED') {
|
||||
console.error('Koneksi database ditolak.');
|
||||
}
|
||||
console.error(err);
|
||||
}
|
||||
if (conn) conn.release();
|
||||
return;
|
||||
})
|
||||
|
||||
// pool.on('acquire', function (connection) {
|
||||
// console.log('Connection %d acquired', connection.threadId);
|
||||
// });
|
||||
|
||||
// pool.on('connection', function (connection) {
|
||||
// console.log('Connection %d connect', connection.threadId);
|
||||
// });
|
||||
|
||||
// pool.on('release', function (connection) {
|
||||
// console.log('Connection %d released', connection.threadId);
|
||||
// });
|
||||
|
||||
module.exports = pool;
|
||||
3
config/netConn.js
Normal file
3
config/netConn.js
Normal file
@ -0,0 +1,3 @@
|
||||
const netConn = [];
|
||||
|
||||
module.exports = netConn;
|
||||
22
config/request.js
Normal file
22
config/request.js
Normal file
@ -0,0 +1,22 @@
|
||||
const request = {
|
||||
osm_reverse_geo: {
|
||||
urlBase: 'https://nominatim.openstreetmap.org',
|
||||
urlPath: 'reverse',
|
||||
urlFull: 'https://nominatim.openstreetmap.org/reverse',
|
||||
method: 'GET',
|
||||
data: {
|
||||
format: 'geojson' // xml,json,jsonv2,geojson(prefer),geocodejson
|
||||
},
|
||||
},
|
||||
kodepos_region: {
|
||||
urlBase: 'https://kodepos.vercel.app',
|
||||
urlPath: 'search',
|
||||
urlFull: 'https://kodepos.vercel.app/search',
|
||||
method: 'GET',
|
||||
data: {
|
||||
json: 'true'
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = request;
|
||||
95
config/response.js
Normal file
95
config/response.js
Normal file
@ -0,0 +1,95 @@
|
||||
// default response by http code, maybe can be customed on controller
|
||||
// custom format response, maybe can be customed on controller
|
||||
|
||||
const response = {
|
||||
200: {
|
||||
meta: {
|
||||
code: '200',
|
||||
type: 'success',
|
||||
message: 'the request succeeded',
|
||||
},
|
||||
data: '',
|
||||
},
|
||||
201: {
|
||||
meta: {
|
||||
code: '201',
|
||||
type: 'success',
|
||||
message: 'resource created',
|
||||
},
|
||||
data: '',
|
||||
},
|
||||
202: {
|
||||
meta: {
|
||||
code: '202',
|
||||
type: 'success',
|
||||
message: 'resource accepted, but in progress',
|
||||
},
|
||||
data: '',
|
||||
},
|
||||
400: {
|
||||
meta: {
|
||||
code: '400',
|
||||
type: 'bad_request',
|
||||
message: 'bad request',
|
||||
},
|
||||
data: '',
|
||||
},
|
||||
401: {
|
||||
meta: {
|
||||
code: '401',
|
||||
type: 'unauthenticated',
|
||||
message: 'unauthenticated',
|
||||
},
|
||||
data: '',
|
||||
},
|
||||
404: {
|
||||
meta: {
|
||||
code: '404',
|
||||
type: 'not_found',
|
||||
message: 'resource not found',
|
||||
},
|
||||
data: '',
|
||||
},
|
||||
422: {
|
||||
meta: {
|
||||
code: '422',
|
||||
type: 'unprocessable_entity',
|
||||
message: 'bad input',
|
||||
},
|
||||
data: '',
|
||||
},
|
||||
500: {
|
||||
meta: {
|
||||
code: '500',
|
||||
type: 'error',
|
||||
message: 'error',
|
||||
},
|
||||
data: '',
|
||||
},
|
||||
email_unique: {
|
||||
meta: {
|
||||
code: '400',
|
||||
type: 'email_unique',
|
||||
message: 'email must be unique',
|
||||
},
|
||||
data: '',
|
||||
},
|
||||
wrong_password: {
|
||||
meta: {
|
||||
code: '400',
|
||||
type: 'wrong_password',
|
||||
message: 'wrong password',
|
||||
},
|
||||
data: '',
|
||||
},
|
||||
status_not_valid: {
|
||||
meta: {
|
||||
code: '400',
|
||||
type: 'status_not_valid',
|
||||
message: 'status not valid',
|
||||
},
|
||||
data: '',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = response;
|
||||
167
controllers/AuthController.js
Normal file
167
controllers/AuthController.js
Normal file
@ -0,0 +1,167 @@
|
||||
const moment = require('moment');
|
||||
const Validator = require('validatorjs');
|
||||
const Helper = require('../library/LibHelper');
|
||||
const UsersModels = require('../models/UsersModels');
|
||||
const LibPassword = require('../library/LibPassword');
|
||||
const LibJwt = require('../library/LibJwt');
|
||||
const response = require('../config/response');
|
||||
|
||||
Validator.useLang('en');
|
||||
|
||||
class AuthController {
|
||||
|
||||
async register(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
first_name: req.body.first_name,
|
||||
last_name: req.body.last_name,
|
||||
email: req.body.email,
|
||||
password: req.body.password,
|
||||
crt_at: moment.unix(now).format('YYYY-MM-DD HH:mm:ss'),
|
||||
updt_at: moment.unix(now).format('YYYY-MM-DD HH:mm:ss'),
|
||||
};
|
||||
const rulesInput = {
|
||||
first_name: 'required|string|max:45',
|
||||
last_name: 'required|string|max:45',
|
||||
email: 'required|email|max:45',
|
||||
password: 'required|string|min:6|max:16',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
// check email unique
|
||||
const getUsers = await UsersModels.findEmail(input.email);
|
||||
if (getUsers.length > 0) {
|
||||
apiRes.meta = response['email_unique'].meta;
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
// create account
|
||||
input.password = await LibPassword.hashPw(input.password); // hash password
|
||||
const respCreateUser = await UsersModels.create(input);
|
||||
|
||||
// success response
|
||||
apiRes.meta = response[201].meta;
|
||||
apiRes.data = (await UsersModels.find(respCreateUser.insertId))[0];
|
||||
return res.status(201).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async login(req, res) {
|
||||
let apiRes = {}
|
||||
try {
|
||||
const now = moment().unix()
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
email: req.body.email,
|
||||
password: req.body.password,
|
||||
};
|
||||
const rulesInput = {
|
||||
email: 'required|email',
|
||||
password: 'required|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
// login
|
||||
const getUsers = await UsersModels.findEmail(input.email);
|
||||
if (getUsers.length < 1) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[404]));
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
const isPwValid = await LibPassword.checkPw(getUsers[0].password, input.password);
|
||||
if (!isPwValid) {
|
||||
apiRes.meta = response['wrong_password'].meta;
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
await UsersModels.update({is_login: 1}, getUsers[0].id);
|
||||
|
||||
// success response
|
||||
const jwt = await LibJwt.createToken({
|
||||
uid: getUsers[0].id
|
||||
});
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success login';
|
||||
apiRes.data = getUsers[0];
|
||||
apiRes.token = jwt.token;
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async profile(req, res) {
|
||||
let apiRes = {}
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { uid } = req.jwt;
|
||||
|
||||
const getUsers = await UsersModels.find(uid);
|
||||
if (getUsers.length < 1) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[404]));
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
delete getUsers[0].password;
|
||||
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.data = getUsers[0];
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async logout(req, res) {
|
||||
let apiRes = {}
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { uid } = req.jwt;
|
||||
|
||||
const getUsers = await UsersModels.find(uid);
|
||||
if (getUsers.length < 1) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[404]));
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
await UsersModels.update({is_login: 0}, uid);
|
||||
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success logout';
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const object = new AuthController();
|
||||
|
||||
module.exports = object;
|
||||
165
controllers/DummyController.js
Normal file
165
controllers/DummyController.js
Normal file
@ -0,0 +1,165 @@
|
||||
const moment = require('moment');
|
||||
const Validator = require('validatorjs');
|
||||
const Helper = require('../library/LibHelper');
|
||||
const DummyModels = require('../models/DummyModels');
|
||||
const response = require('../config/response');
|
||||
const LibMail = require('../library/LibMail');
|
||||
|
||||
Validator.useLang('en');
|
||||
|
||||
class DummyController {
|
||||
|
||||
async logging(req, res) {
|
||||
let apiRes = {}
|
||||
const now = moment().unix();
|
||||
try {
|
||||
apiRes.meta = response[201].meta;
|
||||
|
||||
const insLog = {
|
||||
ip: req.ip,
|
||||
ips: JSON.stringify([...req.ips]),
|
||||
// protocol: req.protocol || null,
|
||||
method: req.method,
|
||||
path: req.path,
|
||||
headers: JSON.stringify({ ...req.headers }),
|
||||
params: JSON.stringify({ ...req.params }),
|
||||
request: JSON.stringify({ ...req.query, ...req.body }),
|
||||
cookies: JSON.stringify({ ...req.cookies }),
|
||||
xhr: req.xhr,
|
||||
response: JSON.stringify(apiRes),
|
||||
crt: now,
|
||||
};
|
||||
await DummyModels.create(insLog);
|
||||
|
||||
return res.status(201).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
|
||||
const insLog = {
|
||||
method: req.method,
|
||||
response: JSON.stringify(apiRes),
|
||||
crt: now,
|
||||
};
|
||||
await DummyModels.create(insLog);
|
||||
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async distance(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
|
||||
const { latFrom, lngFrom, latTo, lngTo } = req.query;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
latFrom: latFrom,
|
||||
lngFrom: lngFrom,
|
||||
latTo: latTo,
|
||||
lngTo: lngTo,
|
||||
};
|
||||
const rulesInput = {
|
||||
latFrom: 'required|string|max:25',
|
||||
lngFrom: 'required|string|max:25',
|
||||
latTo: 'required|string|max:25',
|
||||
lngTo: 'required|string|max:25',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
const respData = {};
|
||||
// round up with precisions digits => 4 == (10000)
|
||||
// reference: https://stackoverflow.com/questions/11832914/how-to-round-to-at-most-2-decimal-places-if-necessary
|
||||
// const precisionDigits = 10000;
|
||||
|
||||
// distance == miles
|
||||
// const distance = Helper.haversineGreatCircleDistance(latFrom, lngFrom, latTo, lngTo, Helper.EARTH_RADIUS_MILES);
|
||||
// respData.distance_km = Helper.milesToKm(distance);
|
||||
// respData.distance_miles = Helper.milesToMiles(distance);
|
||||
// respData.distance_meters = Helper.milesToMeters(distance);
|
||||
|
||||
// distance == km
|
||||
const distance = Helper.haversineGreatCircleDistance(latFrom, lngFrom, latTo, lngTo, Helper.EARTH_RADIUS_KM);
|
||||
respData.distance_km = Helper.kmToKm(distance);
|
||||
respData.distance_miles = Helper.kmToMiles(distance);
|
||||
respData.distance_meters = Helper.kmToMeters(distance);
|
||||
|
||||
// distance == meters
|
||||
// const distance = Helper.haversineGreatCircleDistance(latFrom, lngFrom, latTo, lngTo, Helper.EARTH_RADIUS_M);
|
||||
// respData.distance_km = Helper.metersToKm(distance);
|
||||
// respData.distance_miles = Helper.metersToMiles(distance);
|
||||
// respData.distance_meters = Helper.metersToMeters(distance);
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success get distance';
|
||||
apiRes.data = respData;
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async sendEmail(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
|
||||
const { subject, to } = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
subject,
|
||||
to
|
||||
};
|
||||
const rulesInput = {
|
||||
subject: 'required|string|max:125',
|
||||
to: 'required|string|max:255',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
const mailData = {
|
||||
pic_name: 'Rafif Mulia',
|
||||
pic_mail: 'rafifrest@gmail.com',
|
||||
z_name: 'REST-01',
|
||||
z_type_name: 'Warehousing',
|
||||
z_workflow_name: 'Parking',
|
||||
shiptocode: '12330',
|
||||
z_fulladdress: 'Jl. Perdagangan No.101, RT.4/RW.7, Bintaro, Kec. Pesanggrahan, Kota Jakarta Selatan, Daerah Khusus Ibukota Jakarta 12330',
|
||||
v_nopol: 'B 3633 EVV',
|
||||
da_name: 'Chienghou Zou',
|
||||
da_phone: '+62 8128 8789 878',
|
||||
};
|
||||
const resp = await LibMail.sendVhcSpawnZoneMail(subject, to, mailData);
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success send email';
|
||||
apiRes.data = resp;
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const object = new DummyController();
|
||||
|
||||
module.exports = object;
|
||||
821
controllers/OrderController.js
Normal file
821
controllers/OrderController.js
Normal file
@ -0,0 +1,821 @@
|
||||
const moment = require('moment');
|
||||
const Validator = require('validatorjs');
|
||||
const Helper = require('../library/LibHelper');
|
||||
const response = require('../config/response');
|
||||
const LibMail = require('../library/LibMail');
|
||||
const DanaModels = require('../models/DanaModels');
|
||||
// const LibQueueBlastOrder = require('../library/LibQueueBlastOrder');
|
||||
|
||||
Validator.useLang('en');
|
||||
|
||||
class OrderController {
|
||||
|
||||
async createOrder(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
|
||||
const {
|
||||
trx_code,
|
||||
trx_at,
|
||||
client_id,
|
||||
client_name,
|
||||
client_phone,
|
||||
client_mail,
|
||||
client_addr,
|
||||
client_prefer_type_truck,
|
||||
// weight,
|
||||
// cbm,
|
||||
// koli,
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
pickup_at,
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
vendors,
|
||||
admins,
|
||||
} = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
trx_code,
|
||||
trx_at,
|
||||
client_id,
|
||||
client_name,
|
||||
client_phone,
|
||||
client_mail,
|
||||
// client_addr,
|
||||
client_prefer_type_truck,
|
||||
// weight,
|
||||
// cbm,
|
||||
// koli,
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
pickup_at,
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
vendors,
|
||||
admins,
|
||||
};
|
||||
const rulesInput = {
|
||||
trx_code: 'required|string',
|
||||
trx_at: 'required|numeric',
|
||||
client_id: 'required|integer',
|
||||
client_name: 'required|string|max:255',
|
||||
client_phone: 'required|string',
|
||||
client_mail: 'required|email',
|
||||
// client_addr: 'required|string',
|
||||
client_prefer_type_truck: 'present|string',
|
||||
// weight: 'required|numeric',
|
||||
// cbm: 'required|numeric',
|
||||
// koli: 'required|numeric',
|
||||
pickup_zone_title: 'required|string',
|
||||
pickup_zone_addr: 'required|string',
|
||||
pickup_at: 'required|numeric',
|
||||
drop_zone_title: 'required|string',
|
||||
drop_zone_addr: 'required|string',
|
||||
// vendors: 'required|array',
|
||||
// 'vendors.*.vendor_id': 'required|integer',
|
||||
// 'vendors.*.vendor_name': 'required|string|max:255',
|
||||
// 'vendors.*.vendor_phone': 'required|string',
|
||||
// 'vendors.*.vendor_mail': 'required|email',
|
||||
// 'vendors.*.vendor_addr': 'present|string',
|
||||
// 'vendors.*.vendor_acc_link': 'required|string',
|
||||
// 'vendors.*.vendor_reject_link': 'required|string',
|
||||
admins: 'required|array',
|
||||
'admins.*.admin_id': 'required|integer',
|
||||
'admins.*.admin_name': 'required|string|max:255',
|
||||
'admins.*.admin_phone': 'required|string',
|
||||
'admins.*.admin_mail': 'required|email',
|
||||
// 'admins.*.admin_addr': 'present|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
let resp = {};
|
||||
// for (let vendor of vendors) {
|
||||
// let bidOrderMailData = {
|
||||
// client_id,
|
||||
// client_name,
|
||||
// client_phone,
|
||||
// client_mail,
|
||||
// client_addr,
|
||||
// client_prefer_type_truck: client_prefer_type_truck,
|
||||
// weight: Number(weight),
|
||||
// cbm: Number(cbm),
|
||||
// koli: Number(koli),
|
||||
// pickup_zone_title,
|
||||
// pickup_zone_addr,
|
||||
// pickup_at: moment.unix(pickup_at).format('DD MMM YYYY HH:mm') + ' WIB',
|
||||
// drop_zone_title,
|
||||
// drop_zone_addr,
|
||||
// vendor_id: vendor.vendor_id,
|
||||
// vendor_name: vendor.vendor_name,
|
||||
// vendor_phone: vendor.vendor_phone,
|
||||
// vendor_mail: vendor.vendor_mail,
|
||||
// vendor_addr: vendor.vendor_addr,
|
||||
// };
|
||||
// LibMail.sendBidOrderMail('Ada Order Masuk', vendor.vendor_mail, bidOrderMailData);
|
||||
// }
|
||||
|
||||
for (let admin of admins) {
|
||||
let infoOrderMailData = {
|
||||
trx_code,
|
||||
trx_at: moment.unix(trx_at).format('DD MMM YYYY HH:mm') + ' WIB',
|
||||
client_id,
|
||||
client_name,
|
||||
client_phone,
|
||||
client_mail,
|
||||
// client_addr,
|
||||
client_prefer_type_truck: client_prefer_type_truck,
|
||||
// weight: Number(weight),
|
||||
// cbm: Number(cbm),
|
||||
// koli: Number(koli),
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
pickup_at: moment.unix(pickup_at).format('DD MMM YYYY HH:mm') + ' WIB',
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
admin_id: admin.admin_id,
|
||||
admin_name: admin.admin_name,
|
||||
admin_phone: admin.admin_phone,
|
||||
admin_mail: admin.admin_mail,
|
||||
// admin_addr: admin.admin_addr,
|
||||
};
|
||||
LibMail.sendAdminInfoOrdMail('Ada Order Masuk', admin.admin_mail, infoOrderMailData);
|
||||
}
|
||||
|
||||
let clientCreateOrdMailData = {
|
||||
trx_code,
|
||||
trx_at: moment.unix(trx_at).format('DD MMM YYYY HH:mm') + ' WIB',
|
||||
client_id,
|
||||
client_name,
|
||||
client_phone,
|
||||
client_mail,
|
||||
// client_addr,
|
||||
client_prefer_type_truck: client_prefer_type_truck,
|
||||
// weight: Number(weight),
|
||||
// cbm: Number(cbm),
|
||||
// koli: Number(koli),
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
pickup_at: moment.unix(pickup_at).format('DD MMM YYYY HH:mm') + ' WIB',
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
};
|
||||
LibMail.sendClientCreateOrdMail('Kamu Telah Membuat Order ' + trx_code, client_mail, clientCreateOrdMailData);
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success create new order';
|
||||
apiRes.data = resp;
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async emailToVendor(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
|
||||
const {
|
||||
trx_code,
|
||||
trx_at,
|
||||
client_id,
|
||||
client_name,
|
||||
client_phone,
|
||||
client_mail,
|
||||
// client_addr,
|
||||
client_prefer_type_truck,
|
||||
// weight,
|
||||
// cbm,
|
||||
// koli,
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
pickup_at,
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
vendors,
|
||||
} = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
trx_code,
|
||||
trx_at,
|
||||
client_id,
|
||||
client_name,
|
||||
client_phone,
|
||||
client_mail,
|
||||
// client_addr,
|
||||
client_prefer_type_truck,
|
||||
// weight,
|
||||
// cbm,
|
||||
// koli,
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
pickup_at,
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
vendors,
|
||||
};
|
||||
|
||||
const rulesInput = {
|
||||
trx_code: 'required|string',
|
||||
trx_at: 'required|numeric',
|
||||
client_id: 'required|integer',
|
||||
client_name: 'required|string|max:255',
|
||||
client_phone: 'required|string',
|
||||
client_mail: 'required|email',
|
||||
// client_addr: 'required|string',
|
||||
client_prefer_type_truck: 'present|string',
|
||||
// weight: 'required|numeric',
|
||||
// cbm: 'required|numeric',
|
||||
// koli: 'required|numeric',
|
||||
pickup_zone_title: 'required|string',
|
||||
pickup_zone_addr: 'required|string',
|
||||
pickup_at: 'required|numeric',
|
||||
drop_zone_title: 'required|string',
|
||||
drop_zone_addr: 'required|string',
|
||||
vendors: 'required|array',
|
||||
'vendors.*.vendor_id': 'required|integer',
|
||||
'vendors.*.vendor_name': 'required|string|max:255',
|
||||
'vendors.*.vendor_phone': 'required|string',
|
||||
'vendors.*.vendor_mail': 'required|email',
|
||||
// 'vendors.*.vendor_addr': 'present|string',
|
||||
'vendors.*.vendor_acc_link': 'required|string',
|
||||
// 'vendors.*.vendor_reject_link': 'required|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
let resp = {};
|
||||
for (let vendor of vendors) {
|
||||
let bidOrderMailData = {
|
||||
trx_code,
|
||||
// client_id,
|
||||
client_name,
|
||||
client_phone,
|
||||
client_mail,
|
||||
// client_addr,
|
||||
client_prefer_type_truck: client_prefer_type_truck,
|
||||
// weight: Number(weight),
|
||||
// cbm: Number(cbm),
|
||||
// koli: Number(koli),
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
pickup_at: moment.unix(pickup_at).format('DD MMM YYYY HH:mm') + ' WIB',
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
// vendor_id: vendor.vendor_id,
|
||||
vendor_name: vendor.vendor_name,
|
||||
vendor_phone: vendor.vendor_phone,
|
||||
vendor_mail: vendor.vendor_mail,
|
||||
vendor_addr: vendor.vendor_addr,
|
||||
vendor_acc_link: vendor.vendor_acc_link,
|
||||
};
|
||||
LibMail.sendBidOrderMail('Ada Order Masuk', vendor.vendor_mail, bidOrderMailData);
|
||||
}
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success send email';
|
||||
apiRes.data = resp;
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async emailVdrAccOrder(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
|
||||
const {
|
||||
trx_code,
|
||||
trx_at,
|
||||
client_id,
|
||||
client_name,
|
||||
client_phone,
|
||||
client_mail,
|
||||
// client_addr,
|
||||
client_prefer_type_truck,
|
||||
// weight,
|
||||
// cbm,
|
||||
// koli,
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
pickup_at,
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
vendors,
|
||||
drivers,
|
||||
} = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
trx_code,
|
||||
trx_at,
|
||||
client_id,
|
||||
client_name,
|
||||
client_phone,
|
||||
client_mail,
|
||||
// client_addr,
|
||||
client_prefer_type_truck,
|
||||
// weight,
|
||||
// cbm,
|
||||
// koli,
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
pickup_at,
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
vendors,
|
||||
drivers,
|
||||
};
|
||||
const rulesInput = {
|
||||
trx_code: 'required|string',
|
||||
trx_at: 'required|numeric',
|
||||
client_id: 'required|integer',
|
||||
client_name: 'required|string|max:255',
|
||||
client_phone: 'required|string',
|
||||
client_mail: 'required|email',
|
||||
// client_addr: 'required|string',
|
||||
client_prefer_type_truck: 'present|string',
|
||||
// weight: 'required|numeric',
|
||||
// cbm: 'required|numeric',
|
||||
// koli: 'required|numeric',
|
||||
pickup_zone_title: 'required|string',
|
||||
pickup_zone_addr: 'required|string',
|
||||
pickup_at: 'required|numeric',
|
||||
drop_zone_title: 'required|string',
|
||||
drop_zone_addr: 'required|string',
|
||||
vendors: 'required|array',
|
||||
'vendors.*.vendor_id': 'required|integer',
|
||||
'vendors.*.vendor_name': 'required|string|max:255',
|
||||
'vendors.*.vendor_phone': 'required|string',
|
||||
'vendors.*.vendor_mail': 'required|email',
|
||||
// 'vendors.*.vendor_addr': 'present|string',
|
||||
'vendors.*.vendor_acc_at': 'required|numeric',
|
||||
drivers: 'required|array',
|
||||
'drivers.*.driver_id': 'required|integer',
|
||||
'drivers.*.driver_name': 'required|string|max:255',
|
||||
'drivers.*.driver_phone': 'required|string',
|
||||
'drivers.*.driver_mail': 'required|email',
|
||||
// 'drivers.*.driver_addr': 'present|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
let resp = {};
|
||||
for (let vendor of vendors) {
|
||||
let vdrAccOrderMailData = {
|
||||
trx_code,
|
||||
// client_id,
|
||||
client_name,
|
||||
client_phone,
|
||||
client_mail,
|
||||
// client_addr,
|
||||
client_prefer_type_truck: client_prefer_type_truck,
|
||||
// weight: Number(weight),
|
||||
// cbm: Number(cbm),
|
||||
// koli: Number(koli),
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
pickup_at: moment.unix(pickup_at).format('DD MMM YYYY HH:mm') + ' WIB',
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
// vendor_id: vendor.vendor_id,
|
||||
vendor_name: vendor.vendor_name,
|
||||
vendor_phone: vendor.vendor_phone,
|
||||
vendor_mail: vendor.vendor_mail,
|
||||
vendor_addr: vendor.vendor_addr,
|
||||
acc_at: moment.unix(vendor.vendor_acc_at).format('DD MMM YYYY HH:mm') + ' WIB',
|
||||
};
|
||||
LibMail.sendVdrAccOrderMail('Kamu Telah Menerima Order', vendor.vendor_mail, vdrAccOrderMailData);
|
||||
}
|
||||
|
||||
for (let driver of drivers) {
|
||||
let driverGetOrderMailData = {
|
||||
trx_code,
|
||||
// client_id,
|
||||
client_name,
|
||||
client_phone,
|
||||
client_mail,
|
||||
// client_addr,
|
||||
client_prefer_type_truck: client_prefer_type_truck,
|
||||
// weight: Number(weight),
|
||||
// cbm: Number(cbm),
|
||||
// koli: Number(koli),
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
pickup_at: moment.unix(pickup_at).format('DD MMM YYYY HH:mm') + ' WIB',
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
// driver_id: driver.driver_id,
|
||||
driver_name: driver.driver_name,
|
||||
driver_phone: driver.driver_phone,
|
||||
driver_mail: driver.driver_mail,
|
||||
driver_addr: driver.driver_addr,
|
||||
acc_at: moment.unix(vendors[0].vendor_acc_at).format('DD MMM YYYY HH:mm') + ' WIB',
|
||||
};
|
||||
LibMail.sendDrvGetOrderMail('Kamu Mendapatkan Order', driver.driver_mail, driverGetOrderMailData);
|
||||
}
|
||||
|
||||
let sendClientOrderHaveBeenAccMailData = {
|
||||
trx_code,
|
||||
// client_id,
|
||||
client_name,
|
||||
client_phone,
|
||||
client_mail,
|
||||
// client_addr,
|
||||
client_prefer_type_truck: client_prefer_type_truck,
|
||||
// weight: Number(weight),
|
||||
// cbm: Number(cbm),
|
||||
// koli: Number(koli),
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
pickup_at: moment.unix(pickup_at).format('DD MMM YYYY HH:mm') + ' WIB',
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
// vendor_id: vendors[0].vendor_id,
|
||||
vendor_name: vendors[0].vendor_name,
|
||||
vendor_phone: vendors[0].vendor_phone,
|
||||
vendor_mail: vendors[0].vendor_mail,
|
||||
vendor_addr: vendors[0].vendor_addr,
|
||||
// driver_id: drivers[0].driver_id,
|
||||
driver_name: drivers[0].driver_name,
|
||||
driver_phone: drivers[0].driver_phone,
|
||||
driver_mail: drivers[0].driver_mail,
|
||||
driver_addr: drivers[0].driver_addr,
|
||||
acc_at: moment.unix(vendors[0].vendor_acc_at).format('DD MMM YYYY HH:mm') + ' WIB',
|
||||
};
|
||||
LibMail.sendClientOrderHaveBeenAccMail('Order Kamu Telah Diambil Driver', client_mail, sendClientOrderHaveBeenAccMailData);
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success send email';
|
||||
apiRes.data = resp;
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async delayBlastOrderBAK(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
|
||||
const {
|
||||
ord_id,
|
||||
ord_code,
|
||||
current_ord_vdr_id,
|
||||
next_ord_vdr_id,
|
||||
next_vdr_bid_token,
|
||||
next_vdr_acc_link,
|
||||
} = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
ord_id,
|
||||
ord_code,
|
||||
current_ord_vdr_id,
|
||||
next_ord_vdr_id,
|
||||
next_vdr_bid_token,
|
||||
next_vdr_acc_link,
|
||||
};
|
||||
|
||||
const rulesInput = {
|
||||
ord_id: 'required|integer|min:1',
|
||||
ord_code: 'required|string',
|
||||
current_ord_vdr_id: 'required|integer|min:1',
|
||||
next_ord_vdr_id: 'present|array',
|
||||
next_vdr_bid_token: 'present|array',
|
||||
next_vdr_acc_link: 'present|array',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
LibQueueBlastOrder.addQueue({
|
||||
ord_id,
|
||||
ord_code,
|
||||
current_ord_vdr_id,
|
||||
next_ord_vdr_id,
|
||||
next_vdr_bid_token,
|
||||
next_vdr_acc_link,
|
||||
label: 'Delay Blast Order to Another Vendor',
|
||||
delay: 10 * (60 * 1000), // 600000 || 10 minute || 10 * (60 * 1000)
|
||||
});
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success blast order';
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async delayBlastOrder(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
|
||||
const {
|
||||
ord_id,
|
||||
ord_code,
|
||||
base_link,
|
||||
} = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
ord_id,
|
||||
ord_code,
|
||||
base_link,
|
||||
};
|
||||
|
||||
const rulesInput = {
|
||||
ord_id: 'required|integer|min:1',
|
||||
ord_code: 'required|string',
|
||||
base_link: 'required|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
LibQueueBlastOrder.addQueue({
|
||||
ord_id,
|
||||
ord_code,
|
||||
base_link,
|
||||
delay: 10 * (60 * 1000), // 600000 || 10 minute || 10 * (60 * 1000)
|
||||
});
|
||||
LibQueueBlastOrder.addQueue({
|
||||
ord_id,
|
||||
ord_code,
|
||||
base_link,
|
||||
delay: 20 * (60 * 1000), // 600000 || 20 minute || 20 * (60 * 1000)
|
||||
});
|
||||
LibQueueBlastOrder.addQueue({
|
||||
ord_id,
|
||||
ord_code,
|
||||
base_link,
|
||||
delay: 30 * (60 * 1000), // 600000 || 30 minute || 30 * (60 * 1000)
|
||||
});
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success blast order';
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async sendFinanceInfoTfPocket(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
|
||||
const {
|
||||
trx_code,
|
||||
drv_name,
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
pocket_total,
|
||||
bank_name,
|
||||
bank_code,
|
||||
bank_branch_name,
|
||||
bank_acc_name,
|
||||
bank_acc_no,
|
||||
admins,
|
||||
} = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
trx_code,
|
||||
drv_name,
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
pocket_total,
|
||||
bank_name,
|
||||
bank_code,
|
||||
bank_branch_name,
|
||||
bank_acc_name,
|
||||
bank_acc_no,
|
||||
admins,
|
||||
};
|
||||
const rulesInput = {
|
||||
trx_code: 'required|string|max:255',
|
||||
drv_name: 'required|string|max:255',
|
||||
pickup_zone_title: 'required|string|max:255',
|
||||
pickup_zone_addr: 'required|string',
|
||||
drop_zone_title: 'required|string|max:255',
|
||||
drop_zone_addr: 'required|string',
|
||||
pocket_total: 'required|string|max:255',
|
||||
bank_name: 'required|string',
|
||||
bank_code: 'required|string|max:255',
|
||||
bank_branch_name: 'string',
|
||||
bank_acc_name: 'required|string',
|
||||
bank_acc_no: 'required|string',
|
||||
admins: 'required|array',
|
||||
// 'admins.*.admin_id': 'required|integer',
|
||||
'admins.*.admin_name': 'required|string|max:255',
|
||||
'admins.*.admin_phone': 'required|string',
|
||||
'admins.*.admin_mail': 'required|email',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
let resp = {};
|
||||
|
||||
let mailData = {
|
||||
trx_code,
|
||||
drv_name,
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
pocket_total,
|
||||
bank_name,
|
||||
bank_code,
|
||||
bank_branch_name,
|
||||
bank_acc_name,
|
||||
bank_acc_no,
|
||||
};
|
||||
|
||||
for (let admin of admins) {
|
||||
mailData.admin_name = admin.admin_name;
|
||||
LibMail.sendFinanceInfoTfPocket('Transfer uang saku order ' + trx_code, admin.admin_mail, mailData);
|
||||
}
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success send mail';
|
||||
apiRes.data = resp;
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async sendFinanceInfoDanaAmount(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
|
||||
const {
|
||||
trx_code,
|
||||
drv_name,
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
pocket_total,
|
||||
bank_name,
|
||||
bank_code,
|
||||
bank_branch_name,
|
||||
bank_acc_name,
|
||||
bank_acc_no,
|
||||
admins,
|
||||
} = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
trx_code,
|
||||
drv_name,
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
pocket_total,
|
||||
bank_name,
|
||||
bank_code,
|
||||
bank_branch_name,
|
||||
bank_acc_name,
|
||||
bank_acc_no,
|
||||
admins,
|
||||
};
|
||||
const rulesInput = {
|
||||
trx_code: 'required|string|max:255',
|
||||
drv_name: 'required|string|max:255',
|
||||
pickup_zone_title: 'required|string|max:255',
|
||||
pickup_zone_addr: 'required|string',
|
||||
drop_zone_title: 'string|max:255',
|
||||
drop_zone_addr: 'string',
|
||||
pocket_total: 'required|string|max:255',
|
||||
bank_name: 'required|string',
|
||||
bank_code: 'required|string|max:255',
|
||||
bank_branch_name: 'string',
|
||||
bank_acc_name: 'required|string',
|
||||
bank_acc_no: 'required|string',
|
||||
admins: 'required|array',
|
||||
// 'admins.*.admin_id': 'required|integer',
|
||||
'admins.*.admin_name': 'required|string|max:255',
|
||||
'admins.*.admin_phone': 'required|string',
|
||||
'admins.*.admin_mail': 'required|email',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
const danas = await DanaModels.list({'id': DanaModels.PK_ID, 'limit': 1});
|
||||
if (danas.length < 1) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[400]));
|
||||
apiRes.meta.message = 'dana error';
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
const dana = danas[0];
|
||||
|
||||
let resp = {};
|
||||
|
||||
let mailData = {
|
||||
trx_code,
|
||||
drv_name,
|
||||
pickup_zone_title,
|
||||
pickup_zone_addr,
|
||||
drop_zone_title,
|
||||
drop_zone_addr,
|
||||
pocket_total,
|
||||
bank_name,
|
||||
bank_code,
|
||||
bank_branch_name,
|
||||
bank_acc_name,
|
||||
bank_acc_no,
|
||||
dana_current: 'Rp'+((new Intl.NumberFormat('id-ID')).format(dana.amt)).split('.').join('-').split(',').join('.').split('-').join(','), // yang . => - || , => . || - => ,,
|
||||
dana_minimum: 'Rp'+((new Intl.NumberFormat('id-ID')).format(DanaModels.MINIMUM_AMT)).split('.').join('-').split(',').join('.').split('-').join(','), // yang . => - || , => . || - => ,,
|
||||
};
|
||||
|
||||
for (let admin of admins) {
|
||||
mailData.admin_name = admin.admin_name;
|
||||
LibMail.sendFinanceInfoDanaAmount('Saldo Dana Tidak Mencukupi', admin.admin_mail, mailData);
|
||||
}
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success send mail';
|
||||
apiRes.data = resp;
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const object = new OrderController();
|
||||
|
||||
module.exports = object;
|
||||
2610
controllers/ServiceDriverController.js
Normal file
2610
controllers/ServiceDriverController.js
Normal file
File diff suppressed because it is too large
Load Diff
564
controllers/WorkerController.js
Normal file
564
controllers/WorkerController.js
Normal file
@ -0,0 +1,564 @@
|
||||
const moment = require('moment');
|
||||
const Validator = require('validatorjs');
|
||||
const Helper = require('../library/LibHelper');
|
||||
const GpsTracksModels = require('../models/GpsTracksModels');
|
||||
const response = require('../config/response');
|
||||
const LibSchedulerReverseGeocode = require('../library/LibSchedulerReverseGeocode');
|
||||
const LibQueueBlastOrder = require('../library/LibQueueBlastOrder');
|
||||
const LibSchedulerDrvUpLoc = require('../library/LibSchedulerDrvUpLoc');
|
||||
const LibSchedulerDrvUpPhoto = require('../library/LibSchedulerDrvUpPhoto');
|
||||
const LibSchedulerDrvUpLocIdle = require('../library/LibSchedulerDrvUpLocIdle');
|
||||
const LibSchedulerDrvBlastNotif = require('../library/LibSchedulerDrvBlastNotif');
|
||||
const LibSchedulerGpsTrackerWakeUp = require('../library/LibSchedulerGpsTrackerWakeUp');
|
||||
// START TESTING
|
||||
const axios = require('axios').default;
|
||||
const url = require('url');
|
||||
const request = require('../config/request');
|
||||
// END TESTING
|
||||
|
||||
Validator.useLang('en');
|
||||
|
||||
class WorkerController {
|
||||
|
||||
/**
|
||||
* QUEUE
|
||||
*/
|
||||
|
||||
async add(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { name, data } = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
name,
|
||||
};
|
||||
const rulesInput = {
|
||||
name: 'required|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
if (name === LibSchedulerReverseGeocode.name) {
|
||||
LibSchedulerReverseGeocode.runQueueScheduler({
|
||||
label: 'Reverse geocoding from gps tracker latlng',
|
||||
});
|
||||
} else if (name === LibQueueBlastOrder.name) {
|
||||
LibQueueBlastOrder.addQueue({
|
||||
...data,
|
||||
label: 'Blast Order to Another Vendor',
|
||||
delay: 5000, // 600000 || 10 minute
|
||||
});
|
||||
} else if (name === LibSchedulerDrvUpLoc.name) {
|
||||
LibSchedulerDrvUpLoc.runQueueScheduler({
|
||||
label: 'Scheduler driver up location',
|
||||
});
|
||||
} else if (name === LibSchedulerDrvUpPhoto.name) {
|
||||
LibSchedulerDrvUpPhoto.runQueueScheduler({
|
||||
label: 'Scheduler driver up photo',
|
||||
});
|
||||
} else if (name === LibSchedulerDrvUpLocIdle.name) {
|
||||
LibSchedulerDrvUpLocIdle.runQueueScheduler({
|
||||
label: 'Scheduler driver up location idle',
|
||||
});
|
||||
} else if (name === LibSchedulerDrvBlastNotif.name) {
|
||||
LibSchedulerDrvBlastNotif.runQueueScheduler({
|
||||
label: 'Scheduler driver blast notif',
|
||||
});
|
||||
} else if (name === LibSchedulerGpsTrackerWakeUp.name) {
|
||||
LibSchedulerGpsTrackerWakeUp.runQueueScheduler({
|
||||
label: 'Scheduler gps tracker wakeup',
|
||||
});
|
||||
} else {
|
||||
apiRes = JSON.parse(JSON.stringify(response[404]));
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success add queue';
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async getJobs(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { name } = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
name,
|
||||
};
|
||||
const rulesInput = {
|
||||
name: 'required|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
let gets = undefined;
|
||||
if (name === LibSchedulerReverseGeocode.name) {
|
||||
gets = await LibSchedulerReverseGeocode.getJobs();
|
||||
} else if (name === LibQueueBlastOrder.name) {
|
||||
gets = await LibQueueBlastOrder.getJobs();
|
||||
} else if (name === LibSchedulerDrvUpLoc.name) {
|
||||
gets = await LibSchedulerDrvUpLoc.getJobs();
|
||||
} else if (name === LibSchedulerDrvUpPhoto.name) {
|
||||
LibSchedulerDrvUpPhoto.getJobs();
|
||||
} else if (name === LibSchedulerDrvUpLocIdle.name) {
|
||||
gets = await LibSchedulerDrvUpLocIdle.getJobs();
|
||||
} else if (name === LibSchedulerDrvBlastNotif.name) {
|
||||
gets = await LibSchedulerDrvBlastNotif.getJobs();
|
||||
} else if (name === LibSchedulerGpsTrackerWakeUp.name) {
|
||||
gets = await LibSchedulerGpsTrackerWakeUp.getJobs();
|
||||
} else {
|
||||
apiRes = JSON.parse(JSON.stringify(response[404]));
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success get jobs';
|
||||
apiRes.data = gets;
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async getRepeatableJobs(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { name } = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
name,
|
||||
};
|
||||
const rulesInput = {
|
||||
name: 'required|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
let gets = undefined;
|
||||
if (name === LibSchedulerReverseGeocode.name) {
|
||||
gets = await LibSchedulerReverseGeocode.getRepeatableJobs();
|
||||
} else if (name === LibQueueBlastOrder.name) {
|
||||
gets = await LibQueueBlastOrder.getRepeatableJobs();
|
||||
} else if (name === LibSchedulerDrvUpLoc.name) {
|
||||
gets = await LibSchedulerDrvUpLoc.getRepeatableJobs();
|
||||
} else if (name === LibSchedulerDrvUpPhoto.name) {
|
||||
LibSchedulerDrvUpPhoto.getRepetableJobs();
|
||||
} else if (name === LibSchedulerDrvUpLocIdle.name) {
|
||||
gets = await LibSchedulerDrvUpLocIdle.getRepeatableJobs();
|
||||
} else if (name === LibSchedulerDrvBlastNotif.name) {
|
||||
gets = await LibSchedulerDrvBlastNotif.getRepeatableJobs();
|
||||
} else if (name === LibSchedulerGpsTrackerWakeUp.name) {
|
||||
gets = await LibSchedulerGpsTrackerWakeUp.getRepeatableJobs();
|
||||
} else {
|
||||
apiRes = JSON.parse(JSON.stringify(response[404]));
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success get repeatable jobs';
|
||||
apiRes.data = gets;
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async resume(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { name } = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
name,
|
||||
};
|
||||
const rulesInput = {
|
||||
name: 'required|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
if (name === LibSchedulerReverseGeocode.name) {
|
||||
LibSchedulerReverseGeocode.resumeQueue();
|
||||
} else if (name === LibQueueBlastOrder.name) {
|
||||
LibQueueBlastOrder.resumeQueue();
|
||||
} else if (name === LibSchedulerDrvUpLoc.name) {
|
||||
LibSchedulerDrvUpLoc.resumeQueue();
|
||||
} else if (name === LibSchedulerDrvUpLocIdle.name) {
|
||||
LibSchedulerDrvUpLocIdle.resumeQueue();
|
||||
} else if (name === LibSchedulerDrvUpPhoto.name) {
|
||||
LibSchedulerDrvUpPhoto.resumeQueue();
|
||||
} else if (name === LibSchedulerDrvBlastNotif.name) {
|
||||
LibSchedulerDrvBlastNotif.resumeQueue();
|
||||
} else if (name === LibSchedulerGpsTrackerWakeUp.name) {
|
||||
LibSchedulerGpsTrackerWakeUp.resumeQueue();
|
||||
} else {
|
||||
apiRes = JSON.parse(JSON.stringify(response[404]));
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success resume';
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async pause(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { name } = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
name,
|
||||
};
|
||||
const rulesInput = {
|
||||
name: 'required|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
if (name === LibSchedulerReverseGeocode.name) {
|
||||
LibSchedulerReverseGeocode.pauseQueue();
|
||||
} else if (name === LibQueueBlastOrder.name) {
|
||||
LibQueueBlastOrder.pauseQueue();
|
||||
} else if (name === LibSchedulerDrvUpLoc.name) {
|
||||
LibSchedulerDrvUpLoc.pauseQueue();
|
||||
} else if (name === LibSchedulerDrvUpPhoto.name) {
|
||||
LibSchedulerDrvUpPhoto.pauseQueue();
|
||||
} else if (name === LibSchedulerDrvUpLocIdle.name) {
|
||||
LibSchedulerDrvUpLocIdle.pauseQueue();
|
||||
} else if (name === LibSchedulerDrvBlastNotif.name) {
|
||||
LibSchedulerDrvBlastNotif.pauseQueue();
|
||||
} else if (name === LibSchedulerGpsTrackerWakeUp.name) {
|
||||
LibSchedulerGpsTrackerWakeUp.pauseQueue();
|
||||
} else {
|
||||
apiRes = JSON.parse(JSON.stringify(response[404]));
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success pause job';
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async drain(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { name } = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
name,
|
||||
};
|
||||
const rulesInput = {
|
||||
name: 'required|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
if (name === LibSchedulerReverseGeocode.name) {
|
||||
LibSchedulerReverseGeocode.drainQueue();
|
||||
} else if (name === LibQueueBlastOrder.name) {
|
||||
LibQueueBlastOrder.drainQueue();
|
||||
} else if (name === LibSchedulerDrvUpLoc.name) {
|
||||
LibSchedulerDrvUpLoc.drainQueue()
|
||||
} else if (name === LibSchedulerDrvUpPhoto.name) {
|
||||
LibSchedulerDrvUpPhoto.drainQueue();
|
||||
} else if (name === LibSchedulerDrvUpLocIdle.name) {
|
||||
LibSchedulerDrvUpLocIdle.drainQueue()
|
||||
} else if (name === LibSchedulerDrvBlastNotif.name) {
|
||||
LibSchedulerDrvBlastNotif.drainQueue()
|
||||
} else if (name === LibSchedulerGpsTrackerWakeUp.name) {
|
||||
LibSchedulerGpsTrackerWakeUp.drainQueue()
|
||||
} else {
|
||||
apiRes = JSON.parse(JSON.stringify(response[404]));
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success drain queue';
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async obliterate(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { name } = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
name,
|
||||
};
|
||||
const rulesInput = {
|
||||
name: 'required|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
if (name === LibSchedulerReverseGeocode.name) {
|
||||
LibSchedulerReverseGeocode.obliterateQueue();
|
||||
} else if (name === LibQueueBlastOrder.name) {
|
||||
LibQueueBlastOrder.obliterateQueue();
|
||||
} else if (name === LibSchedulerDrvUpLoc.name) {
|
||||
LibSchedulerDrvUpLoc.obliterateQueue();
|
||||
} else if (name === LibSchedulerDrvUpPhoto.name) {
|
||||
LibSchedulerDrvUpPhoto.obliterateQueue();
|
||||
} else if (name === LibSchedulerDrvUpLocIdle.name) {
|
||||
LibSchedulerDrvUpLocIdle.obliterateQueue();
|
||||
} else if (name === LibSchedulerDrvBlastNotif.name) {
|
||||
LibSchedulerDrvBlastNotif.obliterateQueue();
|
||||
} else if (name === LibSchedulerGpsTrackerWakeUp.name) {
|
||||
LibSchedulerGpsTrackerWakeUp.obliterateQueue();
|
||||
} else {
|
||||
apiRes = JSON.parse(JSON.stringify(response[404]));
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success obliterateQueue queue';
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WORKERS
|
||||
*/
|
||||
|
||||
async start(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { name } = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
name,
|
||||
};
|
||||
const rulesInput = {
|
||||
name: 'required|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
// just work if before this set have waiting list, so new queue will not be processed
|
||||
if (name === LibSchedulerReverseGeocode.name) {
|
||||
LibSchedulerReverseGeocode.setWorker();
|
||||
} else if (name === LibQueueBlastOrder.name) {
|
||||
LibQueueBlastOrder.setWorker();
|
||||
} else if (name === LibSchedulerDrvUpLoc.name) {
|
||||
LibSchedulerDrvUpLoc.setWorker();
|
||||
} else if (name === LibSchedulerDrvUpPhoto.name) {
|
||||
LibSchedulerDrvUpPhoto.setWorker();
|
||||
} else if (name === LibSchedulerDrvUpLocIdle.name) {
|
||||
LibSchedulerDrvUpLocIdle.setWorker();
|
||||
} else if (name === LibSchedulerDrvBlastNotif.name) {
|
||||
LibSchedulerDrvBlastNotif.setWorker();
|
||||
} else if (name === LibSchedulerGpsTrackerWakeUp.name) {
|
||||
LibSchedulerGpsTrackerWakeUp.setWorker();
|
||||
} else {
|
||||
apiRes = JSON.parse(JSON.stringify(response[404]));
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success start worker';
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async shutdown(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { name } = req.body;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
name,
|
||||
};
|
||||
const rulesInput = {
|
||||
name: 'required|string',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
if (name === LibSchedulerReverseGeocode.name) {
|
||||
LibSchedulerReverseGeocode.workerShutDown();
|
||||
} else if (name === LibQueueBlastOrder.name) {
|
||||
LibQueueBlastOrder.workerShutDown();
|
||||
} else if (name === LibSchedulerDrvUpLoc.name) {
|
||||
LibSchedulerDrvUpLoc.workerShutDown();
|
||||
} else if (name === LibSchedulerDrvUpPhoto.name) {
|
||||
LibSchedulerDrvUpPhoto.workerShutDown();
|
||||
} else if (name === LibSchedulerDrvUpLocIdle.name) {
|
||||
LibSchedulerDrvUpLocIdle.workerShutDown();
|
||||
} else if (name === LibSchedulerDrvBlastNotif.name) {
|
||||
LibSchedulerDrvBlastNotif.workerShutDown();
|
||||
} else if (name === LibSchedulerGpsTrackerWakeUp.name) {
|
||||
LibSchedulerGpsTrackerWakeUp.workerShutDown();
|
||||
} else {
|
||||
apiRes = JSON.parse(JSON.stringify(response[404]));
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success shutdown worker';
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DO THE PROCESS VIA REQUEST
|
||||
*/
|
||||
|
||||
async revgeo(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
|
||||
// input validation
|
||||
// const input = { };
|
||||
// const rulesInput = { };
|
||||
// const isInputValid = new Validator(input, rulesInput);
|
||||
// if (isInputValid.fails()) {
|
||||
// apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
// apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
// return res.status(200).json(apiRes);
|
||||
// }
|
||||
|
||||
let params = new url.URLSearchParams({
|
||||
lat: req.body.lat,
|
||||
lon: req.body.lon,
|
||||
format: 'geojson',
|
||||
});
|
||||
const axInstance = axios.create();
|
||||
axios.defaults.timeout = 3000;
|
||||
axios.defaults.crossDomain = true;
|
||||
// respReverseGeo = await axios({
|
||||
// url: request.osm_reverse_geo.urlFull,
|
||||
// method: request.osm_reverse_geo.method,
|
||||
// params: params,
|
||||
// timeout: 3000,
|
||||
// responseType: 'json',
|
||||
// });
|
||||
let respReverseGeo = await axInstance.get(request.osm_reverse_geo.urlFull + '?' + params.toString(), {
|
||||
timeout: 3000,
|
||||
});
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success reverse geocode';
|
||||
apiRes.meta.data = respReverseGeo.data;
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
// apiRes.debug = e.response.data;
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const object = new WorkerController();
|
||||
|
||||
module.exports = object;
|
||||
134
controllers/ZoneController.js
Normal file
134
controllers/ZoneController.js
Normal file
@ -0,0 +1,134 @@
|
||||
const moment = require('moment');
|
||||
const Validator = require('validatorjs');
|
||||
const Helper = require('../library/LibHelper');
|
||||
const ZoneModels = require('../models/ZoneModels');
|
||||
const response = require('../config/response');
|
||||
const axios = require('axios').default;
|
||||
const url = require('url');
|
||||
const request = require('../config/request');
|
||||
|
||||
Validator.useLang('en');
|
||||
|
||||
class ZoneController {
|
||||
|
||||
async nearest(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { lat, lng, meters } = req.query;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
lat: lat,
|
||||
lng: lng,
|
||||
meters: meters,
|
||||
};
|
||||
const rulesInput = {
|
||||
lat: 'required|string|max:25',
|
||||
lng: 'required|string|max:25',
|
||||
meters: 'required|numeric',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
const nearest = await ZoneModels.getNearest(lat, lng, meters);
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success get nearest zone in meters: ' + meters;
|
||||
apiRes.count = nearest.length;
|
||||
apiRes.data = nearest;
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async inCircle(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { lat, lng } = req.query;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
lat: lat,
|
||||
lng: lng,
|
||||
};
|
||||
const rulesInput = {
|
||||
lat: 'required|string|max:25',
|
||||
lng: 'required|string|max:25',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
const inCircle = await ZoneModels.getInCircle(lat, lng);
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success get in circle zone';
|
||||
apiRes.count = inCircle.length;
|
||||
apiRes.data = inCircle;
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
async inShape(req, res) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const now = moment().unix();
|
||||
const { lat, lng } = req.query;
|
||||
|
||||
// input validation
|
||||
const input = {
|
||||
lat: lat,
|
||||
lng: lng,
|
||||
};
|
||||
const rulesInput = {
|
||||
lat: 'required|string|max:25',
|
||||
lng: 'required|string|max:25',
|
||||
};
|
||||
const isInputValid = new Validator(input, rulesInput);
|
||||
if (isInputValid.fails()) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[422]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + Object.values(isInputValid.errors.all())[0][0]); // get first message
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
|
||||
const inShape = await ZoneModels.getInShape(lat, lng);
|
||||
|
||||
// success response
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||
apiRes.meta.message = 'success get in shape zone';
|
||||
apiRes.count = inShape.length;
|
||||
apiRes.data = inShape;
|
||||
|
||||
return res.status(200).json(apiRes);
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(500).json(apiRes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const object = new ZoneController();
|
||||
|
||||
module.exports = object;
|
||||
39
docker-compose.yml
Normal file
39
docker-compose.yml
Normal file
@ -0,0 +1,39 @@
|
||||
version: "3.7"
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: ./
|
||||
dockerfile: Dockerfile
|
||||
image: trucking-node
|
||||
container_name: trucking-node
|
||||
restart: unless-stopped
|
||||
working_dir: /var/www/html/services/trucking
|
||||
volumes:
|
||||
- .:/var/www/html/services/trucking
|
||||
ports:
|
||||
- "6014:6014"
|
||||
- "3400:3400"
|
||||
networks:
|
||||
- trucking-node
|
||||
entrypoint: [ "/bin/sh", "-c" ]
|
||||
command:
|
||||
- |
|
||||
mv /node_modules /var/www/html/services/trucking/node_modules
|
||||
npm run app_scheduler
|
||||
|
||||
redis:
|
||||
image: redis:alpine
|
||||
container_name: trucking-redis
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "6380:6379"
|
||||
networks:
|
||||
- trucking-node
|
||||
entrypoint: [ "/bin/sh", "-c" ]
|
||||
command:
|
||||
- |
|
||||
redis-server
|
||||
|
||||
networks:
|
||||
trucking-node:
|
||||
driver: bridge
|
||||
@ -0,0 +1,12 @@
|
||||
{
|
||||
"type": "service_account",
|
||||
"project_id": "bingcorp-tracker",
|
||||
"private_key_id": "7399bbf4fca3bc4205b32f1a3b9adb740e005aaf",
|
||||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDTpSHA3BozL9mB\nq/2p78/seNNjB7fGwRWIU+s55wAhI46SWgbRs8rpSbVskN8m+KssJPGQg423sj6d\nY72uxULbGVuoM7jRphj52PfxajhUU8VhLWk0oPZqz66arAxiRBQZXrgUgk3jTj3G\nGnkgdFOF/pgBSc8XvN7CUE3A6ktteu2DkKbAI6itP8uA5xp8wtmBfc8hU4pIe1mi\nhrI+WUF2tIO5NsblbhcZWBzodBOTxq3wkcbuLarWWb2rrL7HEbRnG0TzsGRl+Hso\npcGjLwdz2FZuW2HJGWSABqazazlmDEnqk2PDJFsUCyZV38tE+zfvPvh1DnCmNvBB\n7YXW8aPPAgMBAAECggEAL3Po23r+DNf/polPeJiiP9zfWGbUl6WXFFfsd7EJYGS+\nhKXWvZHYPvId0VeyEOTUTDOETeiRD8zRKSzBzLvBv6ox2Mav+6GIHAy/mss8Efwu\nVxl9ayVj2pLyDQ/iPu4Qq5eHImIM4JgcVZx95/7s8zAgGLnZyvK3501mAYkGnGb4\nuO4sqIJsWUa2xmztBgJ9C09VCcBsp0qbFsNV7rA6ygumuvHenXEKvABHtXLqRdBs\nhdoSah4CYqbD80DpEdZVQirS13BjromQ2f3iN9icdBzX2dS6HYCm/fRvKk03HK8N\nPtJNkeaQLG6I955pNSAomV6wm5Z4abmEPPYv8mv/0QKBgQD85SiazR4xJK5DmkeS\nYhxW2Fi9hM0AShtyIjcV4uMgYB5mQ/bxQIuyx8bchUoTPHf7l1IN1nGIBLA37ePU\nuEWqxZfQ2x1yFXEAKL214piRuVXK48kc5734hKQFeTkhNonhMEyoci1SrAhSDsXH\nbeSggtAiVQFzIgCCFH28qmwpjQKBgQDWPlNSUpR8uwEZ19q90UbzCWC3RsiPyGEM\nKxMk4FHC1Hq2y/dL87UyKOL3UupzUGVowMKyktT4nHhP3zhgBu7CFk9GM6BgecNR\nivTmVZoLKZr4sj+weZzZuwDWa+lii3XU4te/CoH9cqk4c7aFQmtWV8hi5AfDf17Z\nqdKoX/y1ywKBgCZJg2Y8W6/Q/9kYSHGvDN9RDc5Thr3eel1DNNfJa92A79lHvOE1\nhnDgsgi83UQgSYH7nN6fcrzHCO7Ow0l3RITgOWXTZpfZCyyc/mvFDJgzWPvIlLAd\nnbM8UaDKg421thYzu8dc0ePMS84wklzpFE4AwAYSnI+TvEP1WjvwCUQZAoGBAIIz\nFkftT7gNnbmq6JB64ndIt7IqHjDjQbc3Zkb+3DFfF8SHaB6MWQ3Gs0hC56B0t2xV\n2PzVJwB/ds5zhbs1+1uQW1T6gviehwjDPdnNI/SssDV7fiEthxj7AKNOqWLuBgn+\nYccEB8OTLyvThpStrLWoW2td0SoJ+galohQZYWbJAoGAVnpfqm2j3mpmebNpAVDy\nzfGKsEo6QBiUeyoGIyRnWqw+jg/jP4a6ytryuUfL/u0QilVXZxSeEZ51wAfpXjud\nCNTVSIFja1df4tp2vgQifJw3y/SpK0IVDs3vBoxL2kCknpDEAnKBbhUv3WVqSCg2\n3ULAhzsRuh3d7Vs/hdMfgOI=\n-----END PRIVATE KEY-----\n",
|
||||
"client_email": "firebase-adminsdk-7tcet@bingcorp-tracker.iam.gserviceaccount.com",
|
||||
"client_id": "104296203536255131294",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-7tcet%40bingcorp-tracker.iam.gserviceaccount.com"
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
{
|
||||
"type": "service_account",
|
||||
"project_id": "bingcorp-tracker",
|
||||
"private_key_id": "c817089752ecb864e685fc23acc65fcb4c14cffe",
|
||||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDGNPI/mray4qQ/\noOxUSbVB2IRiQgxUAifKumWq7/r8229+2ZJQHXuHu8fGPHzS8U9VtZ50pyRyW8kF\n6mrKjmHOG/0EKZPx/GWa/mSpDGENEpKsDIPRrbfrUjZs0oILRXQC1Dvh6USq0th6\nQdFFUiXb8oL03IpSdmUQscUICM1IdS75IAxPRhAg8UQlG9GQggqM7jyKpzwncW4M\nRY+VoCN3znx+X5Hn7OBMcF5IbGq4Fuk4GKgHjkqoHeNUtswrF6k6ZAUdvPie0rhw\n+cFYQdt6O0VcgTA0GtlMUrm5IPxJhD1jLL8p8Mr9kckp1xzqHnxfdqCgOgydIjRM\ns0VCMB77AgMBAAECggEAMXjptmKBk6jqYk9iba9wJJ1MfdIKjbV0BS/9TGtV9GM5\nMypPUNvrB3ghZyOV7Hj62mPYxzko6bprNKTMPv7G/tERmEZgfRgIrGUu7tr+Jmsq\nXPNKu71mmMAOgZ8Rgoq1aDddMwgscY7rJajj+S+F755afY/Gnsqac05L5bN8ucbE\nt9w8zvcut9nKpcMGHSjhgIacTFnAsjw6ZN485UDHKNoxL7DPdMILtJcqzK9dufvQ\n4yf4ps+3VBxLgXEw6yUU5PfFJxIPhZ9VHGOjWCcqsNN0XIiWB5wLpTdwFSqr1+fL\nleRPo1aRY/IqhrFvLqjGSjukxfMtlRjpvHAUTsNw4QKBgQD/kOSAWLM+h1krgm26\nPf7B+0A2cIwVO+Qc1f7JCYgzZA3/xQoclmL5pr+llc6wiLPFTucomu5sD+X8Es1i\nY5Zcxtr7FuUXraNBXsExfzRsGDpD3Skp2Jzq29+eqof5lgFZaLxfW1fPRAgvH0Ml\n32kcG2huWJHvBenA1zeX0yP1QwKBgQDGix3lPgfibEunlop5WZovOcHa3LIAA8t3\n8aBb4sx3xFrTRPYyB+39dGk2FiV/sjofw57MmNhc/EIM6kMEvR0TlDuqHIPUbV5/\nPqeeB6ZSHiTbT+DzuyR9FVnDkKLSpa630cBCI/LVT+Bzb3UbAPGU7WtEEIHn8FKq\nxo1ZoaG36QKBgQCinaqX9FjRj8PwiISTfkEtY1b/jOvF0x8aLhx6BWOx95dkyRbf\nC94cprrJfSJQeBuTj9pMnxDYl+EqXThsw5t4m1vZaz8Iqwb3YHijqyJLKbthVUeN\nBfULCC8pQa9V49ol7xv1vSSJkOt4OHc8kQTLyrDPjfIF2ohbmVYZeFMoCwKBgAMV\ngh9feUvhFsPBqOD9rVFyejpmFzW82VpBnJYQzdBGcoq5lYFtchrvxfqbGXYEVLbN\nmRfgf+vh1zzQHr5iGaOGN+8Khlm0YTVkycHAqKq54SSu9vWSQJzYyg4pnv3aqP4d\n+fiNCmaZ2QiyAIWs3BPOJE5oWzw5FW+lqehshFCRAoGAW8ebJPM8BAcmYnLzF+6d\nnbmMm7jYG+H3oXWmPm64wJZbB96KlKO6zv3s8H3HxDh1IH30gwXEjJlDfweSrBKg\n+kTodZf8AiZ9ehXRfrTYoAaEVoa1VxOnmlxvBLHm/jNsFQ3EKHSkHBMgpXuw1ew1\n+boJf7x3wYYenIozHGpRMYI=\n-----END PRIVATE KEY-----\n",
|
||||
"client_email": "firebase-adminsdk-7tcet@bingcorp-tracker.iam.gserviceaccount.com",
|
||||
"client_id": "104296203536255131294",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-7tcet%40bingcorp-tracker.iam.gserviceaccount.com"
|
||||
}
|
||||
40
files/keys/google-services.json
Normal file
40
files/keys/google-services.json
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "805397037863",
|
||||
"firebase_url": "https://bingcorp-tracker-default-rtdb.asia-southeast1.firebasedatabase.app",
|
||||
"project_id": "bingcorp-tracker",
|
||||
"storage_bucket": "bingcorp-tracker.appspot.com"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:805397037863:android:dd7678e4f5da382d209f02",
|
||||
"android_client_info": {
|
||||
"package_name": "com.example.bingcopapp"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "805397037863-pe9itqcudrnjcvv76f68tgni2cqd1c4i.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyCO2sI-MFlAWS-4uzm9wX5QhCZDyvMWBi4"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "805397037863-pe9itqcudrnjcvv76f68tgni2cqd1c4i.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
||||
70
files/mails/admInfoOrder.ejs
Normal file
70
files/mails/admInfoOrder.ejs
Normal file
@ -0,0 +1,70 @@
|
||||
<%- include('template/start', {asset: asset}) %>
|
||||
|
||||
<tr>
|
||||
<td valign="middle" class="hero" style="padding: .25rem 0 .75rem 0">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="text" style="padding: 1.5rem 1rem; text-align: left; background-color: #fff; margin: 0 1.5rem; border: 1px solid #e4e4e4; border-top: 4px solid #e52920;">
|
||||
<h4 style="font-size: 14x; color: #212B36">Halo <%= admin_name %>,</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Ada client telah membuat order pada tanggal <%= trx_at %> dengan kriteria berikut:
|
||||
</h4>
|
||||
<table style="font-size: 14x; color: #212B36">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Order_Code</th>
|
||||
<td><%= trx_code %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Pickup_At</th>
|
||||
<td>
|
||||
<b><%= pickup_at %></b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client_Name</th>
|
||||
<td><%= client_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client_Phone</th>
|
||||
<td><%= client_phone %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client_Mail</th>
|
||||
<td><%= client_mail %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Pickup_Zone</th>
|
||||
<td>
|
||||
<b><%= pickup_zone_title %></b> <br>
|
||||
<%= pickup_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Drop_Zone</th>
|
||||
<td>
|
||||
<b><%= drop_zone_title %></b> <br>
|
||||
<%= drop_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Segera lakukan pencarian vendor
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Butuh bantuan ? Segera hubungi layanan pelanggan Bonceng di <%= cs_phone %> atau email ke <%= cs_mail %>.
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Email ini dibuat secara otomatis. Mohon tidak mengirimkan balasan ke email ini.
|
||||
</h4>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<%- include('template/end', {asset: asset, cs_mail: cs_mail, cs_phone: cs_phone, cs_addr: cs_addr}) %>
|
||||
70
files/mails/adminInfoNoVdrAccOrd.ejs
Normal file
70
files/mails/adminInfoNoVdrAccOrd.ejs
Normal file
@ -0,0 +1,70 @@
|
||||
<%- include('template/start', {asset: asset}) %>
|
||||
|
||||
<tr>
|
||||
<td valign="middle" class="hero" style="padding: .25rem 0 .75rem 0">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="text" style="padding: 1.5rem 1rem; text-align: left; background-color: #fff; margin: 0 1.5rem; border: 1px solid #e4e4e4; border-top: 4px solid #e52920;">
|
||||
<h4 style="font-size: 14x; color: #212B36">Halo <%= admin_name %>,</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Order pada tanggal <%= trx_at %>, tidak ada vendor yang menerima / menginginkan order dengan kriteria berikut:
|
||||
</h4>
|
||||
<table style="font-size: 14x; color: #212B36">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Order_Code</th>
|
||||
<td><%= trx_code %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Pickup_At</th>
|
||||
<td>
|
||||
<b><%= pickup_at %></b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client_Name</th>
|
||||
<td><%= client_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client_Phone</th>
|
||||
<td><%= client_phone %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client_Mail</th>
|
||||
<td><%= client_mail %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Pickup_Zone</th>
|
||||
<td>
|
||||
<b><%= pickup_zone_title %></b> <br>
|
||||
<%= pickup_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Drop_Zone</th>
|
||||
<td>
|
||||
<b><%= drop_zone_title %></b> <br>
|
||||
<%= drop_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Segera lakukan pencarian / assign vendor secara manual
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Butuh bantuan ? Segera hubungi layanan pelanggan Bonceng di <%= cs_phone %> atau email ke <%= cs_mail %>.
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Email ini dibuat secara otomatis. Mohon tidak mengirimkan balasan ke email ini.
|
||||
</h4>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<%- include('template/end', {asset: asset, cs_mail: cs_mail, cs_phone: cs_phone, cs_addr: cs_addr}) %>
|
||||
98
files/mails/bidOrderMail.ejs
Normal file
98
files/mails/bidOrderMail.ejs
Normal file
@ -0,0 +1,98 @@
|
||||
<%- include('template/start', {asset: asset}) %>
|
||||
|
||||
<tr>
|
||||
<td valign="middle" class="hero" style="padding: .25rem 0 .75rem 0">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="text" style="padding: 1.5rem 1rem; text-align: left; background-color: #fff; margin: 0 1.5rem; border: 1px solid #e4e4e4; border-top: 4px solid #e52920;">
|
||||
<h4 style="font-size: 14x; color: #212B36">Halo <%= vendor_name %>,</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Ada order masuk dengan kriteria berikut:
|
||||
</h4>
|
||||
<table style="font-size: 14x; color: #212B36">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Order_Code</th>
|
||||
<td><%= trx_code %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client_Name</th>
|
||||
<td><%= client_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client_Phone</th>
|
||||
<td><%= client_phone %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client_Mail</th>
|
||||
<td><%= client_mail %></td>
|
||||
</tr>
|
||||
<% if(client_prefer_type_truck !== ''){ %>
|
||||
<tr>
|
||||
<th>Preferred_Type</th>
|
||||
<td><%= client_prefer_type_truck %></td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<!-- start comment -->
|
||||
<% /* %>
|
||||
<% if(weight !== 0){ %>
|
||||
<tr>
|
||||
<th>Weight</th>
|
||||
<td><%= weight %> Kg</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% if(cbm !== 0){ %>
|
||||
<tr>
|
||||
<th>Volume</th>
|
||||
<td><%= cbm %> m³</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% if(koli !== 0){ %>
|
||||
<tr>
|
||||
<th>Koli</th>
|
||||
<td><%= koli %> Pcs</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% */ %>
|
||||
<!-- end comment -->
|
||||
<tr>
|
||||
<th>Pickup_Zone</th>
|
||||
<td>
|
||||
<b><%= pickup_zone_title %></b> <br>
|
||||
<%= pickup_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Pickup_At</th>
|
||||
<td>
|
||||
<b><%= pickup_at %></b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Drop_Zone</th>
|
||||
<td>
|
||||
<b><%= drop_zone_title %></b> <br>
|
||||
<%= drop_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Jika kamu ingin mengambil order ini, silahkan segera klik link berikut: <a href="<%= vendor_acc_link %>"><%= vendor_acc_link %></a>
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Butuh bantuan ? Segera hubungi layanan pelanggan Bonceng di <%= cs_phone %> atau email ke <%= cs_mail %>.
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Email ini dibuat secara otomatis. Mohon tidak mengirimkan balasan ke email ini.
|
||||
</h4>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<%- include('template/end', {asset: asset, cs_mail: cs_mail, cs_phone: cs_phone, cs_addr: cs_addr}) %>
|
||||
86
files/mails/clientCreateOrd.ejs
Normal file
86
files/mails/clientCreateOrd.ejs
Normal file
@ -0,0 +1,86 @@
|
||||
<%- include('template/start', {asset: asset}) %>
|
||||
|
||||
<tr>
|
||||
<td valign="middle" class="hero" style="padding: .25rem 0 .75rem 0">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="text" style="padding: 1.5rem 1rem; text-align: left; background-color: #fff; margin: 0 1.5rem; border: 1px solid #e4e4e4; border-top: 4px solid #e52920;">
|
||||
<h4 style="font-size: 14x; color: #212B36">Halo <%= client_name %>,</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Kamu telah membuat order pada tanggal <%= trx_at %> dengan kriteria berikut:
|
||||
</h4>
|
||||
<table style="font-size: 14x; color: #212B36">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Order_Code</th>
|
||||
<td><%= trx_code %></td>
|
||||
</tr>
|
||||
<% if(client_prefer_type_truck !== ''){ %>
|
||||
<tr>
|
||||
<th>Preferred_Type</th>
|
||||
<td><%= client_prefer_type_truck %></td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<!-- start comment -->
|
||||
<% /* %>
|
||||
<% if(weight !== 0){ %>
|
||||
<tr>
|
||||
<th>Weight</th>
|
||||
<td><%= weight %> Kg</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% if(cbm !== 0){ %>
|
||||
<tr>
|
||||
<th>Volume</th>
|
||||
<td><%= cbm %> m³</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% if(koli !== 0){ %>
|
||||
<tr>
|
||||
<th>Koli</th>
|
||||
<td><%= koli %> Pcs</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% */ %>
|
||||
<!-- end comment -->
|
||||
<tr>
|
||||
<th>Pickup_Zone</th>
|
||||
<td>
|
||||
<b><%= pickup_zone_title %></b> <br>
|
||||
<%= pickup_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Pickup_At</th>
|
||||
<td>
|
||||
<b><%= pickup_at %></b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Drop_Zone</th>
|
||||
<td>
|
||||
<b><%= drop_zone_title %></b> <br>
|
||||
<%= drop_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Jika kamu tidak membuat transaksi ini, silahkan segera hubungi layanan pelanggan Bonceng.
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Butuh bantuan ? Segera hubungi layanan pelanggan Bonceng di <%= cs_phone %> atau email ke <%= cs_mail %>.
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Email ini dibuat secara otomatis. Mohon tidak mengirimkan balasan ke email ini.
|
||||
</h4>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<%- include('template/end', {asset: asset, cs_mail: cs_mail, cs_phone: cs_phone, cs_addr: cs_addr}) %>
|
||||
107
files/mails/clientOrdHaveBeenAccMail.ejs
Normal file
107
files/mails/clientOrdHaveBeenAccMail.ejs
Normal file
@ -0,0 +1,107 @@
|
||||
<%- include('template/start', {asset: asset}) %>
|
||||
|
||||
<tr>
|
||||
<td valign="middle" class="hero" style="padding: .25rem 0 .75rem 0">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="text" style="padding: 1.5rem 1rem; text-align: left; background-color: #fff; margin: 0 1.5rem; border: 1px solid #e4e4e4; border-top: 4px solid #e52920;">
|
||||
<h4 style="font-size: 14x; color: #212B36">Halo <%= client_name %>,</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Order kamu telah diterima pada tanggal <%= acc_at %> oleh <%= driver_name %>, dengan kriteria berikut:
|
||||
</h4>
|
||||
<table style="font-size: 14x; color: #212B36">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Order_Code</th>
|
||||
<td><%= trx_code %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Driver_Name</th>
|
||||
<td><%= driver_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Driver_Phone</th>
|
||||
<td><%= driver_phone %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Driver_Mail</th>
|
||||
<td><%= driver_mail %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Vendor_Name</th>
|
||||
<td><%= vendor_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Vendor_Phone</th>
|
||||
<td><%= vendor_phone %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Vendor_Mail</th>
|
||||
<td><%= vendor_mail %></td>
|
||||
</tr>
|
||||
<% if(client_prefer_type_truck !== ''){ %>
|
||||
<tr>
|
||||
<th>Preferred_Type</th>
|
||||
<td><%= client_prefer_type_truck %></td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<!-- start comment -->
|
||||
<% /* %>
|
||||
<% if(weight !== 0){ %>
|
||||
<tr>
|
||||
<th>Weight</th>
|
||||
<td><%= weight %> Kg</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% if(cbm !== 0){ %>
|
||||
<tr>
|
||||
<th>Volume</th>
|
||||
<td><%= cbm %> m³</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% if(koli !== 0){ %>
|
||||
<tr>
|
||||
<th>Koli</th>
|
||||
<td><%= koli %> Pcs</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% */ %>
|
||||
<!-- end comment -->
|
||||
<tr>
|
||||
<th>Pickup_Zone</th>
|
||||
<td>
|
||||
<b><%= pickup_zone_title %></b> <br>
|
||||
<%= pickup_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Pickup_At</th>
|
||||
<td>
|
||||
<b><%= pickup_at %></b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Drop_Zone</th>
|
||||
<td>
|
||||
<b><%= drop_zone_title %></b> <br>
|
||||
<%= drop_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Butuh bantuan ? Segera hubungi layanan pelanggan Bonceng di <%= cs_phone %> atau email ke <%= cs_mail %>.
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Email ini dibuat secara otomatis. Mohon tidak mengirimkan balasan ke email ini.
|
||||
</h4>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<%- include('template/end', {asset: asset, cs_mail: cs_mail, cs_phone: cs_phone, cs_addr: cs_addr}) %>
|
||||
80
files/mails/driverGetOrderMail.ejs
Normal file
80
files/mails/driverGetOrderMail.ejs
Normal file
@ -0,0 +1,80 @@
|
||||
<%- include('template/start', {asset: asset}) %>
|
||||
|
||||
<tr>
|
||||
<td valign="middle" class="hero" style="padding: .25rem 0 .75rem 0">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="text" style="padding: 1.5rem 1rem; text-align: left; background-color: #fff; margin: 0 1.5rem; border: 1px solid #e4e4e4; border-top: 4px solid #e52920;">
|
||||
<h4 style="font-size: 14x; color: #212B36">Halo <%= driver_name %>,</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Kamu telah mendapatkan order pada tanggal <%= acc_at %>, dengan kriteria berikut:
|
||||
</h4>
|
||||
<table style="font-size: 14x; color: #212B36">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Order_Code</th>
|
||||
<td><%= trx_code %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Pickup_Zone</th>
|
||||
<td>
|
||||
<b><%= pickup_zone_title %></b> <br>
|
||||
<%= pickup_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Pickup_At</th>
|
||||
<td>
|
||||
<b><%= pickup_at %></b>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- start comment -->
|
||||
<% /* %>
|
||||
<% if(weight !== 0){ %>
|
||||
<tr>
|
||||
<th>Weight</th>
|
||||
<td><%= weight %> Kg</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% if(cbm !== 0){ %>
|
||||
<tr>
|
||||
<th>Volume</th>
|
||||
<td><%= cbm %> m³</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% if(koli !== 0){ %>
|
||||
<tr>
|
||||
<th>Koli</th>
|
||||
<td><%= koli %> Pcs</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% */ %>
|
||||
<!-- end comment -->
|
||||
<tr>
|
||||
<th>Drop_Zone</th>
|
||||
<td>
|
||||
<b><%= drop_zone_title %></b> <br>
|
||||
<%= drop_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Silahkan segera temui vendor untuk mendapatkan Delivery Order dan pickup ke lokasi tujuan
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Butuh bantuan ? Segera hubungi layanan pelanggan Bonceng di <%= cs_phone %> atau email ke <%= cs_mail %>.
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Email ini dibuat secara otomatis. Mohon tidak mengirimkan balasan ke email ini.
|
||||
</h4>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<%- include('template/end', {asset: asset, cs_mail: cs_mail, cs_phone: cs_phone, cs_addr: cs_addr}) %>
|
||||
46
files/mails/financeInfoDanaAmount.ejs
Normal file
46
files/mails/financeInfoDanaAmount.ejs
Normal file
@ -0,0 +1,46 @@
|
||||
<%- include('template/start', {asset: asset}) %>
|
||||
|
||||
<tr>
|
||||
<td valign="middle" class="hero" style="padding: .25rem 0 .75rem 0">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="text" style="padding: 1.5rem 1rem; text-align: left; background-color: #fff; margin: 0 1.5rem; border: 1px solid #e4e4e4; border-top: 4px solid #e52920;">
|
||||
<h4 style="font-size: 14x; color: #212B36">Halo <%= admin_name %>,</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Tidak bisa melakukan transfer uang saku, dikarenakan dana saat ini tidak mencukupi untuk melakukan transfer.
|
||||
</h4>
|
||||
<table style="font-size: 14x; color: #212B36">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Dana Saat Ini</th>
|
||||
<td><%= dana_current %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Minimum Saldo Dana</th>
|
||||
<td><%= dana_minimum %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Jumlah Transfer Uang Saku</th>
|
||||
<td><%= pocket_total %></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Segera tambah saldo dana.
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Butuh bantuan ? Segera hubungi layanan pelanggan Bonceng di <%= cs_phone %> atau email ke <%= cs_mail %>.
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Email ini dibuat secara otomatis. Mohon tidak mengirimkan balasan ke email ini.
|
||||
</h4>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<%- include('template/end', {asset: asset, cs_mail: cs_mail, cs_phone: cs_phone, cs_addr: cs_addr}) %>
|
||||
88
files/mails/financeInfoTfPocket.ejs
Normal file
88
files/mails/financeInfoTfPocket.ejs
Normal file
@ -0,0 +1,88 @@
|
||||
<%- include('template/start', {asset: asset}) %>
|
||||
|
||||
<tr>
|
||||
<td valign="middle" class="hero" style="padding: .25rem 0 .75rem 0">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="text" style="padding: 1.5rem 1rem; text-align: left; background-color: #fff; margin: 0 1.5rem; border: 1px solid #e4e4e4; border-top: 4px solid #e52920;">
|
||||
<h4 style="font-size: 14x; color: #212B36">Halo <%= admin_name %>,</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Transfer uang saku kepada driver <% drv_name %>, dengan rincian:
|
||||
</h4>
|
||||
<table style="font-size: 14x; color: #212B36">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th style="white-space: nowrap;">Order Code</th>
|
||||
<td><%= trx_code %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th style="white-space: nowrap; vertical-align: top;">Pickup Zone</th>
|
||||
<td style="vertical-align: top;">
|
||||
<b><%= pickup_zone_title %></b> <br>
|
||||
<%= pickup_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
<% if(drop_zone_title !== ''){ %>
|
||||
<tr>
|
||||
<th style="white-space: nowrap; vertical-align: top;">Drop Zone</th>
|
||||
<td style="vertical-align: top;">
|
||||
<b><%= drop_zone_title %></b> <br>
|
||||
<%= drop_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Nominal</th>
|
||||
<td><%= pocket_total %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Bank</th>
|
||||
<td><%= bank_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Kode</th>
|
||||
<td><%= bank_code %></td>
|
||||
</tr>
|
||||
<% if(bank_branch_name !== ''){ %>
|
||||
<tr>
|
||||
<th>Cabang</th>
|
||||
<td><%= bank_branch_name %></td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<tr>
|
||||
<th style="white-space: nowrap;">Pemilik Rekening</th>
|
||||
<td><%= bank_acc_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th style="white-space: nowrap;">No Rekening</th>
|
||||
<td><%= bank_acc_no %></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Segera lakukan pembayaran
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Butuh bantuan ? Segera hubungi layanan pelanggan Bonceng di <%= cs_phone %> atau email ke <%= cs_mail %>.
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Email ini dibuat secara otomatis. Mohon tidak mengirimkan balasan ke email ini.
|
||||
</h4>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<%- include('template/end', {asset: asset, cs_mail: cs_mail, cs_phone: cs_phone, cs_addr: cs_addr}) %>
|
||||
48
files/mails/template/end.ejs
Normal file
48
files/mails/template/end.ejs
Normal file
@ -0,0 +1,48 @@
|
||||
<!-- end tr -->
|
||||
<!-- 1 Column Text + Button : END -->
|
||||
<tr>
|
||||
<td class="td-help">
|
||||
<h4 class="text-help">
|
||||
Butuh bantuan? hubungi kami:
|
||||
<a href="tel::<%= cs_phone %>"><%= cs_phone %></a> <br>
|
||||
<a href="mailto:<%= cs_mail %>"><%= cs_mail %></a>
|
||||
</h4>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" class="tbl-footer">
|
||||
<tr>
|
||||
<td valign="middle" class="bg_muted footer email-section">
|
||||
<table>
|
||||
<tr>
|
||||
<td valign="center" style="">
|
||||
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td class="td-footer">
|
||||
<img src="<%= asset %>/img/logo_footer.png" width="140px" alt="">
|
||||
<p class="text-address">
|
||||
<%= cs_addr %>
|
||||
</p>
|
||||
<a href="https://www.instagram.com/bonceng.id/">
|
||||
<img src="<%= asset %>/img/instagram_ico.png" width="32px" alt="">
|
||||
</a>
|
||||
<a href="https://twitter.com/Boncengid">
|
||||
<img src="<%= asset %>/img/twitter_ico.png" width="32px" alt="" style="margin: 0 1.25rem">
|
||||
</a>
|
||||
<a href="https://www.facebook.com/Boncengid-439789016427052/">
|
||||
<img src="<%= asset %>/img/facebook_ico.png" width="32px" alt="">
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</center>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
356
files/mails/template/start.ejs
Normal file
356
files/mails/template/start.ejs
Normal file
@ -0,0 +1,356 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"
|
||||
xmlns:o="urn:schemas-microsoft-com:office:office">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="x-apple-disable-message-reformatting">
|
||||
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'PoppinsRegular';
|
||||
src: url('<%= asset %>/font/Poppins.ttf');
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
font-family: 'PoppinsRegular' !important;
|
||||
margin: 0 auto !important;
|
||||
padding: 0 !important;
|
||||
height: 100% !important;
|
||||
width: 100% !important;
|
||||
background: #f1f1f1 !important;
|
||||
}
|
||||
|
||||
* {
|
||||
-ms-text-size-adjust: 100%;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
div[style*="margin: 16px 0"] {
|
||||
margin: 0 !important;
|
||||
}
|
||||
|
||||
table,
|
||||
td {
|
||||
mso-table-lspace: 0pt !important;
|
||||
mso-table-rspace: 0pt !important;
|
||||
}
|
||||
|
||||
table {
|
||||
border-spacing: 0 !important;
|
||||
border-collapse: collapse !important;
|
||||
table-layout: fixed !important;
|
||||
margin: 0 auto !important;
|
||||
}
|
||||
|
||||
img {
|
||||
-ms-interpolation-mode: bicubic;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none !important;
|
||||
}
|
||||
|
||||
*[x-apple-data-detectors],
|
||||
|
||||
.unstyle-auto-detected-links *,
|
||||
.aBn {
|
||||
border-bottom: 0 !important;
|
||||
cursor: default !important;
|
||||
color: inherit !important;
|
||||
text-decoration: none !important;
|
||||
font-size: inherit !important;
|
||||
font-family: inherit !important;
|
||||
font-weight: inherit !important;
|
||||
line-height: inherit !important;
|
||||
}
|
||||
|
||||
.a6S {
|
||||
display: none !important;
|
||||
opacity: 0.01 !important;
|
||||
}
|
||||
|
||||
.im {
|
||||
color: inherit !important;
|
||||
}
|
||||
|
||||
/* CUSTOMAN */
|
||||
.text-address {
|
||||
margin: .25rem 0 1rem 0 !important;
|
||||
font-size: 13px !important;
|
||||
}
|
||||
|
||||
.text-help {
|
||||
margin-bottom: .85rem !important;
|
||||
font-size: 11px !important;
|
||||
color: #6d7d89 !important;
|
||||
}
|
||||
|
||||
.td-footer {
|
||||
text-align: center !important;
|
||||
}
|
||||
|
||||
.td-help {
|
||||
text-align: center !important;
|
||||
/* padding-right: 1.5rem !important; */
|
||||
}
|
||||
|
||||
.tbl-footer {
|
||||
margin: auto !important;
|
||||
}
|
||||
|
||||
img.g-img+div {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
@media only screen and (min-device-width: 320px) and (max-device-width: 374px) {
|
||||
u~div .email-container {
|
||||
min-width: 320px !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (min-device-width: 375px) and (max-device-width: 413px) {
|
||||
u~div .email-container {
|
||||
min-width: 375px !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (min-device-width: 414px) {
|
||||
u~div .email-container {
|
||||
min-width: 414px !important;
|
||||
}
|
||||
}
|
||||
|
||||
.primary {
|
||||
background: #E52920 !important;
|
||||
}
|
||||
|
||||
.bg_white {
|
||||
background: #ffffff !important;
|
||||
}
|
||||
|
||||
.bg_light {
|
||||
background: #fafafa !important;
|
||||
}
|
||||
|
||||
.bg_muted {
|
||||
background: #ededed !important;
|
||||
}
|
||||
|
||||
.bg_black {
|
||||
background: #000000 !important;
|
||||
}
|
||||
|
||||
.bg_dark {
|
||||
background: rgba(0, 0, 0, .8) !important;
|
||||
}
|
||||
|
||||
.email-section {
|
||||
padding: 1.5em !important;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 10px 15px !important;
|
||||
display: inline-block !important;
|
||||
}
|
||||
|
||||
.btn.btn-primary {
|
||||
border-radius: 5px !important;
|
||||
background: #E52920 !important;
|
||||
color: #ffffff !important;
|
||||
}
|
||||
|
||||
.btn.btn-white {
|
||||
border-radius: 5px !important;
|
||||
background: #ffffff !important;
|
||||
color: #000000 !important;
|
||||
}
|
||||
|
||||
.btn.btn-white-outline {
|
||||
border-radius: 5px !important;
|
||||
background: transparent !important;
|
||||
border: 1px solid #fff !important;
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
.btn.btn-black-outline {
|
||||
border-radius: 0px !important;
|
||||
background: transparent !important;
|
||||
border: 2px solid #000 !important;
|
||||
color: #000 !important;
|
||||
font-weight: 700 !important;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
font-family: 'PoppinsRegular', sans-serif !important;
|
||||
color: #212B36 !important;
|
||||
margin-top: 0 !important;
|
||||
font-weight: 400 !important;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'PoppinsRegular', sans-serif !important;
|
||||
font-weight: 400 !important;
|
||||
font-size: 15px !important;
|
||||
line-height: 1.8 !important;
|
||||
color: rgba(0, 0, 0, .4) !important;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #E52920 !important;
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
margin: 0 !important;
|
||||
}
|
||||
|
||||
.logo h1 a {
|
||||
color: #E52920 !important;
|
||||
font-size: 24px !important;
|
||||
font-weight: 700 !important;
|
||||
font-family: 'PoppinsRegular', sans-serif !important;
|
||||
}
|
||||
|
||||
.hero {
|
||||
position: relative !important;
|
||||
z-index: 0 !important;
|
||||
}
|
||||
|
||||
.hero .text {
|
||||
color: rgba(0, 0, 0, .3) !important;
|
||||
}
|
||||
|
||||
.hero .text h2 {
|
||||
color: #000 !important;
|
||||
font-size: 40px !important;
|
||||
margin-bottom: 0 !important;
|
||||
font-weight: 400 !important;
|
||||
line-height: 1.4 !important;
|
||||
}
|
||||
|
||||
.hero .text h3 {
|
||||
font-size: 24px !important;
|
||||
font-weight: 300 !important;
|
||||
}
|
||||
|
||||
.hero .text h2 span {
|
||||
font-weight: 600 !important;
|
||||
color: #E52920 !important;
|
||||
}
|
||||
|
||||
.heading-section {}
|
||||
|
||||
.heading-section h2 {
|
||||
color: #000000 !important;
|
||||
font-size: 28px !important;
|
||||
margin-top: 0 !important;
|
||||
line-height: 1.4 !important;
|
||||
font-weight: 400 !important;
|
||||
}
|
||||
|
||||
.heading-section .subheading {
|
||||
margin-bottom: 20px !important;
|
||||
display: inline-block !important;
|
||||
font-size: 13px !important;
|
||||
text-transform: uppercase !important;
|
||||
letter-spacing: 2px !important;
|
||||
color: rgba(0, 0, 0, .4) !important;
|
||||
position: relative !important;
|
||||
}
|
||||
|
||||
.heading-section .subheading::after {
|
||||
position: absolute !important;
|
||||
left: 0 !important;
|
||||
right: 0 !important;
|
||||
bottom: -10px !important;
|
||||
content: '' !important;
|
||||
width: 100% !important;
|
||||
height: 2px !important;
|
||||
background: #E52920 !important;
|
||||
margin: 0 auto !important;
|
||||
}
|
||||
|
||||
.heading-section-white {
|
||||
color: rgba(255, 255, 255, .8) !important;
|
||||
}
|
||||
|
||||
.heading-section-white h2 {
|
||||
/* font-family: line-height: 1 !important; */
|
||||
padding-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.heading-section-white h2 {
|
||||
color: #ffffff !important;
|
||||
}
|
||||
|
||||
.heading-section-white .subheading {
|
||||
margin-bottom: 0 !important;
|
||||
display: inline-block !important;
|
||||
font-size: 13px !important;
|
||||
text-transform: uppercase !important;
|
||||
letter-spacing: 2px !important;
|
||||
color: rgba(255, 255, 255, .4) !important;
|
||||
}
|
||||
|
||||
ul.social {
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
ul.social li {
|
||||
display: inline-block !important;
|
||||
margin-right: 10px !important;
|
||||
}
|
||||
|
||||
.footer {
|
||||
/* border-top: 1px solid rgba(0, 0, 0, .05) !important; */
|
||||
color: rgba(0, 0, 0, .5) !important;
|
||||
}
|
||||
|
||||
.footer .heading {
|
||||
color: #000 !important;
|
||||
font-size: 20px !important;
|
||||
}
|
||||
|
||||
.footer ul {
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
.footer ul li {
|
||||
list-style: none !important;
|
||||
margin-bottom: 10px !important;
|
||||
}
|
||||
|
||||
.footer ul li a {
|
||||
color: rgba(0, 0, 0, 1) !important;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 500px) {}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body width="100%" style="margin: 0; padding: 0 !important; mso-line-height-rule: exactly; background-color: #f1f1f1;">
|
||||
<center style="width: 100%; background-color: #f1f1f1;">
|
||||
<div style="max-width: 710px; margin: 0 auto;" class="email-container">
|
||||
<!-- BEGIN BODY -->
|
||||
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%"
|
||||
style="margin: auto; background-color: #f8f8f8">
|
||||
<tr>
|
||||
<td valign="top" class="" style=" padding: 1em 2.5em 0 2.5em;">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td class="logo" style="text-align: center;">
|
||||
<img src="<%= asset %>/img/logo-red-brandnew.png" width="140px" alt="">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
95
files/mails/vdrAccOrderMail.ejs
Normal file
95
files/mails/vdrAccOrderMail.ejs
Normal file
@ -0,0 +1,95 @@
|
||||
<%- include('template/start', {asset: asset}) %>
|
||||
|
||||
<tr>
|
||||
<td valign="middle" class="hero" style="padding: .25rem 0 .75rem 0">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="text" style="padding: 1.5rem 1rem; text-align: left; background-color: #fff; margin: 0 1.5rem; border: 1px solid #e4e4e4; border-top: 4px solid #e52920;">
|
||||
<h4 style="font-size: 14x; color: #212B36">Halo <%= vendor_name %>,</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Kamu telah menerima orderan pada tanggal <%= acc_at %>, dengan kriteria berikut:
|
||||
</h4>
|
||||
<table style="font-size: 14x; color: #212B36">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Order_Code</th>
|
||||
<td><%= trx_code %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client_Name</th>
|
||||
<td><%= client_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client_Phone</th>
|
||||
<td><%= client_phone %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client_Mail</th>
|
||||
<td><%= client_mail %></td>
|
||||
</tr>
|
||||
<% if(client_prefer_type_truck !== ''){ %>
|
||||
<tr>
|
||||
<th>Preferred_Type</th>
|
||||
<td><%= client_prefer_type_truck %></td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<!-- start comment -->
|
||||
<% /* %>
|
||||
<% if(weight !== 0){ %>
|
||||
<tr>
|
||||
<th>Weight</th>
|
||||
<td><%= weight %> Kg</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% if(cbm !== 0){ %>
|
||||
<tr>
|
||||
<th>Volume</th>
|
||||
<td><%= cbm %> m³</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% if(koli !== 0){ %>
|
||||
<tr>
|
||||
<th>Koli</th>
|
||||
<td><%= koli %> Pcs</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% */ %>
|
||||
<!-- end comment -->
|
||||
<tr>
|
||||
<th>Pickup_Zone</th>
|
||||
<td>
|
||||
<b><%= pickup_zone_title %></b> <br>
|
||||
<%= pickup_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Pickup_At</th>
|
||||
<td>
|
||||
<b><%= pickup_at %></b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Drop_Zone</th>
|
||||
<td>
|
||||
<b><%= drop_zone_title %></b> <br>
|
||||
<%= drop_zone_addr %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Butuh bantuan ? Segera hubungi layanan pelanggan Bonceng di <%= cs_phone %> atau email ke <%= cs_mail %>.
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Email ini dibuat secara otomatis. Mohon tidak mengirimkan balasan ke email ini.
|
||||
</h4>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<%- include('template/end', {asset: asset, cs_mail: cs_mail, cs_phone: cs_phone, cs_addr: cs_addr}) %>
|
||||
52
files/mails/zoningMail.ejs
Normal file
52
files/mails/zoningMail.ejs
Normal file
@ -0,0 +1,52 @@
|
||||
<%- include('template/start', {asset: asset}) %>
|
||||
|
||||
<tr>
|
||||
<td valign="middle" class="hero" style="padding: .25rem 0 .75rem 0">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="text"
|
||||
style="padding: 1.5rem 1rem; text-align: left; background-color: #fff; margin: 0 1.5rem; border: 1px solid #e4e4e4; border-top: 4px solid #e52920;">
|
||||
<h4 style="font-size: 14x; color: #212B36">Halo <%= pic_name %>,</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Vehicle <%= v_nopol %> with driver <%= da_name %> (<%= da_phone %>) has entering zone:
|
||||
</h4>
|
||||
<table style="font-size: 14x; color: #212B36">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Zone</th>
|
||||
<td><%= z_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Type</th>
|
||||
<td><%= z_type_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Workflow Type</th>
|
||||
<td><%= z_workflow_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Ship-To Code</th>
|
||||
<td><%= shiptocode %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Address</th>
|
||||
<td><%= z_fulladdress %></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Butuh bantuan ? Segera hubungi layanan pelanggan Bonceng di <%= cs_phone %> atau email ke <%= cs_mail %>.
|
||||
</h4>
|
||||
<h4 style="font-size: 14x; color: #212B36">
|
||||
Email ini dibuat secara otomatis. Mohon tidak mengirimkan balasan ke email ini.
|
||||
</h4>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<%- include('template/end', {asset: asset, cs_mail: cs_mail, cs_phone: cs_phone, cs_addr: cs_addr}) %>
|
||||
BIN
files/public/OpenSans-B9K8.ttf
Normal file
BIN
files/public/OpenSans-B9K8.ttf
Normal file
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 72 KiB |
99
files/public/OpenSans-B9K8.ttf_neon_100/neon_100.fnt
Normal file
99
files/public/OpenSans-B9K8.ttf_neon_100/neon_100.fnt
Normal file
@ -0,0 +1,99 @@
|
||||
info face="Open Sans" size=-100 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=0 aa=1 padding=0,0,0,0 spacing=0,0 outline=0
|
||||
common lineHeight=136 base=107 scaleW=1024 scaleH=512 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
|
||||
page id=0 file="NVCrVnY_km5eldKtXvghZGtF.ttf_0.png"
|
||||
chars count=95
|
||||
char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=26 page=0 chnl=15
|
||||
char id=33 x=551 y=144 width=12 height=73 xoffset=7 yoffset=35 xadvance=27 page=0 chnl=15
|
||||
char id=34 x=217 y=353 width=28 height=26 xoffset=6 yoffset=35 xadvance=40 page=0 chnl=15
|
||||
char id=35 x=91 y=0 width=60 height=72 xoffset=2 yoffset=35 xadvance=65 page=0 chnl=15
|
||||
char id=36 x=299 y=127 width=45 height=83 xoffset=6 yoffset=30 xadvance=57 page=0 chnl=15
|
||||
char id=37 x=0 y=243 width=72 height=74 xoffset=5 yoffset=34 xadvance=82 page=0 chnl=15
|
||||
char id=38 x=78 y=72 width=68 height=74 xoffset=6 yoffset=34 xadvance=74 page=0 chnl=15
|
||||
char id=39 x=245 y=351 width=10 height=26 xoffset=6 yoffset=35 xadvance=22 page=0 chnl=15
|
||||
char id=40 x=524 y=290 width=23 height=88 xoffset=4 yoffset=35 xadvance=30 page=0 chnl=15
|
||||
char id=41 x=500 y=297 width=24 height=88 xoffset=2 yoffset=35 xadvance=29 page=0 chnl=15
|
||||
char id=42 x=50 y=464 width=47 height=46 xoffset=4 yoffset=30 xadvance=55 page=0 chnl=15
|
||||
char id=43 x=97 y=462 width=47 height=49 xoffset=5 yoffset=47 xadvance=57 page=0 chnl=15
|
||||
char id=44 x=72 y=292 width=15 height=25 xoffset=3 yoffset=95 xadvance=25 page=0 chnl=15
|
||||
char id=45 x=123 y=146 width=24 height=7 xoffset=4 yoffset=77 xadvance=32 page=0 chnl=15
|
||||
char id=46 x=113 y=225 width=12 height=13 xoffset=7 yoffset=95 xadvance=26 page=0 chnl=15
|
||||
char id=47 x=498 y=146 width=36 height=72 xoffset=0 yoffset=35 xadvance=37 page=0 chnl=15
|
||||
char id=48 x=285 y=428 width=48 height=74 xoffset=5 yoffset=34 xadvance=57 page=0 chnl=15
|
||||
char id=49 x=504 y=218 width=27 height=72 xoffset=8 yoffset=35 xadvance=57 page=0 chnl=15
|
||||
char id=50 x=380 y=414 width=47 height=73 xoffset=5 yoffset=34 xadvance=57 page=0 chnl=15
|
||||
char id=51 x=372 y=266 width=47 height=74 xoffset=5 yoffset=34 xadvance=57 page=0 chnl=15
|
||||
char id=52 x=175 y=380 width=53 height=73 xoffset=2 yoffset=34 xadvance=57 page=0 chnl=15
|
||||
char id=53 x=422 y=338 width=46 height=73 xoffset=6 yoffset=35 xadvance=57 page=0 chnl=15
|
||||
char id=54 x=391 y=126 width=47 height=74 xoffset=6 yoffset=34 xadvance=57 page=0 chnl=15
|
||||
char id=55 x=327 y=346 width=48 height=73 xoffset=5 yoffset=34 xadvance=57 page=0 chnl=15
|
||||
char id=56 x=333 y=419 width=47 height=74 xoffset=5 yoffset=34 xadvance=57 page=0 chnl=15
|
||||
char id=57 x=375 y=340 width=47 height=74 xoffset=5 yoffset=34 xadvance=57 page=0 chnl=15
|
||||
char id=58 x=568 y=68 width=12 height=57 xoffset=7 yoffset=51 xadvance=26 page=0 chnl=15
|
||||
char id=59 x=534 y=144 width=17 height=68 xoffset=2 yoffset=52 xadvance=27 page=0 chnl=15
|
||||
char id=60 x=144 y=461 width=47 height=51 xoffset=5 yoffset=45 xadvance=57 page=0 chnl=15
|
||||
char id=61 x=172 y=353 width=45 height=27 xoffset=6 yoffset=58 xadvance=57 page=0 chnl=15
|
||||
char id=62 x=294 y=216 width=47 height=51 xoffset=5 yoffset=45 xadvance=57 page=0 chnl=15
|
||||
char id=63 x=465 y=0 width=40 height=74 xoffset=1 yoffset=34 xadvance=44 page=0 chnl=15
|
||||
char id=64 x=0 y=72 width=78 height=81 xoffset=6 yoffset=35 xadvance=90 page=0 chnl=15
|
||||
char id=65 x=0 y=317 width=64 height=73 xoffset=0 yoffset=34 xadvance=63 page=0 chnl=15
|
||||
char id=66 x=321 y=55 width=50 height=72 xoffset=10 yoffset=35 xadvance=65 page=0 chnl=15
|
||||
char id=67 x=172 y=279 width=54 height=74 xoffset=6 yoffset=34 xadvance=63 page=0 chnl=15
|
||||
char id=68 x=64 y=317 width=57 height=72 xoffset=10 yoffset=35 xadvance=73 page=0 chnl=15
|
||||
char id=69 x=483 y=74 width=40 height=72 xoffset=10 yoffset=35 xadvance=56 page=0 chnl=15
|
||||
char id=70 x=505 y=0 width=40 height=72 xoffset=10 yoffset=35 xadvance=52 page=0 chnl=15
|
||||
char id=71 x=0 y=390 width=60 height=74 xoffset=6 yoffset=34 xadvance=73 page=0 chnl=15
|
||||
char id=72 x=244 y=144 width=55 height=72 xoffset=10 yoffset=35 xadvance=74 page=0 chnl=15
|
||||
char id=73 x=553 y=438 width=9 height=72 xoffset=10 yoffset=35 xadvance=28 page=0 chnl=15
|
||||
char id=74 x=503 y=385 width=26 height=91 xoffset=-8 yoffset=35 xadvance=27 page=0 chnl=15
|
||||
char id=75 x=228 y=379 width=52 height=72 xoffset=10 yoffset=35 xadvance=62 page=0 chnl=15
|
||||
char id=76 x=464 y=225 width=40 height=72 xoffset=10 yoffset=35 xadvance=52 page=0 chnl=15
|
||||
char id=77 x=66 y=153 width=71 height=72 xoffset=10 yoffset=35 xadvance=91 page=0 chnl=15
|
||||
char id=78 x=137 y=153 width=56 height=72 xoffset=10 yoffset=35 xadvance=76 page=0 chnl=15
|
||||
char id=79 x=146 y=72 width=66 height=74 xoffset=6 yoffset=34 xadvance=78 page=0 chnl=15
|
||||
char id=80 x=438 y=74 width=45 height=73 xoffset=10 yoffset=35 xadvance=60 page=0 chnl=15
|
||||
char id=81 x=0 y=153 width=66 height=90 xoffset=6 yoffset=34 xadvance=78 page=0 chnl=15
|
||||
char id=82 x=226 y=279 width=51 height=72 xoffset=10 yoffset=35 xadvance=62 page=0 chnl=15
|
||||
char id=83 x=420 y=0 width=45 height=74 xoffset=5 yoffset=34 xadvance=55 page=0 chnl=15
|
||||
char id=84 x=267 y=55 width=54 height=72 xoffset=1 yoffset=35 xadvance=56 page=0 chnl=15
|
||||
char id=85 x=212 y=71 width=55 height=73 xoffset=9 yoffset=35 xadvance=72 page=0 chnl=15
|
||||
char id=86 x=151 y=0 width=60 height=72 xoffset=0 yoffset=35 xadvance=60 page=0 chnl=15
|
||||
char id=87 x=0 y=0 width=91 height=72 xoffset=1 yoffset=35 xadvance=93 page=0 chnl=15
|
||||
char id=88 x=60 y=390 width=58 height=72 xoffset=0 yoffset=35 xadvance=58 page=0 chnl=15
|
||||
char id=89 x=118 y=389 width=57 height=72 xoffset=0 yoffset=35 xadvance=56 page=0 chnl=15
|
||||
char id=90 x=371 y=54 width=49 height=72 xoffset=4 yoffset=35 xadvance=57 page=0 chnl=15
|
||||
char id=91 x=547 y=273 width=23 height=88 xoffset=8 yoffset=35 xadvance=33 page=0 chnl=15
|
||||
char id=92 x=523 y=72 width=35 height=72 xoffset=1 yoffset=35 xadvance=37 page=0 chnl=15
|
||||
char id=93 x=563 y=142 width=23 height=88 xoffset=2 yoffset=35 xadvance=33 page=0 chnl=15
|
||||
char id=94 x=0 y=464 width=50 height=46 xoffset=2 yoffset=34 xadvance=54 page=0 chnl=15
|
||||
char id=95 x=78 y=146 width=45 height=7 xoffset=0 yoffset=116 xadvance=45 page=0 chnl=15
|
||||
char id=96 x=211 y=55 width=19 height=16 xoffset=19 yoffset=30 xadvance=57 page=0 chnl=15
|
||||
char id=97 x=341 y=210 width=43 height=56 xoffset=5 yoffset=52 xadvance=56 page=0 chnl=15
|
||||
char id=98 x=344 y=127 width=47 height=78 xoffset=9 yoffset=30 xadvance=62 page=0 chnl=15
|
||||
char id=99 x=384 y=205 width=39 height=56 xoffset=6 yoffset=52 xadvance=48 page=0 chnl=15
|
||||
char id=100 x=277 y=271 width=48 height=78 xoffset=6 yoffset=30 xadvance=62 page=0 chnl=15
|
||||
char id=101 x=240 y=451 width=45 height=56 xoffset=6 yoffset=52 xadvance=56 page=0 chnl=15
|
||||
char id=102 x=461 y=147 width=37 height=78 xoffset=1 yoffset=29 xadvance=33 page=0 chnl=15
|
||||
char id=103 x=121 y=292 width=51 height=79 xoffset=2 yoffset=52 xadvance=55 page=0 chnl=15
|
||||
char id=104 x=419 y=261 width=45 height=77 xoffset=9 yoffset=30 xadvance=62 page=0 chnl=15
|
||||
char id=105 x=558 y=68 width=10 height=74 xoffset=8 yoffset=33 xadvance=26 page=0 chnl=15
|
||||
char id=106 x=529 y=378 width=24 height=98 xoffset=-6 yoffset=33 xadvance=26 page=0 chnl=15
|
||||
char id=107 x=427 y=411 width=44 height=77 xoffset=9 yoffset=30 xadvance=53 page=0 chnl=15
|
||||
char id=108 x=553 y=361 width=9 height=77 xoffset=9 yoffset=30 xadvance=26 page=0 chnl=15
|
||||
char id=109 x=211 y=0 width=77 height=55 xoffset=9 yoffset=52 xadvance=94 page=0 chnl=15
|
||||
char id=110 x=288 y=0 width=45 height=55 xoffset=9 yoffset=52 xadvance=62 page=0 chnl=15
|
||||
char id=111 x=191 y=453 width=49 height=56 xoffset=6 yoffset=52 xadvance=61 page=0 chnl=15
|
||||
char id=112 x=280 y=349 width=47 height=79 xoffset=9 yoffset=52 xadvance=62 page=0 chnl=15
|
||||
char id=113 x=325 y=267 width=47 height=79 xoffset=6 yoffset=52 xadvance=62 page=0 chnl=15
|
||||
char id=114 x=531 y=218 width=32 height=55 xoffset=9 yoffset=52 xadvance=42 page=0 chnl=15
|
||||
char id=115 x=423 y=200 width=38 height=56 xoffset=5 yoffset=52 xadvance=48 page=0 chnl=15
|
||||
char id=116 x=545 y=0 width=32 height=68 xoffset=2 yoffset=40 xadvance=36 page=0 chnl=15
|
||||
char id=117 x=249 y=216 width=45 height=55 xoffset=8 yoffset=53 xadvance=62 page=0 chnl=15
|
||||
char id=118 x=148 y=225 width=51 height=54 xoffset=0 yoffset=53 xadvance=50 page=0 chnl=15
|
||||
char id=119 x=72 y=238 width=76 height=54 xoffset=1 yoffset=53 xadvance=78 page=0 chnl=15
|
||||
char id=120 x=199 y=225 width=50 height=54 xoffset=1 yoffset=53 xadvance=52 page=0 chnl=15
|
||||
char id=121 x=193 y=146 width=51 height=79 xoffset=0 yoffset=52 xadvance=50 page=0 chnl=15
|
||||
char id=122 x=333 y=0 width=39 height=54 xoffset=4 yoffset=53 xadvance=47 page=0 chnl=15
|
||||
char id=123 x=468 y=297 width=32 height=88 xoffset=3 yoffset=35 xadvance=38 page=0 chnl=15
|
||||
char id=124 x=580 y=0 width=7 height=101 xoffset=24 yoffset=30 xadvance=55 page=0 chnl=15
|
||||
char id=125 x=471 y=385 width=32 height=88 xoffset=4 yoffset=35 xadvance=38 page=0 chnl=15
|
||||
char id=126 x=66 y=225 width=47 height=13 xoffset=5 yoffset=65 xadvance=57 page=0 chnl=15
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 8.4 KiB |
99
files/public/OpenSans-B9K8.ttf_neon_16/neon_16.fnt
Normal file
99
files/public/OpenSans-B9K8.ttf_neon_16/neon_16.fnt
Normal file
@ -0,0 +1,99 @@
|
||||
info face="Open Sans" size=-16 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=0 aa=1 padding=0,0,0,0 spacing=0,0 outline=0
|
||||
common lineHeight=22 base=18 scaleW=128 scaleH=128 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
|
||||
page id=0 file="FWd0hhbQQsviQcgc8vksJ1t0.ttf_0.png"
|
||||
chars count=95
|
||||
char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=4 page=0 chnl=15
|
||||
char id=33 x=75 y=12 width=3 height=12 xoffset=0 yoffset=6 xadvance=3 page=0 chnl=15
|
||||
char id=34 x=28 y=123 width=5 height=4 xoffset=1 yoffset=6 xadvance=6 page=0 chnl=15
|
||||
char id=35 x=0 y=104 width=10 height=12 xoffset=1 yoffset=6 xadvance=12 page=0 chnl=15
|
||||
char id=36 x=0 y=90 width=9 height=14 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=37 x=12 y=14 width=13 height=12 xoffset=0 yoffset=6 xadvance=13 page=0 chnl=15
|
||||
char id=38 x=20 y=26 width=12 height=12 xoffset=0 yoffset=6 xadvance=11 page=0 chnl=15
|
||||
char id=39 x=27 y=38 width=2 height=4 xoffset=1 yoffset=6 xadvance=4 page=0 chnl=15
|
||||
char id=40 x=50 y=109 width=5 height=15 xoffset=0 yoffset=6 xadvance=5 page=0 chnl=15
|
||||
char id=41 x=56 y=81 width=5 height=15 xoffset=0 yoffset=6 xadvance=5 page=0 chnl=15
|
||||
char id=42 x=11 y=69 width=9 height=8 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=43 x=59 y=58 width=8 height=8 xoffset=1 yoffset=8 xadvance=10 page=0 chnl=15
|
||||
char id=44 x=33 y=123 width=3 height=4 xoffset=0 yoffset=16 xadvance=4 page=0 chnl=15
|
||||
char id=45 x=21 y=12 width=4 height=2 xoffset=1 yoffset=13 xadvance=6 page=0 chnl=15
|
||||
char id=46 x=40 y=123 width=3 height=3 xoffset=0 yoffset=15 xadvance=3 page=0 chnl=15
|
||||
char id=47 x=66 y=24 width=6 height=12 xoffset=0 yoffset=6 xadvance=6 page=0 chnl=15
|
||||
char id=48 x=21 y=57 width=9 height=12 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=49 x=69 y=12 width=6 height=12 xoffset=1 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=50 x=50 y=24 width=8 height=12 xoffset=1 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=51 x=25 y=43 width=9 height=12 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=52 x=54 y=12 width=8 height=12 xoffset=1 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=53 x=30 y=55 width=9 height=12 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=54 x=32 y=24 width=9 height=12 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=55 x=56 y=0 width=8 height=12 xoffset=1 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=56 x=36 y=12 width=9 height=12 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=57 x=38 y=0 width=9 height=12 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=58 x=63 y=95 width=3 height=9 xoffset=0 yoffset=9 xadvance=3 page=0 chnl=15
|
||||
char id=59 x=60 y=117 width=3 height=11 xoffset=0 yoffset=9 xadvance=3 page=0 chnl=15
|
||||
char id=60 x=56 y=48 width=8 height=10 xoffset=1 yoffset=7 xadvance=9 page=0 chnl=15
|
||||
char id=61 x=20 y=38 width=7 height=5 xoffset=1 yoffset=10 xadvance=9 page=0 chnl=15
|
||||
char id=62 x=60 y=36 width=8 height=10 xoffset=1 yoffset=7 xadvance=9 page=0 chnl=15
|
||||
char id=63 x=62 y=12 width=7 height=12 xoffset=0 yoffset=6 xadvance=7 page=0 chnl=15
|
||||
char id=64 x=0 y=0 width=14 height=14 xoffset=0 yoffset=6 xadvance=14 page=0 chnl=15
|
||||
char id=65 x=0 y=53 width=11 height=12 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15
|
||||
char id=66 x=0 y=116 width=10 height=12 xoffset=1 yoffset=6 xadvance=11 page=0 chnl=15
|
||||
char id=67 x=9 y=90 width=10 height=12 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15
|
||||
char id=68 x=25 y=12 width=11 height=12 xoffset=1 yoffset=6 xadvance=12 page=0 chnl=15
|
||||
char id=69 x=38 y=102 width=8 height=12 xoffset=1 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=70 x=42 y=60 width=8 height=12 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15
|
||||
char id=71 x=27 y=0 width=11 height=12 xoffset=0 yoffset=6 xadvance=11 page=0 chnl=15
|
||||
char id=72 x=10 y=77 width=10 height=12 xoffset=1 yoffset=6 xadvance=12 page=0 chnl=15
|
||||
char id=73 x=77 y=0 width=3 height=12 xoffset=1 yoffset=6 xadvance=5 page=0 chnl=15
|
||||
char id=74 x=15 y=29 width=5 height=16 xoffset=-1 yoffset=6 xadvance=5 page=0 chnl=15
|
||||
char id=75 x=34 y=36 width=9 height=12 xoffset=1 yoffset=6 xadvance=10 page=0 chnl=15
|
||||
char id=76 x=48 y=48 width=8 height=12 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15
|
||||
char id=77 x=14 y=0 width=13 height=12 xoffset=1 yoffset=6 xadvance=15 page=0 chnl=15
|
||||
char id=78 x=0 y=65 width=11 height=12 xoffset=1 yoffset=6 xadvance=13 page=0 chnl=15
|
||||
char id=79 x=0 y=41 width=12 height=12 xoffset=0 yoffset=6 xadvance=12 page=0 chnl=15
|
||||
char id=80 x=41 y=24 width=9 height=12 xoffset=1 yoffset=6 xadvance=10 page=0 chnl=15
|
||||
char id=81 x=0 y=14 width=12 height=15 xoffset=0 yoffset=6 xadvance=12 page=0 chnl=15
|
||||
char id=82 x=45 y=12 width=9 height=12 xoffset=1 yoffset=6 xadvance=10 page=0 chnl=15
|
||||
char id=83 x=47 y=0 width=9 height=12 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=84 x=29 y=87 width=9 height=12 xoffset=1 yoffset=6 xadvance=11 page=0 chnl=15
|
||||
char id=85 x=11 y=57 width=10 height=12 xoffset=1 yoffset=6 xadvance=12 page=0 chnl=15
|
||||
char id=86 x=15 y=45 width=10 height=12 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15
|
||||
char id=87 x=0 y=29 width=15 height=12 xoffset=0 yoffset=6 xadvance=15 page=0 chnl=15
|
||||
char id=88 x=10 y=102 width=10 height=12 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=89 x=19 y=89 width=10 height=12 xoffset=-1 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=90 x=52 y=36 width=8 height=12 xoffset=1 yoffset=6 xadvance=10 page=0 chnl=15
|
||||
char id=91 x=61 y=80 width=5 height=15 xoffset=1 yoffset=6 xadvance=6 page=0 chnl=15
|
||||
char id=92 x=71 y=0 width=6 height=12 xoffset=0 yoffset=6 xadvance=6 page=0 chnl=15
|
||||
char id=93 x=55 y=105 width=5 height=15 xoffset=0 yoffset=6 xadvance=5 page=0 chnl=15
|
||||
char id=94 x=54 y=97 width=9 height=8 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=95 x=14 y=12 width=7 height=2 xoffset=0 yoffset=19 xadvance=7 page=0 chnl=15
|
||||
char id=96 x=36 y=123 width=4 height=3 xoffset=3 yoffset=5 xadvance=9 page=0 chnl=15
|
||||
char id=97 x=30 y=78 width=9 height=9 xoffset=0 yoffset=9 xadvance=9 page=0 chnl=15
|
||||
char id=98 x=29 y=99 width=9 height=12 xoffset=1 yoffset=6 xadvance=10 page=0 chnl=15
|
||||
char id=99 x=64 y=46 width=7 height=9 xoffset=0 yoffset=9 xadvance=7 page=0 chnl=15
|
||||
char id=100 x=39 y=48 width=9 height=12 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=101 x=33 y=67 width=9 height=9 xoffset=0 yoffset=9 xadvance=9 page=0 chnl=15
|
||||
char id=102 x=64 y=0 width=7 height=12 xoffset=0 yoffset=6 xadvance=6 page=0 chnl=15
|
||||
char id=103 x=0 y=77 width=10 height=13 xoffset=0 yoffset=9 xadvance=10 page=0 chnl=15
|
||||
char id=104 x=43 y=36 width=9 height=12 xoffset=1 yoffset=6 xadvance=10 page=0 chnl=15
|
||||
char id=105 x=63 y=66 width=3 height=12 xoffset=1 yoffset=6 xadvance=4 page=0 chnl=15
|
||||
char id=106 x=51 y=81 width=5 height=16 xoffset=-1 yoffset=6 xadvance=4 page=0 chnl=15
|
||||
char id=107 x=58 y=24 width=8 height=12 xoffset=1 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=108 x=60 y=105 width=3 height=12 xoffset=1 yoffset=6 xadvance=4 page=0 chnl=15
|
||||
char id=109 x=28 y=114 width=13 height=9 xoffset=1 yoffset=9 xadvance=14 page=0 chnl=15
|
||||
char id=110 x=39 y=76 width=9 height=9 xoffset=1 yoffset=9 xadvance=10 page=0 chnl=15
|
||||
char id=111 x=20 y=78 width=10 height=9 xoffset=0 yoffset=9 xadvance=10 page=0 chnl=15
|
||||
char id=112 x=10 y=114 width=9 height=13 xoffset=1 yoffset=9 xadvance=10 page=0 chnl=15
|
||||
char id=113 x=19 y=114 width=9 height=13 xoffset=0 yoffset=9 xadvance=9 page=0 chnl=15
|
||||
char id=114 x=68 y=36 width=6 height=9 xoffset=1 yoffset=9 xadvance=7 page=0 chnl=15
|
||||
char id=115 x=46 y=100 width=8 height=9 xoffset=0 yoffset=9 xadvance=8 page=0 chnl=15
|
||||
char id=116 x=57 y=69 width=6 height=11 xoffset=0 yoffset=7 xadvance=6 page=0 chnl=15
|
||||
char id=117 x=41 y=114 width=9 height=9 xoffset=1 yoffset=9 xadvance=10 page=0 chnl=15
|
||||
char id=118 x=48 y=72 width=9 height=9 xoffset=0 yoffset=9 xadvance=8 page=0 chnl=15
|
||||
char id=119 x=20 y=69 width=13 height=9 xoffset=0 yoffset=9 xadvance=12 page=0 chnl=15
|
||||
char id=120 x=50 y=60 width=9 height=9 xoffset=0 yoffset=9 xadvance=8 page=0 chnl=15
|
||||
char id=121 x=20 y=101 width=9 height=13 xoffset=-1 yoffset=9 xadvance=8 page=0 chnl=15
|
||||
char id=122 x=72 y=24 width=6 height=9 xoffset=1 yoffset=9 xadvance=8 page=0 chnl=15
|
||||
char id=123 x=45 y=85 width=6 height=15 xoffset=0 yoffset=6 xadvance=6 page=0 chnl=15
|
||||
char id=124 x=12 y=41 width=3 height=16 xoffset=3 yoffset=6 xadvance=9 page=0 chnl=15
|
||||
char id=125 x=38 y=87 width=7 height=15 xoffset=0 yoffset=6 xadvance=6 page=0 chnl=15
|
||||
char id=126 x=12 y=26 width=8 height=3 xoffset=1 yoffset=11 xadvance=10 page=0 chnl=15
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
99
files/public/OpenSans-B9K8.ttf_neon_32/neon_32.fnt
Normal file
99
files/public/OpenSans-B9K8.ttf_neon_32/neon_32.fnt
Normal file
@ -0,0 +1,99 @@
|
||||
info face="Open Sans" size=-32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=0 aa=1 padding=0,0,0,0 spacing=0,0 outline=0
|
||||
common lineHeight=44 base=35 scaleW=256 scaleH=128 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
|
||||
page id=0 file="MlLA3aDGaXpxSgao3dSOGIYD.ttf_0.png"
|
||||
chars count=95
|
||||
char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=8 page=0 chnl=15
|
||||
char id=33 x=236 y=61 width=4 height=24 xoffset=2 yoffset=11 xadvance=8 page=0 chnl=15
|
||||
char id=34 x=59 y=72 width=9 height=9 xoffset=2 yoffset=11 xadvance=13 page=0 chnl=15
|
||||
char id=35 x=46 y=24 width=19 height=24 xoffset=1 yoffset=11 xadvance=21 page=0 chnl=15
|
||||
char id=36 x=102 y=98 width=15 height=27 xoffset=2 yoffset=10 xadvance=19 page=0 chnl=15
|
||||
char id=37 x=0 y=81 width=23 height=24 xoffset=2 yoffset=11 xadvance=27 page=0 chnl=15
|
||||
char id=38 x=23 y=81 width=22 height=24 xoffset=2 yoffset=11 xadvance=24 page=0 chnl=15
|
||||
char id=39 x=74 y=72 width=3 height=9 xoffset=2 yoffset=11 xadvance=7 page=0 chnl=15
|
||||
char id=40 x=238 y=32 width=8 height=29 xoffset=1 yoffset=11 xadvance=9 page=0 chnl=15
|
||||
char id=41 x=239 y=0 width=8 height=29 xoffset=0 yoffset=11 xadvance=9 page=0 chnl=15
|
||||
char id=42 x=212 y=54 width=16 height=15 xoffset=1 yoffset=10 xadvance=18 page=0 chnl=15
|
||||
char id=43 x=203 y=72 width=15 height=16 xoffset=2 yoffset=15 xadvance=19 page=0 chnl=15
|
||||
char id=44 x=68 y=72 width=6 height=8 xoffset=0 yoffset=31 xadvance=8 page=0 chnl=15
|
||||
char id=45 x=28 y=75 width=8 height=3 xoffset=1 yoffset=24 xadvance=10 page=0 chnl=15
|
||||
char id=46 x=36 y=75 width=4 height=4 xoffset=2 yoffset=31 xadvance=8 page=0 chnl=15
|
||||
char id=47 x=176 y=48 width=12 height=24 xoffset=0 yoffset=11 xadvance=12 page=0 chnl=15
|
||||
char id=48 x=121 y=0 width=15 height=24 xoffset=2 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=49 x=208 y=88 width=9 height=24 xoffset=3 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=50 x=133 y=48 width=15 height=24 xoffset=2 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=51 x=105 y=0 width=16 height=24 xoffset=1 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=52 x=88 y=0 width=17 height=24 xoffset=1 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=53 x=134 y=24 width=15 height=24 xoffset=2 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=54 x=136 y=0 width=15 height=24 xoffset=2 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=55 x=148 y=48 width=15 height=24 xoffset=1 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=56 x=149 y=24 width=15 height=24 xoffset=2 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=57 x=151 y=0 width=15 height=24 xoffset=2 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=58 x=228 y=80 width=4 height=18 xoffset=2 yoffset=17 xadvance=8 page=0 chnl=15
|
||||
char id=59 x=247 y=0 width=6 height=22 xoffset=0 yoffset=17 xadvance=8 page=0 chnl=15
|
||||
char id=60 x=188 y=77 width=15 height=18 xoffset=2 yoffset=14 xadvance=19 page=0 chnl=15
|
||||
char id=61 x=44 y=72 width=15 height=9 xoffset=2 yoffset=19 xadvance=19 page=0 chnl=15
|
||||
char id=62 x=189 y=18 width=15 height=18 xoffset=2 yoffset=14 xadvance=19 page=0 chnl=15
|
||||
char id=63 x=163 y=48 width=13 height=24 xoffset=0 yoffset=11 xadvance=14 page=0 chnl=15
|
||||
char id=64 x=0 y=24 width=25 height=27 xoffset=2 yoffset=11 xadvance=29 page=0 chnl=15
|
||||
char id=65 x=25 y=24 width=21 height=24 xoffset=0 yoffset=11 xadvance=20 page=0 chnl=15
|
||||
char id=66 x=117 y=48 width=16 height=24 xoffset=3 yoffset=11 xadvance=20 page=0 chnl=15
|
||||
char id=67 x=65 y=24 width=18 height=24 xoffset=2 yoffset=11 xadvance=20 page=0 chnl=15
|
||||
char id=68 x=70 y=0 width=18 height=24 xoffset=3 yoffset=11 xadvance=23 page=0 chnl=15
|
||||
char id=69 x=164 y=24 width=13 height=24 xoffset=3 yoffset=11 xadvance=17 page=0 chnl=15
|
||||
char id=70 x=166 y=0 width=13 height=24 xoffset=3 yoffset=11 xadvance=16 page=0 chnl=15
|
||||
char id=71 x=51 y=0 width=19 height=24 xoffset=2 yoffset=11 xadvance=23 page=0 chnl=15
|
||||
char id=72 x=64 y=81 width=18 height=24 xoffset=3 yoffset=11 xadvance=24 page=0 chnl=15
|
||||
char id=73 x=232 y=80 width=3 height=24 xoffset=3 yoffset=11 xadvance=9 page=0 chnl=15
|
||||
char id=74 x=199 y=95 width=9 height=30 xoffset=-3 yoffset=11 xadvance=9 page=0 chnl=15
|
||||
char id=75 x=83 y=48 width=17 height=24 xoffset=3 yoffset=11 xadvance=20 page=0 chnl=15
|
||||
char id=76 x=175 y=72 width=13 height=24 xoffset=3 yoffset=11 xadvance=16 page=0 chnl=15
|
||||
char id=77 x=21 y=51 width=23 height=24 xoffset=3 yoffset=11 xadvance=29 page=0 chnl=15
|
||||
char id=78 x=84 y=98 width=18 height=24 xoffset=3 yoffset=11 xadvance=24 page=0 chnl=15
|
||||
char id=79 x=30 y=0 width=21 height=24 xoffset=2 yoffset=11 xadvance=25 page=0 chnl=15
|
||||
char id=80 x=147 y=97 width=15 height=24 xoffset=3 yoffset=11 xadvance=19 page=0 chnl=15
|
||||
char id=81 x=0 y=51 width=21 height=30 xoffset=2 yoffset=11 xadvance=25 page=0 chnl=15
|
||||
char id=82 x=100 y=48 width=17 height=24 xoffset=3 yoffset=11 xadvance=20 page=0 chnl=15
|
||||
char id=83 x=160 y=72 width=15 height=24 xoffset=1 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=84 x=101 y=24 width=17 height=24 xoffset=1 yoffset=11 xadvance=19 page=0 chnl=15
|
||||
char id=85 x=83 y=24 width=18 height=24 xoffset=3 yoffset=11 xadvance=24 page=0 chnl=15
|
||||
char id=86 x=44 y=48 width=20 height=24 xoffset=0 yoffset=11 xadvance=19 page=0 chnl=15
|
||||
char id=87 x=0 y=0 width=30 height=24 xoffset=0 yoffset=11 xadvance=30 page=0 chnl=15
|
||||
char id=88 x=45 y=81 width=19 height=24 xoffset=0 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=89 x=64 y=48 width=19 height=24 xoffset=0 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=90 x=118 y=24 width=16 height=24 xoffset=1 yoffset=11 xadvance=18 page=0 chnl=15
|
||||
char id=91 x=246 y=29 width=7 height=29 xoffset=3 yoffset=11 xadvance=11 page=0 chnl=15
|
||||
char id=92 x=177 y=24 width=12 height=24 xoffset=0 yoffset=11 xadvance=12 page=0 chnl=15
|
||||
char id=93 x=228 y=51 width=8 height=29 xoffset=0 yoffset=11 xadvance=10 page=0 chnl=15
|
||||
char id=94 x=210 y=0 width=17 height=15 xoffset=0 yoffset=11 xadvance=17 page=0 chnl=15
|
||||
char id=95 x=15 y=123 width=14 height=3 xoffset=0 yoffset=37 xadvance=14 page=0 chnl=15
|
||||
char id=96 x=21 y=75 width=7 height=6 xoffset=6 yoffset=9 xadvance=18 page=0 chnl=15
|
||||
char id=97 x=198 y=54 width=14 height=18 xoffset=1 yoffset=17 xadvance=17 page=0 chnl=15
|
||||
char id=98 x=130 y=72 width=15 height=25 xoffset=3 yoffset=10 xadvance=20 page=0 chnl=15
|
||||
char id=99 x=213 y=36 width=13 height=18 xoffset=2 yoffset=17 xadvance=15 page=0 chnl=15
|
||||
char id=100 x=132 y=97 width=15 height=25 xoffset=2 yoffset=10 xadvance=20 page=0 chnl=15
|
||||
char id=101 x=195 y=0 width=15 height=18 xoffset=2 yoffset=17 xadvance=18 page=0 chnl=15
|
||||
char id=102 x=187 y=96 width=12 height=26 xoffset=1 yoffset=9 xadvance=12 page=0 chnl=15
|
||||
char id=103 x=99 y=72 width=16 height=26 xoffset=1 yoffset=17 xadvance=18 page=0 chnl=15
|
||||
char id=104 x=145 y=72 width=15 height=25 xoffset=3 yoffset=10 xadvance=20 page=0 chnl=15
|
||||
char id=105 x=240 y=61 width=3 height=24 xoffset=3 yoffset=11 xadvance=8 page=0 chnl=15
|
||||
char id=106 x=231 y=0 width=8 height=32 xoffset=-2 yoffset=11 xadvance=8 page=0 chnl=15
|
||||
char id=107 x=162 y=96 width=14 height=25 xoffset=3 yoffset=10 xadvance=17 page=0 chnl=15
|
||||
char id=108 x=253 y=33 width=3 height=25 xoffset=3 yoffset=10 xadvance=8 page=0 chnl=15
|
||||
char id=109 x=0 y=105 width=25 height=18 xoffset=3 yoffset=17 xadvance=30 page=0 chnl=15
|
||||
char id=110 x=198 y=36 width=15 height=18 xoffset=3 yoffset=17 xadvance=20 page=0 chnl=15
|
||||
char id=111 x=179 y=0 width=16 height=18 xoffset=2 yoffset=17 xadvance=19 page=0 chnl=15
|
||||
char id=112 x=115 y=72 width=15 height=26 xoffset=3 yoffset=17 xadvance=20 page=0 chnl=15
|
||||
char id=113 x=117 y=98 width=15 height=26 xoffset=2 yoffset=17 xadvance=20 page=0 chnl=15
|
||||
char id=114 x=246 y=58 width=10 height=18 xoffset=3 yoffset=17 xadvance=13 page=0 chnl=15
|
||||
char id=115 x=219 y=15 width=12 height=18 xoffset=2 yoffset=17 xadvance=15 page=0 chnl=15
|
||||
char id=116 x=218 y=69 width=10 height=22 xoffset=1 yoffset=13 xadvance=12 page=0 chnl=15
|
||||
char id=117 x=204 y=18 width=15 height=18 xoffset=3 yoffset=17 xadvance=20 page=0 chnl=15
|
||||
char id=118 x=50 y=105 width=17 height=18 xoffset=0 yoffset=17 xadvance=16 page=0 chnl=15
|
||||
char id=119 x=25 y=105 width=25 height=18 xoffset=0 yoffset=17 xadvance=25 page=0 chnl=15
|
||||
char id=120 x=67 y=105 width=17 height=18 xoffset=0 yoffset=17 xadvance=17 page=0 chnl=15
|
||||
char id=121 x=82 y=72 width=17 height=26 xoffset=-1 yoffset=17 xadvance=16 page=0 chnl=15
|
||||
char id=122 x=226 y=33 width=12 height=18 xoffset=1 yoffset=17 xadvance=15 page=0 chnl=15
|
||||
char id=123 x=188 y=48 width=10 height=29 xoffset=1 yoffset=11 xadvance=12 page=0 chnl=15
|
||||
char id=124 x=253 y=0 width=3 height=33 xoffset=8 yoffset=10 xadvance=18 page=0 chnl=15
|
||||
char id=125 x=176 y=96 width=11 height=29 xoffset=1 yoffset=11 xadvance=12 page=0 chnl=15
|
||||
char id=126 x=0 y=123 width=15 height=5 xoffset=2 yoffset=20 xadvance=19 page=0 chnl=15
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
99
files/public/OpenSans-B9K8.ttf_neon_64/neon_64.fnt
Normal file
99
files/public/OpenSans-B9K8.ttf_neon_64/neon_64.fnt
Normal file
@ -0,0 +1,99 @@
|
||||
info face="Open Sans" size=-64 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=0 aa=1 padding=0,0,0,0 spacing=0,0 outline=0
|
||||
common lineHeight=87 base=69 scaleW=512 scaleH=256 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
|
||||
page id=0 file="0cqXNM8gYrt7OJ5mzJ_o3PUe.ttf_0.png"
|
||||
chars count=95
|
||||
char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=17 page=0 chnl=15
|
||||
char id=33 x=462 y=135 width=8 height=47 xoffset=5 yoffset=23 xadvance=18 page=0 chnl=15
|
||||
char id=34 x=115 y=129 width=18 height=17 xoffset=4 yoffset=23 xadvance=26 page=0 chnl=15
|
||||
char id=35 x=84 y=146 width=38 height=46 xoffset=2 yoffset=23 xadvance=42 page=0 chnl=15
|
||||
char id=36 x=191 y=127 width=29 height=53 xoffset=4 yoffset=20 xadvance=37 page=0 chnl=15
|
||||
char id=37 x=0 y=156 width=46 height=48 xoffset=3 yoffset=22 xadvance=52 page=0 chnl=15
|
||||
char id=38 x=42 y=98 width=44 height=48 xoffset=4 yoffset=22 xadvance=47 page=0 chnl=15
|
||||
char id=39 x=131 y=238 width=6 height=17 xoffset=4 yoffset=23 xadvance=14 page=0 chnl=15
|
||||
char id=40 x=438 y=92 width=15 height=56 xoffset=3 yoffset=23 xadvance=19 page=0 chnl=15
|
||||
char id=41 x=416 y=197 width=16 height=56 xoffset=1 yoffset=23 xadvance=19 page=0 chnl=15
|
||||
char id=42 x=311 y=0 width=31 height=29 xoffset=2 yoffset=20 xadvance=35 page=0 chnl=15
|
||||
char id=43 x=339 y=212 width=30 height=31 xoffset=3 yoffset=31 xadvance=36 page=0 chnl=15
|
||||
char id=44 x=120 y=238 width=11 height=16 xoffset=1 yoffset=61 xadvance=16 page=0 chnl=15
|
||||
char id=45 x=29 y=250 width=15 height=5 xoffset=3 yoffset=49 xadvance=21 page=0 chnl=15
|
||||
char id=46 x=84 y=192 width=8 height=10 xoffset=5 yoffset=60 xadvance=18 page=0 chnl=15
|
||||
char id=47 x=410 y=0 width=23 height=46 xoffset=0 yoffset=23 xadvance=24 page=0 chnl=15
|
||||
char id=48 x=265 y=32 width=31 height=48 xoffset=3 yoffset=22 xadvance=37 page=0 chnl=15
|
||||
char id=49 x=423 y=148 width=18 height=46 xoffset=5 yoffset=23 xadvance=37 page=0 chnl=15
|
||||
char id=50 x=340 y=163 width=30 height=47 xoffset=3 yoffset=22 xadvance=37 page=0 chnl=15
|
||||
char id=51 x=250 y=166 width=30 height=48 xoffset=3 yoffset=22 xadvance=37 page=0 chnl=15
|
||||
char id=52 x=157 y=142 width=34 height=46 xoffset=1 yoffset=23 xadvance=37 page=0 chnl=15
|
||||
char id=53 x=341 y=114 width=30 height=47 xoffset=4 yoffset=23 xadvance=37 page=0 chnl=15
|
||||
char id=54 x=280 y=166 width=30 height=48 xoffset=4 yoffset=22 xadvance=37 page=0 chnl=15
|
||||
char id=55 x=369 y=210 width=30 height=46 xoffset=3 yoffset=23 xadvance=37 page=0 chnl=15
|
||||
char id=56 x=282 y=116 width=30 height=48 xoffset=3 yoffset=22 xadvance=37 page=0 chnl=15
|
||||
char id=57 x=310 y=164 width=30 height=48 xoffset=3 yoffset=22 xadvance=37 page=0 chnl=15
|
||||
char id=58 x=465 y=0 width=8 height=36 xoffset=5 yoffset=34 xadvance=18 page=0 chnl=15
|
||||
char id=59 x=454 y=0 width=11 height=44 xoffset=2 yoffset=34 xadvance=18 page=0 chnl=15
|
||||
char id=60 x=251 y=0 width=30 height=32 xoffset=3 yoffset=30 xadvance=36 page=0 chnl=15
|
||||
char id=61 x=86 y=129 width=29 height=17 xoffset=4 yoffset=38 xadvance=37 page=0 chnl=15
|
||||
char id=62 x=281 y=0 width=30 height=32 xoffset=3 yoffset=30 xadvance=36 page=0 chnl=15
|
||||
char id=63 x=371 y=46 width=26 height=48 xoffset=0 yoffset=22 xadvance=27 page=0 chnl=15
|
||||
char id=64 x=0 y=46 width=50 height=52 xoffset=4 yoffset=23 xadvance=58 page=0 chnl=15
|
||||
char id=65 x=58 y=0 width=41 height=46 xoffset=0 yoffset=23 xadvance=41 page=0 chnl=15
|
||||
char id=66 x=250 y=120 width=32 height=46 xoffset=6 yoffset=23 xadvance=41 page=0 chnl=15
|
||||
char id=67 x=85 y=202 width=35 height=48 xoffset=4 yoffset=22 xadvance=41 page=0 chnl=15
|
||||
char id=68 x=92 y=46 width=37 height=46 xoffset=6 yoffset=23 xadvance=46 page=0 chnl=15
|
||||
char id=69 x=384 y=0 width=26 height=46 xoffset=6 yoffset=23 xadvance=35 page=0 chnl=15
|
||||
char id=70 x=371 y=94 width=26 height=46 xoffset=6 yoffset=23 xadvance=33 page=0 chnl=15
|
||||
char id=71 x=46 y=154 width=38 height=48 xoffset=4 yoffset=22 xadvance=47 page=0 chnl=15
|
||||
char id=72 x=122 y=146 width=35 height=46 xoffset=6 yoffset=23 xadvance=47 page=0 chnl=15
|
||||
char id=73 x=441 y=148 width=6 height=46 xoffset=6 yoffset=23 xadvance=18 page=0 chnl=15
|
||||
char id=74 x=399 y=197 width=17 height=58 xoffset=-5 yoffset=23 xadvance=17 page=0 chnl=15
|
||||
char id=75 x=168 y=81 width=34 height=46 xoffset=6 yoffset=23 xadvance=39 page=0 chnl=15
|
||||
char id=76 x=397 y=46 width=26 height=46 xoffset=6 yoffset=23 xadvance=33 page=0 chnl=15
|
||||
char id=77 x=0 y=204 width=46 height=46 xoffset=6 yoffset=23 xadvance=58 page=0 chnl=15
|
||||
char id=78 x=120 y=192 width=36 height=46 xoffset=6 yoffset=23 xadvance=48 page=0 chnl=15
|
||||
char id=79 x=50 y=46 width=42 height=48 xoffset=4 yoffset=22 xadvance=50 page=0 chnl=15
|
||||
char id=80 x=355 y=0 width=29 height=46 xoffset=6 yoffset=23 xadvance=38 page=0 chnl=15
|
||||
char id=81 x=0 y=98 width=42 height=58 xoffset=4 yoffset=22 xadvance=50 page=0 chnl=15
|
||||
char id=82 x=202 y=80 width=33 height=46 xoffset=6 yoffset=23 xadvance=39 page=0 chnl=15
|
||||
char id=83 x=370 y=161 width=29 height=48 xoffset=3 yoffset=22 xadvance=35 page=0 chnl=15
|
||||
char id=84 x=201 y=34 width=34 height=46 xoffset=1 yoffset=23 xadvance=36 page=0 chnl=15
|
||||
char id=85 x=166 y=34 width=35 height=47 xoffset=6 yoffset=23 xadvance=47 page=0 chnl=15
|
||||
char id=86 x=46 y=202 width=39 height=46 xoffset=0 yoffset=23 xadvance=38 page=0 chnl=15
|
||||
char id=87 x=0 y=0 width=58 height=46 xoffset=0 yoffset=23 xadvance=59 page=0 chnl=15
|
||||
char id=88 x=99 y=0 width=37 height=46 xoffset=0 yoffset=23 xadvance=37 page=0 chnl=15
|
||||
char id=89 x=129 y=46 width=37 height=46 xoffset=-1 yoffset=23 xadvance=36 page=0 chnl=15
|
||||
char id=90 x=296 y=32 width=31 height=46 xoffset=3 yoffset=23 xadvance=37 page=0 chnl=15
|
||||
char id=91 x=432 y=194 width=15 height=56 xoffset=5 yoffset=23 xadvance=21 page=0 chnl=15
|
||||
char id=92 x=423 y=46 width=23 height=46 xoffset=0 yoffset=23 xadvance=24 page=0 chnl=15
|
||||
char id=93 x=453 y=79 width=15 height=56 xoffset=2 yoffset=23 xadvance=22 page=0 chnl=15
|
||||
char id=94 x=220 y=226 width=33 height=29 xoffset=1 yoffset=23 xadvance=35 page=0 chnl=15
|
||||
char id=95 x=0 y=250 width=29 height=5 xoffset=0 yoffset=74 xadvance=29 page=0 chnl=15
|
||||
char id=96 x=136 y=34 width=13 height=11 xoffset=12 yoffset=19 xadvance=37 page=0 chnl=15
|
||||
char id=97 x=311 y=212 width=28 height=36 xoffset=3 yoffset=34 xadvance=36 page=0 chnl=15
|
||||
char id=98 x=220 y=126 width=30 height=50 xoffset=5 yoffset=20 xadvance=39 page=0 chnl=15
|
||||
char id=99 x=296 y=78 width=25 height=36 xoffset=4 yoffset=34 xadvance=31 page=0 chnl=15
|
||||
char id=100 x=189 y=188 width=31 height=50 xoffset=4 yoffset=20 xadvance=40 page=0 chnl=15
|
||||
char id=101 x=267 y=80 width=29 height=36 xoffset=4 yoffset=34 xadvance=36 page=0 chnl=15
|
||||
char id=102 x=399 y=148 width=24 height=49 xoffset=1 yoffset=20 xadvance=22 page=0 chnl=15
|
||||
char id=103 x=135 y=92 width=33 height=50 xoffset=1 yoffset=34 xadvance=35 page=0 chnl=15
|
||||
char id=104 x=312 y=114 width=29 height=49 xoffset=5 yoffset=20 xadvance=39 page=0 chnl=15
|
||||
char id=105 x=468 y=182 width=6 height=47 xoffset=5 yoffset=22 xadvance=16 page=0 chnl=15
|
||||
char id=106 x=447 y=148 width=15 height=63 xoffset=-4 yoffset=21 xadvance=16 page=0 chnl=15
|
||||
char id=107 x=327 y=29 width=28 height=49 xoffset=5 yoffset=20 xadvance=33 page=0 chnl=15
|
||||
char id=108 x=462 y=182 width=6 height=49 xoffset=5 yoffset=20 xadvance=16 page=0 chnl=15
|
||||
char id=109 x=86 y=94 width=49 height=35 xoffset=5 yoffset=34 xadvance=59 page=0 chnl=15
|
||||
char id=110 x=253 y=214 width=29 height=35 xoffset=5 yoffset=34 xadvance=39 page=0 chnl=15
|
||||
char id=111 x=235 y=84 width=32 height=36 xoffset=4 yoffset=34 xadvance=39 page=0 chnl=15
|
||||
char id=112 x=220 y=176 width=30 height=50 xoffset=5 yoffset=34 xadvance=39 page=0 chnl=15
|
||||
char id=113 x=235 y=34 width=30 height=50 xoffset=4 yoffset=34 xadvance=40 page=0 chnl=15
|
||||
char id=114 x=446 y=44 width=20 height=35 xoffset=5 yoffset=34 xadvance=26 page=0 chnl=15
|
||||
char id=115 x=321 y=78 width=25 height=36 xoffset=3 yoffset=34 xadvance=30 page=0 chnl=15
|
||||
char id=116 x=433 y=0 width=21 height=44 xoffset=1 yoffset=26 xadvance=23 page=0 chnl=15
|
||||
char id=117 x=282 y=214 width=29 height=35 xoffset=5 yoffset=35 xadvance=40 page=0 chnl=15
|
||||
char id=118 x=186 y=0 width=33 height=34 xoffset=0 yoffset=35 xadvance=32 page=0 chnl=15
|
||||
char id=119 x=136 y=0 width=50 height=34 xoffset=0 yoffset=35 xadvance=50 page=0 chnl=15
|
||||
char id=120 x=219 y=0 width=32 height=34 xoffset=1 yoffset=35 xadvance=34 page=0 chnl=15
|
||||
char id=121 x=156 y=192 width=33 height=49 xoffset=0 yoffset=35 xadvance=32 page=0 chnl=15
|
||||
char id=122 x=346 y=78 width=25 height=34 xoffset=3 yoffset=35 xadvance=31 page=0 chnl=15
|
||||
char id=123 x=397 y=92 width=21 height=56 xoffset=1 yoffset=23 xadvance=24 page=0 chnl=15
|
||||
char id=124 x=468 y=36 width=4 height=65 xoffset=15 yoffset=19 xadvance=34 page=0 chnl=15
|
||||
char id=125 x=418 y=92 width=20 height=56 xoffset=2 yoffset=23 xadvance=24 page=0 chnl=15
|
||||
char id=126 x=42 y=146 width=30 height=8 xoffset=3 yoffset=42 xadvance=36 page=0 chnl=15
|
||||
BIN
files/public/img_white_bg.png
Normal file
BIN
files/public/img_white_bg.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
38
library/LibBullAdapter.js
Normal file
38
library/LibBullAdapter.js
Normal file
@ -0,0 +1,38 @@
|
||||
const LibSchedulerReverseGeocode = require('./LibSchedulerReverseGeocode');
|
||||
const LibQueueBlastOrder = require('./LibQueueBlastOrder');
|
||||
const LibSchedulerDrvUpLoc = require('./LibSchedulerDrvUpLoc');
|
||||
const LibSchedulerDrvUpPhoto = require('./LibSchedulerDrvUpPhoto');
|
||||
const LibSchedulerDrvUpLocIdle = require('./LibSchedulerDrvUpLocIdle');
|
||||
const LibSchedulerDrvBlastNotif = require('./LibSchedulerDrvBlastNotif');
|
||||
const LibSchedulerGpsTrackerWakeUp = require('./LibSchedulerGpsTrackerWakeUp');
|
||||
const { createBullBoard } = require('@bull-board/api');
|
||||
const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter');
|
||||
const { ExpressAdapter } = require('@bull-board/express');
|
||||
|
||||
const serverAdapter = new ExpressAdapter();
|
||||
|
||||
const { addQueue, removeQueue, setQueues, replaceQueues } = createBullBoard({
|
||||
queues: [
|
||||
new BullMQAdapter(LibSchedulerReverseGeocode.queue),
|
||||
new BullMQAdapter(LibQueueBlastOrder.queue),
|
||||
new BullMQAdapter(LibSchedulerDrvUpLoc.queue),
|
||||
new BullMQAdapter(LibSchedulerDrvUpPhoto.queue),
|
||||
new BullMQAdapter(LibSchedulerDrvUpLocIdle.queue),
|
||||
new BullMQAdapter(LibSchedulerDrvBlastNotif.queue),
|
||||
new BullMQAdapter(LibSchedulerGpsTrackerWakeUp.queue),
|
||||
],
|
||||
serverAdapter: serverAdapter,
|
||||
})
|
||||
|
||||
// will work on old added queue or new added queue
|
||||
LibSchedulerReverseGeocode.setWorker();
|
||||
LibQueueBlastOrder.setWorker();
|
||||
LibSchedulerDrvUpLoc.setWorker();
|
||||
LibSchedulerDrvUpPhoto.setWorker();
|
||||
LibSchedulerDrvUpLocIdle.setWorker();
|
||||
LibSchedulerDrvBlastNotif.setWorker();
|
||||
LibSchedulerGpsTrackerWakeUp.setWorker();
|
||||
|
||||
serverAdapter.setBasePath(process.env.PATH_URL + '/bull/monitor');
|
||||
|
||||
module.exports = serverAdapter;
|
||||
300
library/LibCurl.js
Normal file
300
library/LibCurl.js
Normal file
@ -0,0 +1,300 @@
|
||||
const axios = require('axios').default;
|
||||
const url = require('url');
|
||||
const request = require('../config/request');
|
||||
const RegionModels = require('../models/RegionModels');
|
||||
|
||||
const DEFAULT_COUNTRY_ID = 1;
|
||||
|
||||
class LibCurl {
|
||||
|
||||
static reverseGeo(lat, lng) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let respReverseGeo = null;
|
||||
try {
|
||||
let params = new url.URLSearchParams({
|
||||
lat,
|
||||
lon: lng,
|
||||
format: 'geojson',
|
||||
});
|
||||
const axInstance = axios.create();
|
||||
axios.defaults.timeout = 3000;
|
||||
axios.defaults.crossDomain = true;
|
||||
// respReverseGeo = await axios({
|
||||
// url: request.osm_reverse_geo.urlFull,
|
||||
// method: request.osm_reverse_geo.method,
|
||||
// params: params,
|
||||
// responseType: 'json',
|
||||
// });
|
||||
respReverseGeo = await axInstance.get(request.osm_reverse_geo.urlFull + '?' + params.toString(), {
|
||||
timeout: 3000,
|
||||
});
|
||||
let respData = respReverseGeo.data || {};
|
||||
if (respReverseGeo.status == 200) {
|
||||
if (respData.features.length < 1) {
|
||||
resolve({type: 'no_available', respData});
|
||||
} else {
|
||||
let respAddr = respData.features[0].properties.address;
|
||||
let addrData = {
|
||||
lat,
|
||||
lng,
|
||||
country_id: DEFAULT_COUNTRY_ID,
|
||||
country_code: respAddr.country_code,
|
||||
country_text: (respAddr.country) ? respAddr.country.toUpperCase() : respAddr.country || null,
|
||||
postcode: respAddr.postcode,
|
||||
fulladdress: encodeURIComponent(respData.features[0].properties.display_name),
|
||||
log_reverse_geo: (respData.features[0].properties) ? JSON.stringify(respData.features[0].properties) : null,
|
||||
};
|
||||
// if (respAddr.state || respAddr.city) {
|
||||
addrData.state_id = null;
|
||||
addrData.state_text = respAddr.region || respAddr.state || respAddr.state_district || respAddr.county || respAddr.city || '';
|
||||
addrData.state_text = (addrData.state_text) ? addrData.state_text.toUpperCase() : addrData.state_text || null;
|
||||
addrData.state_text = addrData.state_text || null;
|
||||
// }
|
||||
// if (respAddr.city_district || respAddr.city) {
|
||||
addrData.city_id = null;
|
||||
addrData.city_text = respAddr.city_district || respAddr.city || '';
|
||||
addrData.city_text = (addrData.city_text) ? addrData.city_text.toUpperCase() : addrData.city_text || null;
|
||||
addrData.city_text = addrData.city_text || null;
|
||||
// }
|
||||
// if (respAddr.suburb || respAddr.subdistrict) {
|
||||
addrData.district_id = null;
|
||||
addrData.district_text = respAddr.suburb || respAddr.subdistrict || respAddr.subdivision || '';
|
||||
addrData.district_text = (addrData.district_text) ? addrData.district_text.toUpperCase() : addrData.district_text || null;
|
||||
addrData.district_text = addrData.district_text || null;
|
||||
// }
|
||||
// if (respAddr.village || respAddr.neighbourhood) {
|
||||
addrData.village_id = null;
|
||||
addrData.village_text = respAddr.village || respAddr.neighbourhood || '';
|
||||
addrData.village_text = (addrData.village_text) ? addrData.village_text.toUpperCase() : addrData.village_text || null;
|
||||
addrData.village_text = addrData.village_text || null;
|
||||
// }
|
||||
// if (respAddr.amenity || respAddr.road || respAddr.city_block) {
|
||||
addrData.streets = '';
|
||||
addrData.streets += (respAddr.amenity) ? respAddr.amenity + ', ' : '';
|
||||
addrData.streets += (respAddr.road) ? respAddr.road + ', ' : '';
|
||||
addrData.streets += (respAddr.house_number) ? respAddr.house_number + ', ' : '';
|
||||
addrData.streets += (respAddr.house_name) ? respAddr.house_name + ', ' : '';
|
||||
addrData.streets += (respAddr.city_block) ? respAddr.city_block + ', ' : '';
|
||||
addrData.streets += addrData.streets || null;
|
||||
if (addrData.streets) {
|
||||
addrData.streets = encodeURIComponent(addrData.streets.slice(0, -2));
|
||||
}
|
||||
// }
|
||||
|
||||
let byAll = await RegionModels.whereLike({
|
||||
nmProvinsiKel: addrData.state_text,
|
||||
nmKotamadyaKel: addrData.city_text,
|
||||
nmKecamatanKel: addrData.district_text,
|
||||
nmKelurahan: addrData.village_text,
|
||||
});
|
||||
if (byAll.length > 1) {
|
||||
addrData.state_id = byAll[0].kodeProv;
|
||||
addrData.city_id = byAll[0].kodeKab;
|
||||
addrData.district_id = byAll[0].kodeKec;
|
||||
addrData.village_id = byAll[0].kodeKel;
|
||||
}
|
||||
|
||||
let byKel = await RegionModels.whereLike({
|
||||
nmKelurahan: addrData.village_text,
|
||||
});
|
||||
if (byAll.length < 1 && byKel.length > 0) {
|
||||
addrData.state_id = byKel[0].kodeProv;
|
||||
addrData.city_id = byKel[0].kodeKab;
|
||||
addrData.district_id = byKel[0].kodeKec;
|
||||
addrData.village_id = byKel[0].kodeKel;
|
||||
}
|
||||
|
||||
if (addrData.state_id === null) {
|
||||
let byPr = await RegionModels.whereLike({ nmProvinsiKel: addrData.state_text });
|
||||
if (byPr.length > 0) { addrData.state_id = byPr[0].kodeProv; }
|
||||
}
|
||||
|
||||
if (addrData.state_id !== null && addrData.city_id === null) {
|
||||
let byKt = await RegionModels.whereLike({ nmKotamadyaKel: addrData.city_text });
|
||||
if (byKt.length > 0) { addrData.city_id = byKt[0].kodeKab; }
|
||||
}
|
||||
|
||||
if (addrData.state_id !== null && addrData.city_id !== null && addrData.district_id === null) {
|
||||
let byKc = await RegionModels.whereLike({ nmKecamatanKel: addrData.district_text });
|
||||
if (byKc.length > 0) { addrData.district_id = byKc[0].kodeKec; }
|
||||
}
|
||||
|
||||
if (addrData.state_id !== null && addrData.city_id !== null && addrData.district_id !== null && addrData.village_id === null) {
|
||||
let byKl = await RegionModels.whereLike({ nmKelurahan: addrData.village_text });
|
||||
if (byKl.length > 0) { addrData.village_id = byKl[0].kodeKel; }
|
||||
}
|
||||
|
||||
resolve({type: 'sc', respData, addrData});
|
||||
}
|
||||
} else {
|
||||
resolve({type: 'fail', respData});
|
||||
}
|
||||
} catch (e) {
|
||||
let respData = {}
|
||||
if (respReverseGeo) {
|
||||
if (respReverseGeo.status != 200) {
|
||||
respData.data = respReverseGeo.data;
|
||||
} else {
|
||||
respData.msg = e.message;
|
||||
}
|
||||
} else if (typeof e.response != 'undefined') {
|
||||
respData.data = e.response;
|
||||
} else {
|
||||
respData.msg = e.message;
|
||||
}
|
||||
resolve({type: 'error', respData});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// https://github.com/sooluh/kodepos
|
||||
// https://kodepos.vercel.app/search?q=16418&json=true
|
||||
static getRegionId(postcode) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let respRegion = null;
|
||||
try {
|
||||
let params = new url.URLSearchParams({
|
||||
q: postcode,
|
||||
json: 'true',
|
||||
});
|
||||
const axInstance = axios.create();
|
||||
axios.defaults.timeout = 3000;
|
||||
axios.defaults.crossDomain = true;
|
||||
// respRegion = await axios({
|
||||
// url: request.kodepos_region.urlFull,
|
||||
// method: request.kodepos_region.method,
|
||||
// params: params,
|
||||
// responseType: 'json',
|
||||
// });
|
||||
respRegion = await axInstance.get(request.kodepos_region.urlFull + '?' + params.toString(), {
|
||||
timeout: 3000,
|
||||
});
|
||||
let respData = respRegion.data || {};
|
||||
if (respData.status !== true || respRegion.status == 200) {
|
||||
if (typeof respData.data === undefied || respData.data.length < 1) {
|
||||
resolve({type: 'no_available', respData});
|
||||
} else {
|
||||
let respAddr = respData.data[0];
|
||||
let addrData = {
|
||||
state_id: null,
|
||||
state_text: respAddr.province || null,
|
||||
city_id: null,
|
||||
city_text: respAddr.city || null,
|
||||
district_id: null,
|
||||
district_text: respAddr.subdistrict || null,
|
||||
village_id: null,
|
||||
village_text: respAddr.urban || null,
|
||||
};
|
||||
|
||||
let byAll = await RegionModels.whereLike({
|
||||
nmProvinsiKel: addrData.state_text,
|
||||
nmKotamadyaKel: addrData.city_text,
|
||||
nmKecamatanKel: addrData.district_text,
|
||||
nmKelurahan: addrData.village_text,
|
||||
});
|
||||
if (byAll.length > 1) {
|
||||
addrData.state_id = byAll[0].kodeProv;
|
||||
addrData.city_id = byAll[0].kodeKab;
|
||||
addrData.district_id = byAll[0].kodeKec;
|
||||
addrData.village_id = byAll[0].kodeKel;
|
||||
}
|
||||
|
||||
let byKel = await RegionModels.whereLike({
|
||||
nmKelurahan: addrData.village_text,
|
||||
});
|
||||
if (byAll.length < 1 && byKel.length > 0) {
|
||||
addrData.state_id = byKel[0].kodeProv;
|
||||
addrData.city_id = byKel[0].kodeKab;
|
||||
addrData.district_id = byKel[0].kodeKec;
|
||||
addrData.village_id = byKel[0].kodeKel;
|
||||
}
|
||||
|
||||
if (addrData.state_id === null) {
|
||||
let byPr = await RegionModels.whereLike({ nmProvinsiKel: addrData.state_text });
|
||||
if (byPr.length > 0) { addrData.state_id = byPr[0].kodeProv; }
|
||||
}
|
||||
|
||||
if (addrData.state_id !== null && addrData.city_id === null) {
|
||||
let byKt = await RegionModels.whereLike({ nmKotamadyaKel: addrData.city_text });
|
||||
if (byKt.length > 0) { addrData.city_id = byKt[0].kodeKab; }
|
||||
}
|
||||
|
||||
if (addrData.state_id !== null && addrData.city_id !== null && addrData.district_id === null) {
|
||||
let byKc = await RegionModels.whereLike({ nmKecamatanKel: addrData.district_text });
|
||||
if (byKc.length > 0) { addrData.district_id = byKc[0].kodeKec; }
|
||||
}
|
||||
|
||||
if (addrData.state_id !== null && addrData.city_id !== null && addrData.district_id !== null && addrData.village_id === null) {
|
||||
let byKl = await RegionModels.whereLike({ nmKelurahan: addrData.village_text });
|
||||
if (byKl.length > 0) { addrData.village_id = byKl[0].kodeKel; }
|
||||
}
|
||||
|
||||
resolve({type: 'sc', respData, addrData});
|
||||
}
|
||||
} else {
|
||||
resolve({type: 'fail', respData});
|
||||
}
|
||||
} catch (e) {
|
||||
let respData = {}
|
||||
if (respRegion) {
|
||||
if (respRegion.status != 200) {
|
||||
respData.data = respRegion.data;
|
||||
} else {
|
||||
respData.msg = e.message;
|
||||
}
|
||||
} else if (typeof e.response != 'undefined') {
|
||||
respData.data = e.response;
|
||||
} else {
|
||||
respData.msg = e.message;
|
||||
}
|
||||
resolve({type: 'error', respData});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static formurlencoded(apiUrl, data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let respApi = null;
|
||||
try {
|
||||
let params = new url.URLSearchParams();
|
||||
for (let row of data.names || []) {
|
||||
params.append('names[]', row);
|
||||
}
|
||||
for (let row of data.photos || []) {
|
||||
params.append('photos[]', row);
|
||||
}
|
||||
const axInstance = axios.create();
|
||||
axios.defaults.timeout = 3000;
|
||||
axios.defaults.crossDomain = true;
|
||||
respApi = await axInstance.post(apiUrl, params, {
|
||||
headers: {
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
});
|
||||
let respData = respApi.data || {};
|
||||
if (respData.meta.code == 200) {
|
||||
resolve({type: 'sc', respData});
|
||||
} else {
|
||||
resolve({type: 'fail', respData});
|
||||
}
|
||||
} catch (e) {
|
||||
let respData = {}
|
||||
if (respApi) {
|
||||
if (respApi.status != 200) {
|
||||
respData.data = respApi.data;
|
||||
} else {
|
||||
respData.msg = e.message;
|
||||
}
|
||||
} else if (typeof e.response != 'undefined') {
|
||||
respData.data = e.response;
|
||||
} else {
|
||||
respData.msg = e.message;
|
||||
}
|
||||
resolve({type: 'error', respData});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = LibCurl;
|
||||
573
library/LibDevice.js
Normal file
573
library/LibDevice.js
Normal file
@ -0,0 +1,573 @@
|
||||
const LibHelper = require('./LibHelper');
|
||||
|
||||
class LibDevice {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Buffer} buffer
|
||||
* @param {Object} opts
|
||||
* @returns {Object} me
|
||||
* must return at least => obj.protocol_name
|
||||
*/
|
||||
static identifyProtocolFromBuffer(buffer, opts = {}) {
|
||||
let ori_hex_str = '';
|
||||
if (typeof opts.skip_buffer != 'undefined' && opts.skip_buffer === true) {
|
||||
ori_hex_str = buffer;
|
||||
} else {
|
||||
ori_hex_str = buffer.toString('hex'); // 16
|
||||
}
|
||||
|
||||
const data = ori_hex_str;
|
||||
const me = {
|
||||
ori_string: data,
|
||||
};
|
||||
|
||||
// eelinkCustom
|
||||
if (opts.isEelinkCustom) {
|
||||
me.protocol_name = 'eelinkCustom';
|
||||
|
||||
me.field0 = data.slice(0, 2); // system status flag
|
||||
me.field1 = data.slice(2, 18); // IMEI
|
||||
me.field2 = data.slice(18, 34); // IMSI
|
||||
me.field3 = data.slice(34, 42); // Time
|
||||
me.field4 = data.slice(42, 58); // Location
|
||||
me.field5 = data.slice(58, 62); // Altitude
|
||||
me.field6 = data.slice(62, 66); // Heading
|
||||
me.field7 = data.slice(66, 68); // Velocity
|
||||
me.field8 = data.slice(68, 70); // Power Input Voltage
|
||||
me.field9 = data.slice(70, 72); // GPIO Status
|
||||
me.field10 = data.slice(72, 74); // Time Seconds
|
||||
me.field11 = data.slice(74, 76); // RSSI
|
||||
me.field12 = data.slice(76, 78); // Sequence Counter
|
||||
me.field13 = data.slice(78, 80); // Vendor ID
|
||||
me.field14 = data.slice(80, 82); // GPS Satellites
|
||||
me.field15 = data.slice(82, 90); // Accumulators
|
||||
|
||||
me.ori_string = data;
|
||||
}
|
||||
// gt06
|
||||
else if (data.slice(0, 4) == '7878') {
|
||||
me.protocol_name = 'gt06';
|
||||
|
||||
me.start = data.slice(0, 4);
|
||||
me.length = parseInt(data.slice(4, 6), 16);
|
||||
me.protocol_id = data.slice(6, 8);
|
||||
me.serial_number = data.slice(-12, -8)
|
||||
me.error_check = data.slice(-8, -4)
|
||||
me.finish = data.slice(-4); // data.substr(6 + me.length * 2, 4);
|
||||
|
||||
if (me.finish != '0d0a') {
|
||||
throw 'finish code incorrect!';
|
||||
}
|
||||
|
||||
me.ori_string = data;
|
||||
}
|
||||
// gt02a
|
||||
else if (data.slice(0, 4) == '6868') {
|
||||
me.protocol_name = 'gt02a';
|
||||
}
|
||||
// tk103
|
||||
// else if (data.indexOf("B")) {
|
||||
// me.protocol_name = 'tk103';
|
||||
// }
|
||||
// eelink
|
||||
else if (data.slice(0, 4) == '6767') {
|
||||
me.protocol_name = 'eelink';
|
||||
|
||||
me.start = data.slice(0, 4);
|
||||
me.pid = data.slice(4, 6);
|
||||
me.size = parseInt(data.slice(6, 10), 16);
|
||||
me.sequence = parseInt(data.slice(10, 4), 16);
|
||||
|
||||
me.ori_string = data;
|
||||
}
|
||||
// unknown
|
||||
else {
|
||||
me.protocol_name = 'unknown';
|
||||
}
|
||||
|
||||
return me;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Object} me
|
||||
* @param {String} device_id
|
||||
* @returns
|
||||
* must return at least => act.cmd,act.action_type,act.device_id
|
||||
*/
|
||||
static gt06Action(me, device_id = null) {
|
||||
const act = {}
|
||||
|
||||
// Login message
|
||||
if (me.protocol_id == '01') {
|
||||
act.action_type = 'login';
|
||||
|
||||
act.cmd = 'login_request';
|
||||
act.action = 'login_request';
|
||||
act.device_id = me.ori_string.slice(8).slice(0, 16).padStart(16, '0');
|
||||
|
||||
act.buffer_resp = LibDevice.gt06AuthorizeResp(me);
|
||||
}
|
||||
// Location data
|
||||
else if (me.protocol_id == '12') {
|
||||
act.action_type = 'location';
|
||||
|
||||
act.cmd = 'ping';
|
||||
act.action = 'ping';
|
||||
act.device_id = device_id; // because device_id only sent when login
|
||||
|
||||
// content data
|
||||
// me.ori_string.slice(8).slice(0, 52); // me.ori_string.substr(8, me.length * 2);
|
||||
|
||||
// gps information
|
||||
act.gps_string = me.ori_string.slice(8).slice(0, 36);
|
||||
act.gps_data = LibDevice.gt06ParseLocation(me, act.gps_string);
|
||||
// if (!act.gps_data) {
|
||||
// //Something bad happened
|
||||
// _this.do_log('GPS Data can\'t be parsed. Discarding packet...');
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// lbs information
|
||||
act.lbs_string = me.ori_string.slice(8).slice(36, 52);
|
||||
act.lbs_data = LibDevice.gt06ParseLbs(me, act.lbs_string);
|
||||
}
|
||||
// Status information
|
||||
else if (me.protocol_id == '13') {
|
||||
act.action_type = 'heartbeat';
|
||||
|
||||
act.cmd = 'heartbeat';
|
||||
act.action = 'heartbeat';
|
||||
act.device_id = device_id; // because device_id only sent when login
|
||||
|
||||
// status information
|
||||
act.stts_string = me.ori_string.slice(8).slice(0, 10);
|
||||
act.stts_data = LibDevice.gt06ParseHeartbeat(me, act.stts_string);
|
||||
|
||||
act.buffer_resp = LibDevice.gt06HeartbeatResp(me);
|
||||
}
|
||||
// String information
|
||||
else if (me.protocol_id == '15') {
|
||||
// act.action_type = 'other'; // 'heartbeat';
|
||||
// act.cmd = 'other'; // 'heartbeat';
|
||||
// act.action = 'other'; // 'heartbeat';
|
||||
// act.device_id = ''; // device_id; // because device_id only sent when login
|
||||
|
||||
act.action_type = 'heartbeat';
|
||||
|
||||
act.cmd = 'heartbeat';
|
||||
act.action = 'heartbeat';
|
||||
act.device_id = device_id; // because device_id only sent when login
|
||||
|
||||
// status information
|
||||
act.stts_string = me.ori_string.slice(8).slice(0, 10);
|
||||
act.stts_data = LibDevice.gt06ParseHeartbeat(me, act.stts_string);
|
||||
|
||||
act.buffer_resp = LibDevice.gt06HeartbeatResp(me);
|
||||
}
|
||||
// Alarm data
|
||||
else if (me.protocol_id == '16' || me.protocol_id == '18') {
|
||||
act.action_type = 'alarm';
|
||||
|
||||
act.cmd = 'alarm';
|
||||
act.action = 'alarm';
|
||||
act.device_id = device_id; // because device_id only sent when login
|
||||
|
||||
// content data
|
||||
// me.ori_string.slice(8).slice(0, 64); // me.ori_string.substr(8, me.length * 2);
|
||||
|
||||
// gps information
|
||||
act.gps_string = me.ori_string.slice(8).slice(0, 36);
|
||||
act.gps_data = LibDevice.gt06ParseLocation(me, act.gps_string);
|
||||
|
||||
// lbs information
|
||||
act.lbs_string = me.ori_string.slice(8).slice(36, 54);
|
||||
act.lbs_data = LibDevice.gt06ParseLbs(me, act.lbs_string);
|
||||
|
||||
// status information
|
||||
act.stts_string = me.ori_string.slice(8).slice(54, 64);
|
||||
act.stts_data = LibDevice.gt06ParseStatusAlarm(me, act.stts_string);
|
||||
|
||||
act.buffer_resp = LibDevice.gt06AlarmResp(me);
|
||||
}
|
||||
// GPS, query address information by phone number
|
||||
else if (me.protocol_id == '1A') {
|
||||
act.action_type = 'other';
|
||||
|
||||
act.cmd = 'other';
|
||||
act.action = 'other';
|
||||
act.device_id = '';
|
||||
}
|
||||
// Command information sent by the server to the terminal
|
||||
else if (me.protocol_id == '80') {
|
||||
act.action_type = 'other';
|
||||
|
||||
act.cmd = 'other';
|
||||
act.action = 'other';
|
||||
act.device_id = '';
|
||||
} else {
|
||||
act.action_type = 'other';
|
||||
|
||||
act.cmd = 'other';
|
||||
act.action = 'other';
|
||||
act.device_id = '';
|
||||
}
|
||||
|
||||
return act;
|
||||
}
|
||||
|
||||
static gt06AuthorizeResp(me) {
|
||||
return Buffer.from("787805010001d9dc0d0a", "hex");
|
||||
}
|
||||
|
||||
static gt06ParseLocation(me, gps_string = null) {
|
||||
if (!gps_string) {
|
||||
gps_string = me.ori_string.slice(8).slice(0, 36);
|
||||
}
|
||||
|
||||
let year = (parseInt(gps_string.slice(0, 2), 16) + '').padStart(2, 0);
|
||||
year = '20' + year;
|
||||
let month = (parseInt(gps_string.slice(2, 4), 16) + '').padStart(2, 0);
|
||||
let day = (parseInt(gps_string.slice(4, 6), 16) + '').padStart(2, 0);
|
||||
let hour = (parseInt(gps_string.slice(6, 8), 16) + '').padStart(2, 0);
|
||||
let minute = (parseInt(gps_string.slice(8, 10), 16) + '').padStart(2, 0);
|
||||
let second = (parseInt(gps_string.slice(10, 12), 16) + '').padStart(2, 0);
|
||||
|
||||
let ob1 = LibHelper.hex2bin(gps_string.slice(32, 34)); // orientation_byte1
|
||||
let ob1_bit7 = ob1.slice(0, 1);
|
||||
let ob1_bit6 = ob1.slice(1, 2);
|
||||
let ob1_bit5 = ob1.slice(2, 3); // 0 (realtime GPS) or differential positioning
|
||||
let ob1_bit4 = ob1.slice(3, 4); // 1 (GPS has been positioned)
|
||||
let ob1_bit3 = ob1.slice(4, 5); // 0 (east longitude) || 1 (west longitude)
|
||||
let ob1_bit2 = ob1.slice(5, 6); // 1 (north latitude) || 0 (south latitude)
|
||||
let ob1_bit1 = ob1.slice(6, 7);
|
||||
let ob1_bit0 = ob1.slice(7, 8);
|
||||
let ob2 = LibHelper.hex2bin(gps_string.slice(34, 36)); // orientation_byte2
|
||||
// let ob2_bit7 = ob2.slice(0, 1);
|
||||
// let ob2_bit6 = ob2.slice(1, 2);
|
||||
// let ob2_bit5 = ob2.slice(2, 3);
|
||||
// let ob2_bit4 = ob2.slice(3, 4);
|
||||
// let ob2_bit3 = ob2.slice(4, 5);
|
||||
// let ob2_bit2 = ob2.slice(5, 6);
|
||||
// let ob2_bit1 = ob2.slice(6, 7);
|
||||
// let ob2_bit0 = ob2.slice(7, 8);
|
||||
|
||||
let lat_wind = ''; // wind direction N,S
|
||||
let lng_wind = ''; // wind direction W,E
|
||||
if (ob1_bit3 == 1) {
|
||||
lng_wind = 'W';
|
||||
}
|
||||
if (ob1_bit3 == 0) {
|
||||
lng_wind = 'E';
|
||||
}
|
||||
if (ob1_bit2 == 1) {
|
||||
lat_wind = 'N';
|
||||
}
|
||||
if (ob1_bit2 == 0) {
|
||||
lat_wind = 'S';
|
||||
}
|
||||
|
||||
const data = {
|
||||
'date_raw': gps_string.slice(0, 12),
|
||||
'date': `${year}-${month}-${day} ${hour}:${minute}:${second}`,
|
||||
'quantity_pos_satellites_raw': gps_string.slice(12, 14),
|
||||
'quantity_pos_satellites_c': parseInt(gps_string.slice(12, 13), 16), // length of gps information
|
||||
'quantity_pos_satellites_b': parseInt(gps_string.slice(13, 14), 16), // number of positioning satellites
|
||||
realtime_dif_gps: ob1_bit5, // 0 (realtime GPS) or differential positioning
|
||||
positioning_gps: ob1_bit6, // 1 (GPS has been positioned)
|
||||
'latitude_raw': gps_string.slice(14, 22),
|
||||
'longitude_raw': gps_string.slice(22, 30),
|
||||
lat_wind_direction: lat_wind,
|
||||
lng_wind_direction: lng_wind,
|
||||
'latitude': LibDevice.gt06Hex2DMM(gps_string.slice(14, 22), lat_wind),
|
||||
'longitude': LibDevice.gt06Hex2DMM(gps_string.slice(22, 30), lng_wind),
|
||||
'speed': parseInt(gps_string.slice(30, 32), 16), // km/h
|
||||
'orientation_raw': gps_string.slice(32, 36),
|
||||
'orientation': parseInt(`${ob1_bit1}${ob1_bit0}${ob2}`, 2), // -360 ~ 360 derajat
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// more accurate
|
||||
static gt06Hex2DMM(hex, direction) {
|
||||
hex = parseInt(hex, 16);
|
||||
// convert hexadecimal to Degrees Minutes.m (DMM)
|
||||
let a = parseInt(hex, 10) // to decimal values
|
||||
let b = a / 30000.0
|
||||
let degrees = b / 60
|
||||
let minutes = b % 60
|
||||
// convert DMM to Decimal Degrees (DD)
|
||||
// let d = minutes / 60
|
||||
// let dd = degrees + d
|
||||
// add - follow wind direction
|
||||
if (direction == "S" || direction == "W" || direction == "s" || direction == "w") {
|
||||
degrees = degrees * -1;
|
||||
}
|
||||
return degrees;
|
||||
}
|
||||
// ga akurat
|
||||
static gt06Hex2DMM1(hex, direction) {
|
||||
hex = parseInt(hex, 16);
|
||||
// convert hexadecimal to Degrees Minutes.m (DMM)
|
||||
let a = parseInt(hex, 10) // to decimal values
|
||||
let b = a / 30000.0
|
||||
let degrees = b / 60
|
||||
let minutes = b % 60
|
||||
// convert DMM to Decimal Degrees (DD)
|
||||
let d = minutes / 60
|
||||
let dd = degrees + d
|
||||
// add - follow wind direction
|
||||
if (direction == "S" || direction == "W" || direction == "s" || direction == "w") {
|
||||
dd = dd * -1;
|
||||
}
|
||||
return dd;
|
||||
}
|
||||
|
||||
static gt06HeartbeatResp(me) {
|
||||
return Buffer.from("787805130001d9dc0d0a", "hex");
|
||||
}
|
||||
|
||||
static gt06ParseHeartbeat(me, stts_string) {
|
||||
if (!stts_string) {
|
||||
stts_string = me.ori_string.slice(8).slice(0, 10);
|
||||
}
|
||||
|
||||
let terminal_info_raw = stts_string.slice(0, 2);
|
||||
let tib1 = LibHelper.hex2bin(terminal_info_raw); // terminal_info_byte1
|
||||
let tib1_bit7 = tib1.slice(0, 1);
|
||||
let tib1_bit6 = tib1.slice(1, 2);
|
||||
let tib1_bit5 = tib1.slice(2, 3);
|
||||
let tib1_bit4 = tib1.slice(3, 4);
|
||||
let tib1_bit3 = tib1.slice(4, 5);
|
||||
let tib1_bit2 = tib1.slice(5, 6);
|
||||
let tib1_bit1 = tib1.slice(6, 7);
|
||||
let tib1_bit0 = tib1.slice(7, 8);
|
||||
|
||||
/**
|
||||
* 0: No Power (shutdown)
|
||||
* 1: Extremely Low Battery (not enough for calling or sending text messages, etc.)
|
||||
* 2: Very Low Battery (Low Battery Alarm)
|
||||
* 3: Low Battery (can be used normally)
|
||||
* 4: Medium
|
||||
* 5: High
|
||||
* 6: Very High
|
||||
*/
|
||||
let voltage_level = stts_string.slice(2, 4);
|
||||
|
||||
let gsm_signal_strength = stts_string.slice(4, 6);
|
||||
|
||||
let alarm_stts = stts_string.slice(6, 8); // former bit: terminal alarm status (suitable for alarm packet and electronic fence project)
|
||||
let language = stts_string.slice(8, 10); // latter bit: the current language used in the terminal
|
||||
|
||||
const data = {
|
||||
terminal_info_raw: terminal_info_raw,
|
||||
terminal_info_byte: tib1,
|
||||
terminal_info: {
|
||||
oil_electricity: tib1_bit7, // 1: oil and electricity disconnected, 0: gas oil and electricity connected
|
||||
gps_tracking: tib1_bit6, // 1: GPS tracking is on, 0: GPS tracking is off
|
||||
stts: `${tib1_bit5}${tib1_bit4}${tib1_bit3}`, // 100: SOS, 011: Low Battery Alarm, 010: Power Cut Alarm, 001: Shock Alarm, 000: Normal
|
||||
charge: tib1_bit2, // 1: Charge On, 0: Charge Off
|
||||
acc: tib1_bit1, // 1: ACC high, 0: ACC Low
|
||||
is_active: tib1_bit0, // 1: Activated, 0: Deactivated
|
||||
},
|
||||
voltage_level,
|
||||
gsm_signal_strength, // 0x00: no signal; 0x01: extremely weak signal; 0x02: very weak signal; 0x03: good signal; 0x04: strong signal.
|
||||
alarm_stts, // 0x00: normal, 0x01: SOS, 0x02: Power Cut Alarm, 0x03: Shock Alarm, 0x04: Fence In Alarm, 0x05: Fence Out Alarm
|
||||
language, // 0x01: Chinese, 0x02: English
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static gt06ParseLbs(me, lbs_string) {
|
||||
let mcc_raw = null,
|
||||
mcc = null, // mobile country code
|
||||
mnc_raw = null,
|
||||
mnc = null, // mobile network code
|
||||
lac_raw = null,
|
||||
lac = null, // location area code
|
||||
cellID_raw = null,
|
||||
cellID = null, // cell tower id
|
||||
lbs_length_raw = null,
|
||||
lbs_length = null;
|
||||
|
||||
// from location
|
||||
if (lbs_string.length == 16) {
|
||||
mcc_raw = lbs_string.slice(0, 4);
|
||||
mnc_raw = lbs_string.slice(4, 6);
|
||||
lac_raw = lbs_string.slice(6, 10);
|
||||
cellID_raw = lbs_string.slice(10, 16);
|
||||
}
|
||||
// from alarm
|
||||
else if (lbs_string.length == 18) {
|
||||
lbs_length_raw = lbs_string.slice(0, 2);
|
||||
mcc_raw = lbs_string.slice(2, 6);
|
||||
mnc_raw = lbs_string.slice(6, 8);
|
||||
lac_raw = lbs_string.slice(8, 12);
|
||||
cellID_raw = lbs_string.slice(12, 18);
|
||||
}
|
||||
|
||||
if (lbs_length_raw) {
|
||||
lbs_length = parseInt(lbs_length_raw, 16);
|
||||
}
|
||||
if (mnc_raw && mcc_raw && lac_raw && cellID_raw) {
|
||||
mnc = parseInt(mnc_raw, 16);
|
||||
mcc = parseInt(mcc_raw, 16);
|
||||
lac = parseInt(lac_raw, 16);
|
||||
cellID = parseInt(cellID_raw, 16);
|
||||
}
|
||||
|
||||
const data = {
|
||||
lbs_length_raw,
|
||||
lbs_length,
|
||||
mcc_raw,
|
||||
mcc,
|
||||
mnc_raw,
|
||||
mnc,
|
||||
lac_raw,
|
||||
lac,
|
||||
cellID_raw,
|
||||
cellID,
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static gt06ParseStatusAlarm(me, stts_string) {
|
||||
if (!stts_string) {
|
||||
stts_string = me.ori_string.slice(8).slice(54, 10);
|
||||
}
|
||||
|
||||
let terminal_info_raw = stts_string.slice(0, 2);
|
||||
let tib1 = LibHelper.hex2bin(terminal_info_raw); // terminal_info_byte1
|
||||
let tib1_bit7 = tib1.slice(0, 1);
|
||||
let tib1_bit6 = tib1.slice(1, 2);
|
||||
let tib1_bit5 = tib1.slice(2, 3);
|
||||
let tib1_bit4 = tib1.slice(3, 4);
|
||||
let tib1_bit3 = tib1.slice(4, 5);
|
||||
let tib1_bit2 = tib1.slice(5, 6);
|
||||
let tib1_bit1 = tib1.slice(6, 7);
|
||||
let tib1_bit0 = tib1.slice(7, 8);
|
||||
|
||||
/**
|
||||
* 0: No Power (shutdown)
|
||||
* 1: Extremely Low Battery (not enough for calling or sending text messages, etc.)
|
||||
* 2: Very Low Battery (Low Battery Alarm)
|
||||
* 3: Low Battery (can be used normally)
|
||||
* 4: Medium
|
||||
* 5: High
|
||||
* 6: Very High
|
||||
*/
|
||||
let voltage_level = stts_string.slice(2, 4);
|
||||
|
||||
let gsm_signal_strength = stts_string.slice(4, 6);
|
||||
|
||||
let alarm_stts = stts_string.slice(6, 8); // former bit: terminal alarm status (suitable for alarm packet and electronic fence project)
|
||||
let language = stts_string.slice(8, 10); // latter bit: the current language used in the terminal
|
||||
|
||||
const data = {
|
||||
terminal_info_raw: terminal_info_raw,
|
||||
terminal_info_byte: tib1,
|
||||
terminal_info: {
|
||||
oil_electricity: tib1_bit7, // 1: oil and electricity disconnected, 0: gas oil and electricity connected
|
||||
gps_tracking: tib1_bit6, // 1: GPS tracking is on, 0: GPS tracking is off
|
||||
stts: `${tib1_bit5}${tib1_bit4}${tib1_bit3}`, // 100: SOS, 011: Low Battery Alarm, 010: Power Cut Alarm, 001: Shock Alarm, 000: Normal
|
||||
charge: tib1_bit2, // 1: Charge On, 0: Charge Off
|
||||
acc: tib1_bit1, // 1: ACC high, 0: ACC Low
|
||||
is_active: tib1_bit0, // 1: Activated, 0: Deactivated
|
||||
},
|
||||
voltage_level,
|
||||
gsm_signal_strength, // 0x00: no signal; 0x01: extremely weak signal; 0x02: very weak signal; 0x03: good signal; 0x04: strong signal.
|
||||
alarm_stts, // 0x00: normal, 0x01: SOS, 0x02: Power Cut Alarm, 0x03: Shock Alarm, 0x04: Fence In Alarm, 0x05: Fence Out Alarm
|
||||
language, // 0x01: Chinese, 0x02: English
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static gt06AlarmResp(me) {
|
||||
return Buffer.from("787805160001d9dc0d0a", "hex");
|
||||
}
|
||||
|
||||
static eelinkCustomAction(me, device_id = null) {
|
||||
const act = {
|
||||
device_id: me.field1,
|
||||
action_type: 'exist_data',
|
||||
cmd: 'exist_data',
|
||||
}
|
||||
|
||||
if (me.field3 == '60000000' || me.field3 == '00000000') {
|
||||
act.action_type = 'no_data_since_hardware_reset';
|
||||
act.cmd = 'no_data_since_hardware_reset';
|
||||
|
||||
// act.buffer_resp = Buffer.from('LOAD');
|
||||
// act.buffer_resp = 'LOAD';
|
||||
// act.buffer_resp = Buffer.from(`6767${me.field0}000A0001${me.field1}01`, 'hex');
|
||||
// act.buffer_resp = `6767${me.field0}000A0001${me.field1}01`;
|
||||
}
|
||||
|
||||
if (act.action_type !== 'exist_data') return act;
|
||||
|
||||
act.flag = me.field0;
|
||||
act.imsi = me.field2; // International Mobile Subscriber Identifier
|
||||
|
||||
act.time_string = me.field3;
|
||||
const time_data = {};
|
||||
time_data.year = '20' + (parseInt(me.field3.slice(0, 1), 16) + 10);
|
||||
time_data.month = '' + parseInt(me.field3.slice(1, 2), 16);
|
||||
if (time_data.month.length === 1) { time_data.month = '0' + time_data.month; }
|
||||
time_data.day = '' + parseInt(me.field3.slice(2, 4), 16);
|
||||
if (time_data.day.length === 1) { time_data.day = '0' + time_data.day; }
|
||||
time_data.hour = '' + parseInt(me.field3.slice(4, 6), 16);
|
||||
if (time_data.hour.length === 1) { time_data.hour = '0' + time_data.hour; }
|
||||
time_data.minute = '' + parseInt(me.field3.slice(6, 8), 16);
|
||||
if (time_data.minute.length === 1) { time_data.minute = '0' + time_data.minute; }
|
||||
act.time_data = time_data;
|
||||
|
||||
/**
|
||||
* north => -9000000 to +9000000, can 1 or 2 digits of degree
|
||||
* west => -18000000 to +18000000, usually 3 digits degree
|
||||
*/
|
||||
act.location_string = me.field4;
|
||||
// original value is expressed as signed hex value, so we must to conversion to decimal
|
||||
// using two complement
|
||||
let north = ~parseInt(me.field4.slice(0, 8), 16);
|
||||
let west = ~parseInt(me.field4.slice(8, 16), 16);
|
||||
// add magnitude
|
||||
north = north * -1 + 1;
|
||||
west = west * -1 + 1;
|
||||
// convert to string
|
||||
north += '';
|
||||
west += '';
|
||||
// remove - from string at first and save to temporary variable
|
||||
let signedNorth = '';
|
||||
if (north.indexOf('-') === 0) {
|
||||
north = north.slice(1);
|
||||
signedNorth = '-';
|
||||
}
|
||||
let signedWest = '';
|
||||
if (west.indexOf('-') === 0) {
|
||||
west = west.slice(1);
|
||||
signedWest = '-';
|
||||
}
|
||||
// separate DDM => Degree Decimal Minutes
|
||||
let northDegree = north.slice(0, 1);
|
||||
let northDecimalMinute = north.slice(1, 7);
|
||||
if (north.length === 8) {
|
||||
northDegree = north.slice(0, 2);
|
||||
northDecimalMinute = north.slice(2, 7);
|
||||
}
|
||||
let westDegree = west.slice(0, 3);
|
||||
let westDecimalMinute = west.slice(3, 7);
|
||||
// convert DDM to DD (Decimal Degrees)
|
||||
act.latitude = '' + signedNorth + northDegree + '.' + ('' + (northDecimalMinute/60)).replace('.', '');
|
||||
act.longitude = '' + signedWest + westDegree + '.' + ('' + (westDecimalMinute/60)).replace('.', '');
|
||||
|
||||
return act;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LibDevice;
|
||||
45
library/LibFile.js
Normal file
45
library/LibFile.js
Normal file
@ -0,0 +1,45 @@
|
||||
const fs = require('fs');
|
||||
const path = require("path");
|
||||
|
||||
const STORAGE_PATH = path.join(__dirname, '../files/storage/');
|
||||
|
||||
class LibFile {
|
||||
static save(filename, dirpath, rawBase64) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const cleanBase64 = rawBase64.replace(/^data:(image|application)\/(png|jpg|jpeg);base64,/, '');
|
||||
const saveLocation = `${STORAGE_PATH}${dirpath}/${filename}`;
|
||||
|
||||
LibFile.ensureDirectoryExistence(saveLocation);
|
||||
|
||||
fs.writeFile(saveLocation, cleanBase64, 'base64', function (err) {
|
||||
if (err) return reject(err);
|
||||
resolve(`${dirpath}/${filename}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static ensureDirectoryExistence(filePath) {
|
||||
var dirname = path.dirname(filePath);
|
||||
if (fs.existsSync(dirname)) {
|
||||
return true;
|
||||
}
|
||||
LibFile.ensureDirectoryExistence(dirname);
|
||||
fs.mkdirSync(dirname);
|
||||
}
|
||||
|
||||
static remove(filenamepath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const removeLocation = `${STORAGE_PATH}${filenamepath}`;
|
||||
// if not exists mean, have been deleted
|
||||
if (!fs.existsSync(removeLocation)) return resolve(true);
|
||||
// if exist mean not deleted
|
||||
fs.unlink(removeLocation, function(err) {
|
||||
if (err) return reject(err);
|
||||
resolve(true);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LibFile;
|
||||
72
library/LibFirebase.js
Normal file
72
library/LibFirebase.js
Normal file
@ -0,0 +1,72 @@
|
||||
const fs = require('fs');
|
||||
const path = require("path");
|
||||
const firebase = require('firebase-admin');
|
||||
|
||||
// const account = fs.readFileSync(path.join(__dirname, '../files/keys/bingcorp-tracker-firebase-adminsdk-7tcet-7399bbf4fc.json')); // jadinya buffer
|
||||
const account = require(path.join(__dirname, '../files/keys/bingcorp-tracker-firebase-adminsdk-7tcet-7399bbf4fc.json')); // langsung json
|
||||
const firebaseAdmin = firebase.initializeApp({
|
||||
credential: firebase.credential.cert(account),
|
||||
databaseURL: 'https://bingcorp-tracker-default-rtdb.asia-southeast1.firebasedatabase.app',
|
||||
});
|
||||
|
||||
class LibFirebase {
|
||||
|
||||
static upLocActiveOrder = 1;
|
||||
static upPhotoOtwDrop = 2;
|
||||
static upLocIdle = 3;
|
||||
static scTfMoney = 6; // success transfer pocket money to driver
|
||||
static blastNotif = 7; // notif per 6jam semua driver baik ada order / kaga
|
||||
|
||||
firebaseAdmin = null;
|
||||
|
||||
firebaseInit() {
|
||||
const firebase = require('firebase-admin');
|
||||
// const account = fs.readFileSync(path.join(__dirname, '../files/keys/bingcorp-tracker-firebase-adminsdk-7tcet-7399bbf4fc.json')); // jadinya buffer
|
||||
const account = require(path.join(__dirname, '../files/keys/bingcorp-tracker-firebase-adminsdk-7tcet-7399bbf4fc.json')); // langsung json
|
||||
return firebase.initializeApp({
|
||||
credential: firebase.credential.cert(account),
|
||||
databaseURL: 'https://bingcorp-tracker-default-rtdb.asia-southeast1.firebasedatabase.app',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* https://firebase.google.com/docs/cloud-messaging/send-message
|
||||
* https://firebase.google.com/docs/reference/admin/node/firebase-admin.messaging.messaging#messagingsendtodevice
|
||||
*
|
||||
* https://firebase.google.com/docs/reference/admin/node/firebase-admin.messaging.messagingoptions.md#messagingoptions_interface
|
||||
*/
|
||||
sendToDevice(registrationToken = '', payload = {}, options = {}) {
|
||||
// const obj = this;
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
// console.log('check value => ', obj.firebaseAdmin);
|
||||
// if (obj.firebaseAdmin === null) {
|
||||
// // obj.firebaseAdmin = this.firebaseInit();
|
||||
// obj.firebaseAdmin = 'udah di assign';
|
||||
// }
|
||||
// console.log('check value => ', obj.firebaseAdmin);
|
||||
if (!options['priority']) {
|
||||
options.priority = 'normal';
|
||||
}
|
||||
if (!options['timeToLive']) {
|
||||
options.timeToLive = 60 * 60 * 24;
|
||||
}
|
||||
const response = await firebaseAdmin.messaging().sendToDevice(registrationToken, payload, options);
|
||||
resolve(response);
|
||||
// {
|
||||
// results: [ { error: [FirebaseMessagingError] } ],
|
||||
// canonicalRegistrationTokenCount: 0,
|
||||
// failureCount: 1,
|
||||
// successCount: 0,
|
||||
// multicastId: 7795206774601661000
|
||||
// }
|
||||
} catch (err) {
|
||||
console.log('error sending message');
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LibFirebase;
|
||||
97
library/LibHelper.js
Normal file
97
library/LibHelper.js
Normal file
@ -0,0 +1,97 @@
|
||||
class LibHelper {
|
||||
|
||||
static EARTH_RADIUS_M = 6371000;
|
||||
static EARTH_RADIUS_KM = 6371;
|
||||
static EARTH_RADIUS_MILES = 3959; // 3958.756 || 3959 || 3963
|
||||
|
||||
static setErrMsg(msg) {
|
||||
if (process.env.NODE_ENV == 'development') {
|
||||
return msg;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the great-circle distance between two points, with
|
||||
* the Haversine formula.
|
||||
* @param float latitudeFrom Latitude of start point in [deg decimal]
|
||||
* @param float longitudeFrom Longitude of start point in [deg decimal]
|
||||
* @param float latitudeTo Latitude of target point in [deg decimal]
|
||||
* @param float longitudeTo Longitude of target point in [deg decimal]
|
||||
* @param float earthRadius Mean earth radius in [m]
|
||||
* @return float Distance between points in [m] (same as earthRadius)
|
||||
* reference: https://stackoverflow.com/questions/14750275/haversine-formula-with-php
|
||||
* tolak ukur: tarik garis lurus
|
||||
* more accurate using km/meters than miles i think ~ rafifmulia
|
||||
*/
|
||||
static haversineGreatCircleDistance(latFrom, lngFrom, latTo, lngTo, earthRadius = LibHelper.EARTH_RADIUS_M) {
|
||||
// convert from degrees to radians
|
||||
let latFromRads = LibHelper.degsToRads(latFrom);
|
||||
let lngFromRads = LibHelper.degsToRads(lngFrom);
|
||||
let latToRads = LibHelper.degsToRads(latTo);
|
||||
let lngToRads = LibHelper.degsToRads(lngTo);
|
||||
|
||||
let latDelta = latToRads - latFromRads;
|
||||
let lngDelta = lngToRads - lngFromRads;
|
||||
|
||||
let angle = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(latDelta / 2), 2) + Math.cos(latFromRads) * Math.cos(latToRads) * Math.pow(Math.sin(lngDelta / 2), 2)));
|
||||
let distance = angle * earthRadius;
|
||||
|
||||
return distance;
|
||||
}
|
||||
|
||||
// reference: https://www.codegrepper.com/code-examples/javascript/deg2rad+javascript
|
||||
// degrees to radians
|
||||
static degsToRads(deg) {
|
||||
return (deg * Math.PI) / 180.0;
|
||||
}
|
||||
// radians to degrees
|
||||
static radsToDegs(rad) {
|
||||
return rad * 180.0 / Math.PI;
|
||||
}
|
||||
|
||||
// round up with precisions digits => 4 == (10000)
|
||||
// reference: https://stackoverflow.com/questions/11832914/how-to-round-to-at-most-2-decimal-places-if-necessary
|
||||
static milesToKm(miles, precisionDigits = 10000) {
|
||||
return Math.round(((miles * 1.609) + Number.EPSILON) * precisionDigits) / precisionDigits;
|
||||
}
|
||||
static milesToMeters(miles, precisionDigits = 10000) {
|
||||
return Math.round(((miles * 1609) + Number.EPSILON) * precisionDigits) / precisionDigits;
|
||||
}
|
||||
static milesToMiles(meters, precisionDigits = 10000) {
|
||||
return Math.round(((meters) + Number.EPSILON) * precisionDigits) / precisionDigits;
|
||||
}
|
||||
static kmToMiles(km, precisionDigits = 10000) {
|
||||
return Math.round(((km / 1.609) + Number.EPSILON) * precisionDigits) / precisionDigits;
|
||||
}
|
||||
static kmToMeters(km, precisionDigits = 10000) {
|
||||
return Math.round(((km * 1000) + Number.EPSILON) * precisionDigits) / precisionDigits;
|
||||
}
|
||||
static kmToKm(meters, precisionDigits = 10000) {
|
||||
return Math.round(((meters) + Number.EPSILON) * precisionDigits) / precisionDigits;
|
||||
}
|
||||
static metersToKm(meters, precisionDigits = 10000) {
|
||||
return Math.round(((meters / 1000) + Number.EPSILON) * precisionDigits) / precisionDigits;
|
||||
}
|
||||
static metersToMiles(meters, precisionDigits = 10000) {
|
||||
return Math.round(((meters / 1609) + Number.EPSILON) * precisionDigits) / precisionDigits;
|
||||
}
|
||||
static metersToMeters(meters, precisionDigits = 10000) {
|
||||
return Math.round(((meters) + Number.EPSILON) * precisionDigits) / precisionDigits;
|
||||
}
|
||||
|
||||
static hex2bin(hex) {
|
||||
return ("00000000" + (parseInt(hex, 16)).toString(2)).slice(-8);
|
||||
}
|
||||
|
||||
static splitEvery4Char(str) {
|
||||
if (str) {
|
||||
str = '' + str;
|
||||
let splitEvery4Char = str.match(/.{1,4}/g)
|
||||
return splitEvery4Char.join(' ')
|
||||
}
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = LibHelper;
|
||||
140
library/LibImgGeotagging.js
Normal file
140
library/LibImgGeotagging.js
Normal file
@ -0,0 +1,140 @@
|
||||
const fs = require('fs');
|
||||
const path = require("path");
|
||||
const moment = require('moment');
|
||||
const Jimp = require("jimp");
|
||||
|
||||
/**
|
||||
* download ttf font => https://www.fontspace.com/search?q=open%20sans
|
||||
* load custom font on jimp => https://github.com/oliver-moran/jimp/issues/375
|
||||
* convert ttf to (fnt,png) => https://github.com/oliver-moran/jimp/issues/1002 => https://ttf2fnt.com/
|
||||
* neon color palette => https://icolorpalette.com/color/neon-green
|
||||
* reference => https://libgdx.com/wiki/graphics/2d/fonts/bitmap-fonts
|
||||
*/
|
||||
const FONT_OPEN_SANS_NEON_100 = path.resolve(__dirname, '../files/public/OpenSans-B9K8.ttf_neon_100/neon_100.fnt');
|
||||
const FONT_OPEN_SANS_NEON_64 = path.resolve(__dirname, '../files/public/OpenSans-B9K8.ttf_neon_64/neon_64.fnt');
|
||||
const FONT_OPEN_SANS_NEON_32 = path.resolve(__dirname, '../files/public/OpenSans-B9K8.ttf_neon_32/neon_32.fnt');
|
||||
const FONT_OPEN_SANS_NEON_16 = path.resolve(__dirname, '../files/public/OpenSans-B9K8.ttf_neon_16/neon_16.fnt');
|
||||
|
||||
class LibImgGeotagging {
|
||||
|
||||
static create(tempFileName = '', tempFileNamePath = '', photo = 'base64', { fulladdress, lat, lng, photo_at }) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const JimpLoadedFile = await Jimp.read(Buffer.from(photo.replace(/^data:(image|application)\/(png|jpg|jpeg);base64,/, ''), 'base64'));
|
||||
JimpLoadedFile.quality(60);
|
||||
fulladdress = (fulladdress) ? decodeURIComponent(fulladdress) : null;
|
||||
let theAddr = fulladdress || '';
|
||||
let text = moment.unix(photo_at).format('DD MMMM YYYY HH:mm:ss') + ' WIB' + ' ' + lat + ',' + lng + ' ' + theAddr;
|
||||
let startX = 10;
|
||||
let startY = 10;
|
||||
// example 00
|
||||
// const JimpLoadFont = await Jimp.loadFont(Jimp.FONT_SANS_64_WHITE);
|
||||
// await JimpLoadedFile
|
||||
// // .print(JimpLoadFont, startX, JimpLoadedFile.bitmap.height-450, { text }, JimpLoadedFile.bitmap.width)
|
||||
// .print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * 75 / 100, JimpLoadedFile.bitmap.height)
|
||||
// // .print(JimpLoadFont, startX, startY, { text: moment.unix(photo_at).format('YYYY-MM-DD HH:mm:ss') + ' WIB', alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width, JimpLoadedFile.bitmap.height)
|
||||
// // .print(JimpLoadFont, startX, startY, { text: '' + lat + ',' + lng, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width, JimpLoadedFile.bitmap.height)
|
||||
// // .print(JimpLoadFont, startX, startY, { text: `${theAddr}`, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width, JimpLoadedFile.bitmap.height)
|
||||
// .writeAsync(tempFileNamePath);
|
||||
|
||||
// example with set background with opacity 01
|
||||
// const imgBg = Buffer.from(fs.readFileSync(path.resolve(__dirname, '../files/public/img_white_bg.png'))).toString('base64');
|
||||
// const JimpImgBg = await Jimp.read(Buffer.from(imgBg.replace(/^data:(image|application)\/(png|jpg|jpeg);base64,/, ''), 'base64'));
|
||||
// const JimpLoadFont = (JimpLoadedFile.bitmap.height > 1000) ? await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK) : await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);
|
||||
// await JimpLoadedFile
|
||||
// .composite(JimpImgBg, 0, JimpLoadedFile.bitmap.height-200, { mode: Jimp.BLEND_SOURCE_OVER, opacitySource: 0.5, opacityDest: 1 })
|
||||
// .print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * percent / 100, JimpLoadedFile.bitmap.height)
|
||||
// .writeAsync(tempFileNamePath);
|
||||
|
||||
// write geotagging based on size
|
||||
// https://www.pixel.web.id/ukuran-foto-sesuai-standar/
|
||||
// font color => https://www.fontspace.com/search?q=open%20sans
|
||||
/**
|
||||
* kalo height <= 600px maka metode maka jadikan satu baru menggunakan alignmentX dan Y
|
||||
* kalo height > 600px maka metode print pecah jadi 3 baris dan pake minus(-) di startY, misal -300 -200 -100
|
||||
*/
|
||||
console.log('image width => ', JimpLoadedFile.bitmap.width, ' || ', 'image height => ', JimpLoadedFile.bitmap.height);
|
||||
const percent = (JimpLoadedFile.bitmap.height > 1000) ? 75 : 50;
|
||||
if (JimpLoadedFile.bitmap.width > 3000) {
|
||||
startY = -10;
|
||||
const JimpLoadFont = (JimpLoadedFile.bitmap.height > 1000) ? await Jimp.loadFont(FONT_OPEN_SANS_NEON_100) : await Jimp.loadFont(FONT_OPEN_SANS_NEON_64);
|
||||
await JimpLoadedFile
|
||||
.print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * percent / 100, JimpLoadedFile.bitmap.height)
|
||||
.writeAsync(tempFileNamePath);
|
||||
} else if (JimpLoadedFile.bitmap.width > 2400) {
|
||||
startY = -10;
|
||||
const JimpLoadFont = (JimpLoadedFile.bitmap.height > 1000) ? await Jimp.loadFont(FONT_OPEN_SANS_NEON_64) : await Jimp.loadFont(FONT_OPEN_SANS_NEON_64);
|
||||
await JimpLoadedFile
|
||||
.print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * percent / 100, JimpLoadedFile.bitmap.height)
|
||||
.writeAsync(tempFileNamePath);
|
||||
} else if (JimpLoadedFile.bitmap.width > 2100) {
|
||||
startY = -10;
|
||||
const JimpLoadFont = (JimpLoadedFile.bitmap.height > 1000) ? await Jimp.loadFont(FONT_OPEN_SANS_NEON_64) : await Jimp.loadFont(FONT_OPEN_SANS_NEON_64);
|
||||
await JimpLoadedFile
|
||||
.print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * percent / 100, JimpLoadedFile.bitmap.height)
|
||||
.writeAsync(tempFileNamePath);
|
||||
} else if (JimpLoadedFile.bitmap.width > 1800) {
|
||||
// done testing
|
||||
startY = -10;
|
||||
const JimpLoadFont = (JimpLoadedFile.bitmap.height > 1000) ? await Jimp.loadFont(FONT_OPEN_SANS_NEON_64) : await Jimp.loadFont(FONT_OPEN_SANS_NEON_32);
|
||||
await JimpLoadedFile
|
||||
.print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * percent / 100, JimpLoadedFile.bitmap.height)
|
||||
.writeAsync(tempFileNamePath);
|
||||
} else if (JimpLoadedFile.bitmap.width > 1650) {
|
||||
startY = -10;
|
||||
const JimpLoadFont = (JimpLoadedFile.bitmap.height > 1000) ? await Jimp.loadFont(FONT_OPEN_SANS_NEON_32) : await Jimp.loadFont(FONT_OPEN_SANS_NEON_32);
|
||||
await JimpLoadedFile
|
||||
.print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * percent / 100, JimpLoadedFile.bitmap.height)
|
||||
.writeAsync(tempFileNamePath);
|
||||
} else if (JimpLoadedFile.bitmap.width > 1500) {
|
||||
startY = -10;
|
||||
const JimpLoadFont = (JimpLoadedFile.bitmap.height > 1000) ? await Jimp.loadFont(FONT_OPEN_SANS_NEON_32) : await Jimp.loadFont(FONT_OPEN_SANS_NEON_32);
|
||||
await JimpLoadedFile
|
||||
.print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * percent / 100, JimpLoadedFile.bitmap.height)
|
||||
.writeAsync(tempFileNamePath);
|
||||
} else if (JimpLoadedFile.bitmap.width > 1200) {
|
||||
startY = -10;
|
||||
const JimpLoadFont = (JimpLoadedFile.bitmap.height > 1000) ? await Jimp.loadFont(FONT_OPEN_SANS_NEON_32) : await Jimp.loadFont(FONT_OPEN_SANS_NEON_32);
|
||||
await JimpLoadedFile
|
||||
.print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * percent / 100, JimpLoadedFile.bitmap.height)
|
||||
.writeAsync(tempFileNamePath);
|
||||
} else if (JimpLoadedFile.bitmap.width > 900) {
|
||||
// done testing
|
||||
startY = -10;
|
||||
const JimpLoadFont = (JimpLoadedFile.bitmap.height > 1000) ? await Jimp.loadFont(FONT_OPEN_SANS_NEON_32) : await Jimp.loadFont(FONT_OPEN_SANS_NEON_32);
|
||||
await JimpLoadedFile
|
||||
.print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * percent / 100, JimpLoadedFile.bitmap.height)
|
||||
.writeAsync(tempFileNamePath);
|
||||
} else if (JimpLoadedFile.bitmap.width > 750) {
|
||||
// done testing
|
||||
startX = 8;
|
||||
startY = -8;
|
||||
const JimpLoadFont = (JimpLoadedFile.bitmap.height > 1000) ? await Jimp.loadFont(FONT_OPEN_SANS_NEON_32) : await Jimp.loadFont(FONT_OPEN_SANS_NEON_16);
|
||||
await JimpLoadedFile
|
||||
.print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * percent / 100, JimpLoadedFile.bitmap.height)
|
||||
.writeAsync(tempFileNamePath);
|
||||
} else if (JimpLoadedFile.bitmap.width > 400) {
|
||||
startX = 5;
|
||||
startY = -5;
|
||||
const JimpLoadFont = (JimpLoadedFile.bitmap.height > 1000) ? await Jimp.loadFont(FONT_OPEN_SANS_NEON_16) : await Jimp.loadFont(FONT_OPEN_SANS_NEON_16);
|
||||
await JimpLoadedFile
|
||||
.print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * percent / 100, JimpLoadedFile.bitmap.height)
|
||||
.writeAsync(tempFileNamePath);
|
||||
} else {
|
||||
startX = 5;
|
||||
startY = -5;
|
||||
const JimpLoadFont = (JimpLoadedFile.bitmap.height > 1000) ? await Jimp.loadFont(FONT_OPEN_SANS_NEON_16) : await Jimp.loadFont(FONT_OPEN_SANS_NEON_16);
|
||||
await JimpLoadedFile
|
||||
.print(JimpLoadFont, startX, startY, { text, alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT, alignmentY: Jimp.VERTICAL_ALIGN_BOTTOM }, JimpLoadedFile.bitmap.width * percent / 100, JimpLoadedFile.bitmap.height)
|
||||
.writeAsync(tempFileNamePath);
|
||||
}
|
||||
resolve({type: 'sc'});
|
||||
} catch (e) {
|
||||
reject({type: 'err', e});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LibImgGeotagging;
|
||||
55
library/LibJwt.js
Normal file
55
library/LibJwt.js
Normal file
@ -0,0 +1,55 @@
|
||||
const jwt = require('jsonwebtoken');
|
||||
const cryptojs = require("crypto-js");
|
||||
|
||||
const confJwt = {
|
||||
algorithm: 'HS256',
|
||||
issuer: 'BINGCORP',
|
||||
subject: 'APP_DRIVER',
|
||||
audience: 'MOBILE',
|
||||
// expiresIn: '365d',
|
||||
};
|
||||
const SECRET_KEY = 'BINGCORP';
|
||||
const KEY_ENC = 'dRgUjXn2r5u8x/A?D(G+KbPeShVmYp3s'; // just random string
|
||||
|
||||
class LibJwt {
|
||||
|
||||
static async createToken(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// mengapa data perlu di enc lagi ? karena di jwt data tersebut hanya di base64_enc
|
||||
let cipherText = cryptojs.AES.encrypt(JSON.stringify(data), KEY_ENC).toString();
|
||||
let payload = {
|
||||
cipherText,
|
||||
};
|
||||
|
||||
jwt.sign(payload, SECRET_KEY, confJwt, function (err, token) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve({ type: 'success', token });
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
static async verifyToken(token) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
jwt.verify(token, SECRET_KEY, confJwt, function (err, decoded) {
|
||||
if (err) {
|
||||
resolve({ type: 'fail', message: err.message });
|
||||
return false;
|
||||
}
|
||||
const { cipherText } = decoded;
|
||||
let bytes = cryptojs.AES.decrypt(cipherText, KEY_ENC);
|
||||
let dataDecoded = JSON.parse(bytes.toString(cryptojs.enc.Utf8));
|
||||
resolve({ type: 'success', data: dataDecoded });
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LibJwt;
|
||||
28
library/LibLogReqResApi.js
Normal file
28
library/LibLogReqResApi.js
Normal file
@ -0,0 +1,28 @@
|
||||
const LibWinston = require('./LibWinston');
|
||||
const Logger = LibWinston.initialize('req_res_api');
|
||||
|
||||
class LibLogReqResApi {
|
||||
|
||||
static async log(req, apiRes) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
delete req.body.photo;
|
||||
const payload = {
|
||||
url: req.originalUrl,
|
||||
auth: req.auth,
|
||||
params: req.params,
|
||||
query: req.query,
|
||||
body: req.body,
|
||||
resp: apiRes,
|
||||
};
|
||||
Logger.log('info', `${JSON.stringify(payload)}`);
|
||||
resolve(true);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LibLogReqResApi;
|
||||
1163
library/LibMail.js
Normal file
1163
library/LibMail.js
Normal file
File diff suppressed because it is too large
Load Diff
206
library/LibMysqlHelper.js
Normal file
206
library/LibMysqlHelper.js
Normal file
@ -0,0 +1,206 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
// const Promise = require("bluebird");
|
||||
|
||||
class MysqlHelpers {
|
||||
static async insert (table, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO ${table} SET ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, data, function (err, result) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Number(result.insertId);
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(result);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
})
|
||||
}
|
||||
static async update (table, data, colId, valId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `UPDATE ${table} SET ? WHERE ${colId} = ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, [data, valId], function (err, result) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(result);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
})
|
||||
}
|
||||
static async delete (table, colId, valId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `DELETE FROM ${table} WHERE ${colId} = ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, [valId], function (err, result) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(result);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
})
|
||||
}
|
||||
static async createConnection () {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
if (conn) conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(conn);
|
||||
});
|
||||
})
|
||||
}
|
||||
static async getDbMysqlConn () {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(db);
|
||||
})
|
||||
}
|
||||
static async releaseConnection (conn) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (conn) conn.release();
|
||||
resolve(true);
|
||||
})
|
||||
}
|
||||
static async createTrx (conn) {
|
||||
return new Promise((resolve, reject) => {
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(conn);
|
||||
});
|
||||
})
|
||||
}
|
||||
static async queryTrx (conn, query = '', params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
conn.query(query, params, function (err, result) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Number(result.insertId);
|
||||
resolve(result);
|
||||
});
|
||||
})
|
||||
}
|
||||
static async query (conn, query = '', params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
conn.query(query, params, function (err, result) {
|
||||
if (err) return reject(err);
|
||||
// Number(result.insertId);
|
||||
resolve(result);
|
||||
});
|
||||
})
|
||||
}
|
||||
static async commit (conn) {
|
||||
return new Promise((resolve, reject) => {
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(true);
|
||||
});
|
||||
})
|
||||
}
|
||||
static async rollback (conn) {
|
||||
return new Promise((resolve, reject) => {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err);
|
||||
});
|
||||
return false;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MysqlHelpers;
|
||||
39
library/LibPassword.js
Normal file
39
library/LibPassword.js
Normal file
@ -0,0 +1,39 @@
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
const saltRounds = 10;
|
||||
|
||||
class LibPassword {
|
||||
|
||||
static async hashPw(plainTextPassword) {
|
||||
return new Promise((resolve, reject) => {
|
||||
bcrypt.genSalt(saltRounds, function (err, salt) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
bcrypt.hash(plainTextPassword, salt, function (err, hash) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(hash);
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
static async checkPw(hash, plainText) {
|
||||
return new Promise((resolve, reject) => {
|
||||
bcrypt.compare(plainText, hash, function (err, result) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(result);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LibPassword;
|
||||
82
library/LibQueueBlastOrder.js
Normal file
82
library/LibQueueBlastOrder.js
Normal file
@ -0,0 +1,82 @@
|
||||
const path = require('path');
|
||||
const RedisConn = require('./LibRedisConn');
|
||||
const QueueMQ = require('bullmq').Queue;
|
||||
const QueueSchedulerMQ = require('bullmq').QueueScheduler;
|
||||
const WorkerMQ = require('bullmq').Worker;
|
||||
// const JobMQ = require('bullmq').Job;
|
||||
const LibWinston = require('./LibWinston');
|
||||
const EventEmitter = require('events');
|
||||
|
||||
const queueName = process.env.REDIS_QUEUE_BLAST_ORDER;
|
||||
const theQueue = new QueueMQ(queueName, { connection: RedisConn });
|
||||
const theQueueScheduler = new QueueSchedulerMQ(queueName, { connection: RedisConn });
|
||||
|
||||
const Logger = LibWinston.initialize(queueName);
|
||||
|
||||
class MyEmitter extends EventEmitter { };
|
||||
const myEmitter = new MyEmitter();
|
||||
|
||||
/**
|
||||
* bisa multiple queue tanpa new Queue(name) lagi, tinggal dibedain aja nama processornya ketika queue.add(nameProcessor)
|
||||
* worker hanya memproses nama sesuai dengan nameProcessor bukan nama ketika new Queue(name)
|
||||
* concurrency di worker adalah maksimal yang bisa diproses dalam satu waktu bersamaan
|
||||
* attempts di queue adalah maksimal percobaan ketika gagal
|
||||
*/
|
||||
|
||||
const LibQueueBlastOrder = {
|
||||
name: queueName,
|
||||
queue: theQueue,
|
||||
addQueue: function (data) {
|
||||
this.queue.add(queueName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
delay: data.delay,
|
||||
});
|
||||
},
|
||||
pauseQueue: function () {
|
||||
this.queue.pause();
|
||||
},
|
||||
resumeQueue: function () {
|
||||
this.queue.resume();
|
||||
},
|
||||
getJobs: async function () {
|
||||
return await this.queue.getJobs();
|
||||
},
|
||||
getRepeatableJobs: async function () {
|
||||
return await this.queue.getRepeatableJobs();
|
||||
},
|
||||
setWorker: function () {
|
||||
try {
|
||||
const processorFile = path.join(__dirname, '../workers/BlastOrderWorker.js');
|
||||
const schedulerWorker = new WorkerMQ(queueName, processorFile, {
|
||||
connection: RedisConn,
|
||||
concurrency: 1,
|
||||
})
|
||||
schedulerWorker.on('completed', async (job, returnValue) => {
|
||||
Logger.log('info', `${queueName} completed: ${JSON.stringify(returnValue)}`);
|
||||
})
|
||||
schedulerWorker.on('failed', async (job, failedReason) => {
|
||||
Logger.log('error', `${queueName} failed: ${JSON.stringify(failedReason)}`);
|
||||
});
|
||||
schedulerWorker.on('error', async (errMsg) => {
|
||||
Logger.log('error', `${queueName} error: ${JSON.stringify(errMsg)}`);
|
||||
});
|
||||
myEmitter.on(queueName + 'ShutDown', () => {
|
||||
// gracefull shutdown
|
||||
schedulerWorker.close();
|
||||
});
|
||||
} catch (e) {
|
||||
Logger.log('error', `${queueName} worker_error: ${JSON.stringify(e, Object.getOwnPropertyNames(e))}`);
|
||||
}
|
||||
},
|
||||
drainQueue: function () {
|
||||
this.queue.drain();
|
||||
},
|
||||
obliterateQueue: function () {
|
||||
this.queue.obliterate();
|
||||
},
|
||||
workerShutDown: function () {
|
||||
myEmitter.emit(queueName + 'ShutDown');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LibQueueBlastOrder
|
||||
9
library/LibRedisConn.js
Normal file
9
library/LibRedisConn.js
Normal file
@ -0,0 +1,9 @@
|
||||
const Redis = require('ioredis');
|
||||
const redisConn = new Redis({
|
||||
port: process.env.REDIS_PORT,
|
||||
host: process.env.REDIS_HOST,
|
||||
maxRetriesPerRequest: null,
|
||||
enableReadyCheck: false,
|
||||
});
|
||||
|
||||
module.exports = redisConn;
|
||||
93
library/LibSchedulerDrvBlastNotif.js
Normal file
93
library/LibSchedulerDrvBlastNotif.js
Normal file
@ -0,0 +1,93 @@
|
||||
const path = require('path');
|
||||
const RedisConn = require('./LibRedisConn');
|
||||
const QueueMQ = require('bullmq').Queue;
|
||||
const QueueSchedulerMQ = require('bullmq').QueueScheduler;
|
||||
const WorkerMQ = require('bullmq').Worker;
|
||||
// const JobMQ = require('bullmq').Job;
|
||||
const LibWinston = require('./LibWinston');
|
||||
const EventEmitter = require('events');
|
||||
|
||||
const schedulerName = process.env.REDIS_SCHEDULER_DRV_BLAST_NOTIF;
|
||||
const theQueue = new QueueMQ(schedulerName, { connection: RedisConn });
|
||||
const theQueueScheduler = new QueueSchedulerMQ(schedulerName, { connection: RedisConn });
|
||||
|
||||
const Logger = LibWinston.initialize(schedulerName);
|
||||
|
||||
class MyEmitter extends EventEmitter { };
|
||||
const myEmitter = new MyEmitter();
|
||||
|
||||
/**
|
||||
* bisa multiple queue tanpa new Queue(name) lagi, tinggal dibedain aja nama processornya ketika queue.add(nameProcessor)
|
||||
* worker hanya memproses nama sesuai dengan nameProcessor bukan nama ketika new Queue(name)
|
||||
* concurrency di worker adalah maksimal yang bisa diproses dalam satu waktu bersamaan
|
||||
* attempts di queue adalah maksimal percobaan ketika gagal
|
||||
*/
|
||||
|
||||
const LibSchedulerDrvBlastNotif = {
|
||||
name: schedulerName,
|
||||
queue: theQueue,
|
||||
runQueueScheduler: function (data) {
|
||||
// * * * * * // every minute
|
||||
// */3 * * * * // every 3 minute
|
||||
// 0 */1 * * * // every hour
|
||||
this.queue.add(schedulerName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
repeat: {
|
||||
cron: process.env.SCHEDULE_DRV_BLAST_NOTIF_TIME,
|
||||
},
|
||||
attempts: 0,
|
||||
});
|
||||
},
|
||||
addQueue: function (data) {
|
||||
this.queue.add(schedulerName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
});
|
||||
},
|
||||
pauseQueue: function () {
|
||||
this.queue.pause();
|
||||
},
|
||||
resumeQueue: function () {
|
||||
this.queue.resume();
|
||||
},
|
||||
getJobs: async function () {
|
||||
return await this.queue.getJobs();
|
||||
},
|
||||
getRepeatableJobs: async function () {
|
||||
return await this.queue.getRepeatableJobs();
|
||||
},
|
||||
setWorker: function () {
|
||||
try {
|
||||
const processorFile = path.join(__dirname, '../workers/DrvBlastNotifWorker.js');
|
||||
const schedulerWorker = new WorkerMQ(schedulerName, processorFile, {
|
||||
connection: RedisConn,
|
||||
concurrency: 1,
|
||||
})
|
||||
schedulerWorker.on('completed', async (job, returnValue) => {
|
||||
Logger.log('info', `${schedulerName} completed: ${JSON.stringify(returnValue)}`);
|
||||
})
|
||||
schedulerWorker.on('failed', async (job, failedReason) => {
|
||||
Logger.log('error', `${schedulerName} failed: ${JSON.stringify(failedReason)}`);
|
||||
});
|
||||
schedulerWorker.on('error', async (errMsg) => {
|
||||
Logger.log('error', `${schedulerName} error: ${JSON.stringify(errMsg)}`);
|
||||
});
|
||||
myEmitter.on(schedulerName + 'ShutDown', () => {
|
||||
// gracefull shutdown
|
||||
schedulerWorker.close();
|
||||
});
|
||||
} catch (e) {
|
||||
Logger.log('error', `${schedulerName} worker_error: ${JSON.stringify(e, Object.getOwnPropertyNames(e))}`);
|
||||
}
|
||||
},
|
||||
drainQueue: function () {
|
||||
this.queue.drain();
|
||||
},
|
||||
obliterateQueue: function () {
|
||||
this.queue.obliterate();
|
||||
},
|
||||
workerShutDown: function () {
|
||||
myEmitter.emit(schedulerName + 'ShutDown');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LibSchedulerDrvBlastNotif
|
||||
93
library/LibSchedulerDrvUpLoc.js
Normal file
93
library/LibSchedulerDrvUpLoc.js
Normal file
@ -0,0 +1,93 @@
|
||||
const path = require('path');
|
||||
const RedisConn = require('./LibRedisConn');
|
||||
const QueueMQ = require('bullmq').Queue;
|
||||
const QueueSchedulerMQ = require('bullmq').QueueScheduler;
|
||||
const WorkerMQ = require('bullmq').Worker;
|
||||
// const JobMQ = require('bullmq').Job;
|
||||
const LibWinston = require('./LibWinston');
|
||||
const EventEmitter = require('events');
|
||||
|
||||
const schedulerName = process.env.REDIS_SCHEDULER_DRV_UP_LOC;
|
||||
const theQueue = new QueueMQ(schedulerName, { connection: RedisConn });
|
||||
const theQueueScheduler = new QueueSchedulerMQ(schedulerName, { connection: RedisConn });
|
||||
|
||||
const Logger = LibWinston.initialize(schedulerName);
|
||||
|
||||
class MyEmitter extends EventEmitter { };
|
||||
const myEmitter = new MyEmitter();
|
||||
|
||||
/**
|
||||
* bisa multiple queue tanpa new Queue(name) lagi, tinggal dibedain aja nama processornya ketika queue.add(nameProcessor)
|
||||
* worker hanya memproses nama sesuai dengan nameProcessor bukan nama ketika new Queue(name)
|
||||
* concurrency di worker adalah maksimal yang bisa diproses dalam satu waktu bersamaan
|
||||
* attempts di queue adalah maksimal percobaan ketika gagal
|
||||
*/
|
||||
|
||||
const LibSchedulerDrvUpLoc = {
|
||||
name: schedulerName,
|
||||
queue: theQueue,
|
||||
runQueueScheduler: function (data) {
|
||||
// * * * * * // every minute
|
||||
// */3 * * * * // every 3 minute
|
||||
// 0 */1 * * * // every hour
|
||||
this.queue.add(schedulerName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
repeat: {
|
||||
cron: process.env.SCHEDULE_DRV_UP_LOC_TIME,
|
||||
},
|
||||
attempts: 0,
|
||||
});
|
||||
},
|
||||
addQueue: function (data) {
|
||||
this.queue.add(schedulerName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
});
|
||||
},
|
||||
pauseQueue: function () {
|
||||
this.queue.pause();
|
||||
},
|
||||
resumeQueue: function () {
|
||||
this.queue.resume();
|
||||
},
|
||||
getJobs: async function () {
|
||||
return await this.queue.getJobs();
|
||||
},
|
||||
getRepeatableJobs: async function () {
|
||||
return await this.queue.getRepeatableJobs();
|
||||
},
|
||||
setWorker: function () {
|
||||
try {
|
||||
const processorFile = path.join(__dirname, '../workers/DrvUpLocWorker.js');
|
||||
const schedulerWorker = new WorkerMQ(schedulerName, processorFile, {
|
||||
connection: RedisConn,
|
||||
concurrency: 1,
|
||||
})
|
||||
schedulerWorker.on('completed', async (job, returnValue) => {
|
||||
Logger.log('info', `${schedulerName} completed: ${JSON.stringify(returnValue)}`);
|
||||
})
|
||||
schedulerWorker.on('failed', async (job, failedReason) => {
|
||||
Logger.log('error', `${schedulerName} failed: ${JSON.stringify(failedReason)}`);
|
||||
});
|
||||
schedulerWorker.on('error', async (errMsg) => {
|
||||
Logger.log('error', `${schedulerName} error: ${JSON.stringify(errMsg)}`);
|
||||
});
|
||||
myEmitter.on(schedulerName + 'ShutDown', () => {
|
||||
// gracefull shutdown
|
||||
schedulerWorker.close();
|
||||
});
|
||||
} catch (e) {
|
||||
Logger.log('error', `${schedulerName} worker_error: ${JSON.stringify(e, Object.getOwnPropertyNames(e))}`);
|
||||
}
|
||||
},
|
||||
drainQueue: function () {
|
||||
this.queue.drain();
|
||||
},
|
||||
obliterateQueue: function () {
|
||||
this.queue.obliterate();
|
||||
},
|
||||
workerShutDown: function () {
|
||||
myEmitter.emit(schedulerName + 'ShutDown');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LibSchedulerDrvUpLoc
|
||||
93
library/LibSchedulerDrvUpLocIdle.js
Normal file
93
library/LibSchedulerDrvUpLocIdle.js
Normal file
@ -0,0 +1,93 @@
|
||||
const path = require('path');
|
||||
const RedisConn = require('./LibRedisConn');
|
||||
const QueueMQ = require('bullmq').Queue;
|
||||
const QueueSchedulerMQ = require('bullmq').QueueScheduler;
|
||||
const WorkerMQ = require('bullmq').Worker;
|
||||
// const JobMQ = require('bullmq').Job;
|
||||
const LibWinston = require('./LibWinston');
|
||||
const EventEmitter = require('events');
|
||||
|
||||
const schedulerName = process.env.REDIS_SCHEDULER_DRV_UP_LOC_IDLE;
|
||||
const theQueue = new QueueMQ(schedulerName, { connection: RedisConn });
|
||||
const theQueueScheduler = new QueueSchedulerMQ(schedulerName, { connection: RedisConn });
|
||||
|
||||
const Logger = LibWinston.initialize(schedulerName);
|
||||
|
||||
class MyEmitter extends EventEmitter { };
|
||||
const myEmitter = new MyEmitter();
|
||||
|
||||
/**
|
||||
* bisa multiple queue tanpa new Queue(name) lagi, tinggal dibedain aja nama processornya ketika queue.add(nameProcessor)
|
||||
* worker hanya memproses nama sesuai dengan nameProcessor bukan nama ketika new Queue(name)
|
||||
* concurrency di worker adalah maksimal yang bisa diproses dalam satu waktu bersamaan
|
||||
* attempts di queue adalah maksimal percobaan ketika gagal
|
||||
*/
|
||||
|
||||
const LibSchedulerDrvUpLocIdle = {
|
||||
name: schedulerName,
|
||||
queue: theQueue,
|
||||
runQueueScheduler: function (data) {
|
||||
// * * * * * // every minute
|
||||
// */3 * * * * // every 3 minute
|
||||
// 0 */1 * * * // every hour
|
||||
this.queue.add(schedulerName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
repeat: {
|
||||
cron: process.env.SCHEDULE_DRV_UP_LOC_IDLE_TIME,
|
||||
},
|
||||
attempts: 0,
|
||||
});
|
||||
},
|
||||
addQueue: function (data) {
|
||||
this.queue.add(schedulerName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
});
|
||||
},
|
||||
pauseQueue: function () {
|
||||
this.queue.pause();
|
||||
},
|
||||
resumeQueue: function () {
|
||||
this.queue.resume();
|
||||
},
|
||||
getJobs: async function () {
|
||||
return await this.queue.getJobs();
|
||||
},
|
||||
getRepeatableJobs: async function () {
|
||||
return await this.queue.getRepeatableJobs();
|
||||
},
|
||||
setWorker: function () {
|
||||
try {
|
||||
const processorFile = path.join(__dirname, '../workers/DrvUpLocIdleWorker.js');
|
||||
const schedulerWorker = new WorkerMQ(schedulerName, processorFile, {
|
||||
connection: RedisConn,
|
||||
concurrency: 1,
|
||||
})
|
||||
schedulerWorker.on('completed', async (job, returnValue) => {
|
||||
Logger.log('info', `${schedulerName} completed: ${JSON.stringify(returnValue)}`);
|
||||
})
|
||||
schedulerWorker.on('failed', async (job, failedReason) => {
|
||||
Logger.log('error', `${schedulerName} failed: ${JSON.stringify(failedReason)}`);
|
||||
});
|
||||
schedulerWorker.on('error', async (errMsg) => {
|
||||
Logger.log('error', `${schedulerName} error: ${JSON.stringify(errMsg)}`);
|
||||
});
|
||||
myEmitter.on(schedulerName + 'ShutDown', () => {
|
||||
// gracefull shutdown
|
||||
schedulerWorker.close();
|
||||
});
|
||||
} catch (e) {
|
||||
Logger.log('error', `${schedulerName} worker_error: ${JSON.stringify(e, Object.getOwnPropertyNames(e))}`);
|
||||
}
|
||||
},
|
||||
drainQueue: function () {
|
||||
this.queue.drain();
|
||||
},
|
||||
obliterateQueue: function () {
|
||||
this.queue.obliterate();
|
||||
},
|
||||
workerShutDown: function () {
|
||||
myEmitter.emit(schedulerName + 'ShutDown');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LibSchedulerDrvUpLocIdle
|
||||
93
library/LibSchedulerDrvUpPhoto.js
Normal file
93
library/LibSchedulerDrvUpPhoto.js
Normal file
@ -0,0 +1,93 @@
|
||||
const path = require('path');
|
||||
const RedisConn = require('./LibRedisConn');
|
||||
const QueueMQ = require('bullmq').Queue;
|
||||
const QueueSchedulerMQ = require('bullmq').QueueScheduler;
|
||||
const WorkerMQ = require('bullmq').Worker;
|
||||
// const JobMQ = require('bullmq').Job;
|
||||
const LibWinston = require('./LibWinston');
|
||||
const EventEmitter = require('events');
|
||||
|
||||
const schedulerName = process.env.REDIS_SCHEDULER_DRV_UP_PHOTO;
|
||||
const theQueue = new QueueMQ(schedulerName, { connection: RedisConn });
|
||||
const theQueueScheduler = new QueueSchedulerMQ(schedulerName, { connection: RedisConn });
|
||||
|
||||
const Logger = LibWinston.initialize(schedulerName);
|
||||
|
||||
class MyEmitter extends EventEmitter { };
|
||||
const myEmitter = new MyEmitter();
|
||||
|
||||
/**
|
||||
* bisa multiple queue tanpa new Queue(name) lagi, tinggal dibedain aja nama processornya ketika queue.add(nameProcessor)
|
||||
* worker hanya memproses nama sesuai dengan nameProcessor bukan nama ketika new Queue(name)
|
||||
* concurrency di worker adalah maksimal yang bisa diproses dalam satu waktu bersamaan
|
||||
* attempts di queue adalah maksimal percobaan ketika gagal
|
||||
*/
|
||||
|
||||
const LibSchedulerDrvUpPhoto = {
|
||||
name: schedulerName,
|
||||
queue: theQueue,
|
||||
runQueueScheduler: function (data) {
|
||||
// * * * * * // every minute
|
||||
// */3 * * * * // every 3 minute
|
||||
// 0 */1 * * * // every hour
|
||||
this.queue.add(schedulerName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
repeat: {
|
||||
cron: process.env.SCHEDULE_DRV_UP_PHOTO_TIME,
|
||||
},
|
||||
attempts: 0,
|
||||
});
|
||||
},
|
||||
addQueue: function (data) {
|
||||
this.queue.add(schedulerName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
});
|
||||
},
|
||||
pauseQueue: function () {
|
||||
this.queue.pause();
|
||||
},
|
||||
resumeQueue: function () {
|
||||
this.queue.resume();
|
||||
},
|
||||
getJobs: async function () {
|
||||
return await this.queue.getJobs();
|
||||
},
|
||||
getRepeatableJobs: async function () {
|
||||
return await this.queue.getRepeatableJobs();
|
||||
},
|
||||
setWorker: function () {
|
||||
try {
|
||||
const processorFile = path.join(__dirname, '../workers/DrvUpPhotoWorker.js');
|
||||
const schedulerWorker = new WorkerMQ(schedulerName, processorFile, {
|
||||
connection: RedisConn,
|
||||
concurrency: 1,
|
||||
})
|
||||
schedulerWorker.on('completed', async (job, returnValue) => {
|
||||
Logger.log('info', `${schedulerName} completed: ${JSON.stringify(returnValue)}`);
|
||||
})
|
||||
schedulerWorker.on('failed', async (job, failedReason) => {
|
||||
Logger.log('error', `${schedulerName} failed: ${JSON.stringify(failedReason)}`);
|
||||
});
|
||||
schedulerWorker.on('error', async (errMsg) => {
|
||||
Logger.log('error', `${schedulerName} error: ${JSON.stringify(errMsg)}`);
|
||||
});
|
||||
myEmitter.on(schedulerName + 'ShutDown', () => {
|
||||
// gracefull shutdown
|
||||
schedulerWorker.close();
|
||||
});
|
||||
} catch (e) {
|
||||
Logger.log('error', `${schedulerName} worker_error: ${JSON.stringify(e, Object.getOwnPropertyNames(e))}`);
|
||||
}
|
||||
},
|
||||
drainQueue: function () {
|
||||
this.queue.drain();
|
||||
},
|
||||
obliterateQueue: function () {
|
||||
this.queue.obliterate();
|
||||
},
|
||||
workerShutDown: function () {
|
||||
myEmitter.emit(schedulerName + 'ShutDown');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LibSchedulerDrvUpPhoto
|
||||
133
library/LibSchedulerGpsTrackerWakeUp.js
Normal file
133
library/LibSchedulerGpsTrackerWakeUp.js
Normal file
@ -0,0 +1,133 @@
|
||||
const path = require('path');
|
||||
const RedisConn = require('./LibRedisConn');
|
||||
const QueueMQ = require('bullmq').Queue;
|
||||
const QueueSchedulerMQ = require('bullmq').QueueScheduler;
|
||||
const WorkerMQ = require('bullmq').Worker;
|
||||
// const JobMQ = require('bullmq').Job;
|
||||
const LibWinston = require('./LibWinston');
|
||||
const EventEmitter = require('events');
|
||||
|
||||
const schedulerName = process.env.REDIS_SCHEDULER_GPS_TRACKER_WAKEUP;
|
||||
const theQueue = new QueueMQ(schedulerName, { connection: RedisConn });
|
||||
const theQueueScheduler = new QueueSchedulerMQ(schedulerName, { connection: RedisConn });
|
||||
|
||||
const Logger = LibWinston.initialize(schedulerName);
|
||||
|
||||
class MyEmitter extends EventEmitter { };
|
||||
const myEmitter = new MyEmitter();
|
||||
|
||||
/**
|
||||
* bisa multiple queue tanpa new Queue(name) lagi, tinggal dibedain aja nama processornya ketika queue.add(nameProcessor)
|
||||
* worker hanya memproses nama sesuai dengan nameProcessor bukan nama ketika new Queue(name)
|
||||
* concurrency di worker adalah maksimal yang bisa diproses dalam satu waktu bersamaan
|
||||
* attempts di queue adalah maksimal percobaan ketika gagal
|
||||
*/
|
||||
|
||||
const LibSchedulerDrvUpLocIdle = {
|
||||
name: schedulerName,
|
||||
queue: theQueue,
|
||||
runQueueScheduler: function (data) {
|
||||
// * * * * * // every minute
|
||||
// */3 * * * * // every 3 minute
|
||||
// 0 */1 * * * // every hour
|
||||
this.queue.add(schedulerName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
repeat: {
|
||||
cron: process.env.SCHEDULE_GPS_TRACKER_WAKEUP_TIME,
|
||||
},
|
||||
attempts: 0,
|
||||
});
|
||||
},
|
||||
addQueue: function (data) {
|
||||
this.queue.add(schedulerName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
});
|
||||
},
|
||||
pauseQueue: function () {
|
||||
this.queue.pause();
|
||||
},
|
||||
resumeQueue: function () {
|
||||
this.queue.resume();
|
||||
},
|
||||
getJobs: async function () {
|
||||
return await this.queue.getJobs();
|
||||
},
|
||||
getRepeatableJobs: async function () {
|
||||
return await this.queue.getRepeatableJobs();
|
||||
},
|
||||
setWorker: function () {
|
||||
try {
|
||||
// const processorFile = path.join(__dirname, '../workers/GpsTrackerWakeUp.js');
|
||||
const schedulerWorker = new WorkerMQ(schedulerName, worker, {
|
||||
connection: RedisConn,
|
||||
concurrency: 1,
|
||||
})
|
||||
schedulerWorker.on('completed', async (job, returnValue) => {
|
||||
Logger.log('info', `${schedulerName} completed: ${JSON.stringify(returnValue)}`);
|
||||
})
|
||||
schedulerWorker.on('failed', async (job, failedReason) => {
|
||||
Logger.log('error', `${schedulerName} failed: ${JSON.stringify(failedReason)}`);
|
||||
});
|
||||
schedulerWorker.on('error', async (errMsg) => {
|
||||
Logger.log('error', `${schedulerName} error: ${JSON.stringify(errMsg)}`);
|
||||
});
|
||||
myEmitter.on(schedulerName + 'ShutDown', () => {
|
||||
// gracefull shutdown
|
||||
schedulerWorker.close();
|
||||
});
|
||||
} catch (e) {
|
||||
Logger.log('error', `${schedulerName} worker_error: ${JSON.stringify(e, Object.getOwnPropertyNames(e))}`);
|
||||
}
|
||||
},
|
||||
drainQueue: function () {
|
||||
this.queue.drain();
|
||||
},
|
||||
obliterateQueue: function () {
|
||||
this.queue.obliterate();
|
||||
},
|
||||
workerShutDown: function () {
|
||||
myEmitter.emit(schedulerName + 'ShutDown');
|
||||
}
|
||||
}
|
||||
|
||||
const netConn = require('../config/netConn');
|
||||
async function worker (job) {
|
||||
try {
|
||||
// const now = moment().unix();
|
||||
Logger.log('info', `${schedulerName} running: ${JSON.stringify(job.opts)}`);
|
||||
|
||||
// (async function() {
|
||||
try {
|
||||
let loop = process.env.SCHEDULE_GPS_TRACKER_WAKEUP_MAX_LOOP;
|
||||
for (let x = 0; x < loop; x++) {
|
||||
for (const device_id in netConn) {
|
||||
const c = netConn[device_id];
|
||||
// c.write(Buffer.from("DWXX#", "hex"));
|
||||
c.write("DWXX#");
|
||||
console.log('looking up information location');
|
||||
// c.on('data', function(data) {
|
||||
// console.log('worker ', data);
|
||||
// });
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
Logger.log('error', `${schedulerName} error: ${JSON.stringify(e)}`);
|
||||
}
|
||||
// })();
|
||||
|
||||
return {
|
||||
type: 'success',
|
||||
message: 'success run scheduler gps tracker wakeup worker',
|
||||
data: null,
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
type: 'error',
|
||||
message: e.message,
|
||||
e: e,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = LibSchedulerDrvUpLocIdle
|
||||
93
library/LibSchedulerReverseGeocode.js
Normal file
93
library/LibSchedulerReverseGeocode.js
Normal file
@ -0,0 +1,93 @@
|
||||
const path = require('path');
|
||||
const RedisConn = require('./LibRedisConn');
|
||||
const QueueMQ = require('bullmq').Queue;
|
||||
const QueueSchedulerMQ = require('bullmq').QueueScheduler;
|
||||
const WorkerMQ = require('bullmq').Worker;
|
||||
// const JobMQ = require('bullmq').Job;
|
||||
const LibWinston = require('./LibWinston');
|
||||
const EventEmitter = require('events');
|
||||
|
||||
const schedulerName = process.env.REDIS_SCHEDULER_REVERSE_GEO;
|
||||
const theQueue = new QueueMQ(schedulerName, { connection: RedisConn });
|
||||
const theQueueScheduler = new QueueSchedulerMQ(schedulerName, { connection: RedisConn });
|
||||
|
||||
const Logger = LibWinston.initialize(schedulerName);
|
||||
|
||||
class MyEmitter extends EventEmitter { };
|
||||
const myEmitter = new MyEmitter();
|
||||
|
||||
/**
|
||||
* bisa multiple queue tanpa new Queue(name) lagi, tinggal dibedain aja nama processornya ketika queue.add(nameProcessor)
|
||||
* worker hanya memproses nama sesuai dengan nameProcessor bukan nama ketika new Queue(name)
|
||||
* concurrency di worker adalah maksimal yang bisa diproses dalam satu waktu bersamaan
|
||||
* attempts di queue adalah maksimal percobaan ketika gagal
|
||||
*/
|
||||
|
||||
const LibSchedulerReverseGeocode = {
|
||||
name: schedulerName,
|
||||
queue: theQueue,
|
||||
runQueueScheduler: function (data) {
|
||||
// * * * * * // every minute
|
||||
// */3 * * * * // every 3 minute
|
||||
// 0 */1 * * * // every hour
|
||||
this.queue.add(schedulerName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
repeat: {
|
||||
cron: process.env.SCHEDULE_REVERSE_GEO_TIME,
|
||||
},
|
||||
attempts: 0,
|
||||
});
|
||||
},
|
||||
addQueue: function (data) {
|
||||
this.queue.add(schedulerName, data, {
|
||||
removeOnComplete: false, // false just for debugging
|
||||
});
|
||||
},
|
||||
pauseQueue: function () {
|
||||
this.queue.pause();
|
||||
},
|
||||
resumeQueue: function () {
|
||||
this.queue.resume();
|
||||
},
|
||||
getJobs: async function () {
|
||||
return await this.queue.getJobs();
|
||||
},
|
||||
getRepeatableJobs: async function () {
|
||||
return await this.queue.getRepeatableJobs();
|
||||
},
|
||||
setWorker: function () {
|
||||
try {
|
||||
const processorFile = path.join(__dirname, '../workers/ReverseGeocodeWorker.js');
|
||||
const schedulerWorker = new WorkerMQ(schedulerName, processorFile, {
|
||||
connection: RedisConn,
|
||||
concurrency: 1,
|
||||
})
|
||||
schedulerWorker.on('completed', async (job, returnValue) => {
|
||||
Logger.log('info', `${schedulerName} completed: ${JSON.stringify(returnValue)}`);
|
||||
})
|
||||
schedulerWorker.on('failed', async (job, failedReason) => {
|
||||
Logger.log('error', `${schedulerName} failed: ${JSON.stringify(failedReason)}`);
|
||||
});
|
||||
schedulerWorker.on('error', async (errMsg) => {
|
||||
Logger.log('error', `${schedulerName} error: ${JSON.stringify(errMsg)}`);
|
||||
});
|
||||
myEmitter.on(schedulerName + 'ShutDown', () => {
|
||||
// gracefull shutdown
|
||||
schedulerWorker.close();
|
||||
});
|
||||
} catch (e) {
|
||||
Logger.log('error', `${schedulerName} worker_error: ${JSON.stringify(e, Object.getOwnPropertyNames(e))}`);
|
||||
}
|
||||
},
|
||||
drainQueue: function () {
|
||||
this.queue.drain();
|
||||
},
|
||||
obliterateQueue: function () {
|
||||
this.queue.obliterate();
|
||||
},
|
||||
workerShutDown: function () {
|
||||
myEmitter.emit(schedulerName + 'ShutDown');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LibSchedulerReverseGeocode
|
||||
53
library/LibWinston.js
Normal file
53
library/LibWinston.js
Normal file
@ -0,0 +1,53 @@
|
||||
const path = require('path');
|
||||
const winston = require('winston');
|
||||
|
||||
class LibWinston {
|
||||
|
||||
static initialize(filename) {
|
||||
winston.addColors(this.getColours());
|
||||
return winston.createLogger({
|
||||
level: this.getAccessLevel(),
|
||||
levels: this.getLevels(),
|
||||
exitOnError: false,
|
||||
format: winston.format.combine(
|
||||
// winston.format.colorize(),
|
||||
winston.format.timestamp(),
|
||||
winston.format.json(),
|
||||
),
|
||||
transports: [
|
||||
new winston.transports.File({ filename: path.join(__dirname, '../logs', `${filename}.log`), level: this.getAccessLevel(), maxsize: '10000000', maxFiles: '10' }),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
static getLevels() {
|
||||
return {
|
||||
error: 0,
|
||||
warn: 1,
|
||||
info: 2,
|
||||
http: 3,
|
||||
debug: 4,
|
||||
};
|
||||
}
|
||||
|
||||
static getColours() {
|
||||
return {
|
||||
error: 'red',
|
||||
warn: 'yellow',
|
||||
info: 'green',
|
||||
http: 'magenta',
|
||||
debug: 'white',
|
||||
};
|
||||
}
|
||||
|
||||
static getAccessLevel() {
|
||||
if (process.env.NODE_ENV == 'production') {
|
||||
return 'info';
|
||||
}
|
||||
// development
|
||||
return 'debug';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LibWinston;
|
||||
37
middleware/AuthDriverMiddleware.js
Normal file
37
middleware/AuthDriverMiddleware.js
Normal file
@ -0,0 +1,37 @@
|
||||
const Helper = require('../library/LibHelper');
|
||||
const DriversModels = require('../models/DriversModels');
|
||||
const LibJwt = require('../library/LibJwt');
|
||||
const response = require('../config/response');
|
||||
|
||||
class AuthDriverMiddleware {
|
||||
static async initialize(req, res, next) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const tokenData = await LibJwt.verifyToken(req.headers['x-api-key']);
|
||||
if (tokenData.type !== 'success') {
|
||||
apiRes = JSON.parse(JSON.stringify(response[401]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + tokenData.message);
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
const phoneDevice = await DriversModels.getDeviceByImei(tokenData.data.device_id);
|
||||
if (phoneDevice.length < 1) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[401]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': your session has expired');
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
if (phoneDevice[0].is_login !== DriversModels.IS_LOGIN) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[401]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': your session has expired');
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
req.auth = JSON.parse(JSON.stringify(tokenData.data));
|
||||
next();
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[401]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AuthDriverMiddleware.initialize;
|
||||
26
middleware/AuthDriverMiddlewareNotStrict.js
Normal file
26
middleware/AuthDriverMiddlewareNotStrict.js
Normal file
@ -0,0 +1,26 @@
|
||||
const Helper = require('../library/LibHelper');
|
||||
// const DriversModels = require('../models/DriversModels');
|
||||
const LibJwt = require('../library/LibJwt');
|
||||
const response = require('../config/response');
|
||||
|
||||
class AuthDriverMiddlewareNotStrict {
|
||||
static async initialize(req, res, next) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const tokenData = await LibJwt.verifyToken(req.headers['x-api-key']);
|
||||
if (tokenData.type !== 'success') {
|
||||
apiRes = JSON.parse(JSON.stringify(response[401]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + tokenData.message);
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
req.auth = JSON.parse(JSON.stringify(tokenData.data));
|
||||
next();
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[401]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AuthDriverMiddlewareNotStrict.initialize;
|
||||
32
middleware/AuthMiddleware.js
Normal file
32
middleware/AuthMiddleware.js
Normal file
@ -0,0 +1,32 @@
|
||||
const Helper = require('../library/LibHelper');
|
||||
// const UsersModels = require('../models/UsersModels');
|
||||
const LibJwt = require('../library/LibJwt');
|
||||
const response = require('../config/response');
|
||||
|
||||
class AuthMiddleware {
|
||||
static async initialize(req, res, next) {
|
||||
let apiRes = {};
|
||||
try {
|
||||
const tokenData = await LibJwt.verifyToken(req.headers['x-api-key']);
|
||||
if (tokenData.type !== 'success') {
|
||||
apiRes = JSON.parse(JSON.stringify(response[401]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + tokenData.message);
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
req.jwt = tokenData.data;
|
||||
// const getUser = await UsersModels.find(req.jwt.uid);
|
||||
// if (getUser.length < 1) {
|
||||
// apiRes = JSON.parse(JSON.stringify(response[401]));
|
||||
// return res.status(200).json(apiRes);
|
||||
// }
|
||||
req.jwt.hub_id = getUser[0].hub_id;
|
||||
next();
|
||||
} catch (e) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[401]));
|
||||
apiRes.meta.message += Helper.setErrMsg(': ' + e.message);
|
||||
return res.status(200).json(apiRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AuthMiddleware.initialize;
|
||||
17
middleware/MorganMiddleware.js
Normal file
17
middleware/MorganMiddleware.js
Normal file
@ -0,0 +1,17 @@
|
||||
const morgan = require('morgan');
|
||||
const LibWinston = require('../library/LibWinston');
|
||||
|
||||
const customFormat = "{remoteAddr:':remote-addr', remoteUser:':remote-user', date:':date[iso]', method:':method', url:':url', http:'HTTP/:http-version', statusCode:':status', contentLength:':res[content-length]', referrer:':referrer', userAgent:':user-agent'}";
|
||||
|
||||
class MorganMiddleware {
|
||||
static initialize() {
|
||||
return morgan(customFormat, {
|
||||
stream: {
|
||||
write: (msg) => LibWinston.http(msg),
|
||||
},
|
||||
// skip: (req, res) => res.statusCode < 400,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MorganMiddleware.initialize();
|
||||
80
models/DanaModels.js
Normal file
80
models/DanaModels.js
Normal file
@ -0,0 +1,80 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class DanaModels {
|
||||
|
||||
static PK_ID = 1;
|
||||
static MINIMUM_AMT = 1000000; // 9M
|
||||
|
||||
static list(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select = '', where = '', join = '', order_by = '', group_by = '', limit = '';
|
||||
|
||||
if (filter['id']) {
|
||||
where += ' AND dana.id = ?';
|
||||
params.push(filter['id']);
|
||||
}
|
||||
|
||||
if (filter['group_by']) {
|
||||
group_by = filter['group_by'];
|
||||
}
|
||||
|
||||
if (filter['limit']) {
|
||||
limit = ' LIMIT ' + filter['limit'];
|
||||
}
|
||||
|
||||
let query = `SELECT
|
||||
dana.*
|
||||
${select}
|
||||
FROM t_dana as dana
|
||||
${join}
|
||||
WHERE dana.id is not null
|
||||
${where}
|
||||
${group_by}
|
||||
${order_by}
|
||||
${limit}
|
||||
;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static bundleUpdt (updtDana = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
|
||||
if (Object.keys(updtDana).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_dana SET ? WHERE id = ?;`, [updtDana, updtDana.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DanaModels;
|
||||
295
models/DriversModels.js
Normal file
295
models/DriversModels.js
Normal file
@ -0,0 +1,295 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class DriversModels {
|
||||
|
||||
static DEFAULT_PHONE_CODE = 62;
|
||||
|
||||
// t_drivers
|
||||
static IS_INACTIVE = 0;
|
||||
static IS_ACTIVE = 1;
|
||||
|
||||
static IN_ORD_YES = 1;
|
||||
static IN_ORD_NO = 2;
|
||||
|
||||
// t_phone_devices
|
||||
static IS_LOGOUT = 0;
|
||||
static IS_LOGIN = 1;
|
||||
|
||||
// start t_drivers
|
||||
static all() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `SELECT * FROM t_drivers;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, (err, results) => {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(results);
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static find(id) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `SELECT * FROM t_drivers WHERE id = ? LIMIT 1;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, [id]);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, [id], (err, results) => {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(results);
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static findPhone(phone) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `SELECT * FROM t_drivers WHERE dlt is null AND phone = ? LIMIT 1;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, [phone]);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, [phone], (err, results) => {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(results);
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static create(data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `INSERT INTO t_drivers SET ?;`;
|
||||
db.query(query, data, (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static update(data, id) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `UPDATE t_drivers SET ? WHERE id = ?;`;
|
||||
db.query(query, [data, id], (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static delete(id) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `DELETE FROM t_drivers WHERE id = ?;`;
|
||||
db.query(query, [id], (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static bundleUpdtOrdDrvVhc (updtDrv = {}, updtVhc = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
|
||||
if (Object.keys(updtDrv).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_drivers SET ? WHERE id = ?;`, [updtDrv, updtDrv.id]);
|
||||
if (Object.keys(updtVhc).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_vehicles SET ? WHERE id = ?;`, [updtVhc, updtVhc.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
// end t_drivers
|
||||
|
||||
// start t_phone_devices
|
||||
static getDeviceByDid(did) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `SELECT * FROM t_phone_devices WHERE dlt is null AND did = ? LIMIT 1;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, [did]);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, [did], (err, results) => {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(results);
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static getDeviceByImei(device_id) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `SELECT * FROM t_phone_devices WHERE dlt is null AND device_id = ? LIMIT 1;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, [device_id]);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, [device_id], (err, results) => {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(results);
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static getDriversLogin(is_login) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `SELECT * FROM t_phone_devices WHERE dlt is null AND is_login = ?;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, [is_login]);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, [device_id], (err, results) => {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(results);
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static insPhoneDevice(data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `INSERT INTO t_phone_devices SET ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, data, function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Number(resp.insertId);
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static updtPhoneDevice(data, id) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `UPDATE t_phone_devices SET ? WHERE id = ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, [data, id], function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
// end t_phone_devices
|
||||
}
|
||||
|
||||
module.exports = DriversModels;
|
||||
214
models/DummyModels.js
Normal file
214
models/DummyModels.js
Normal file
@ -0,0 +1,214 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
|
||||
class DummyModels {
|
||||
|
||||
static DEFAULT_COUNTRY_ID = 1;
|
||||
|
||||
static TYPE_ADDR_OSM = 1;
|
||||
|
||||
static STTS_REVERSE_GEO_SC = 1;
|
||||
static STTS_REVERSE_GEO_NOT = 2;
|
||||
static STTS_REVERSE_GEO_ER = 3;
|
||||
static STTS_REVERSE_GEO_LOST = 4;
|
||||
|
||||
static async create(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO t_dummy_gps SET ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, data, function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Number(resp.insertId);
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async create2(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO t_dummy_gps2 SET ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, data, function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Number(resp.insertId);
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async get2() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_dummy_gps2 ORDER BY id DESC LIMIT 1000';
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async get2ForReverseGeo(limit) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_dummy_gps2 WHERE latitude is not null AND longitude is not null AND stts_reverse_geo = ? ORDER BY id ASC LIMIT ?';
|
||||
params.push(DummyModels.STTS_REVERSE_GEO_NOT, limit);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async update2(id, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `UPDATE t_dummy_gps2 SET ? WHERE id = ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, [data, id], function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async create2Address(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO t_dummy_gps2_address SET ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, data, function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Number(resp.insertId);
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DummyModels;
|
||||
596
models/GpsTracksModels.js
Normal file
596
models/GpsTracksModels.js
Normal file
@ -0,0 +1,596 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class GpsTracksModels {
|
||||
|
||||
static DEFAULT_COUNTRY_ID = 1;
|
||||
|
||||
static TYPE_ADDR_OSM = 1;
|
||||
|
||||
static STTS_REVERSE_GEO_SC = 1;
|
||||
static STTS_REVERSE_GEO_NOT = 2;
|
||||
static STTS_REVERSE_GEO_ER = 3;
|
||||
static STTS_REVERSE_GEO_LOST = 4;
|
||||
|
||||
static STTS_EN_DFT = 0;
|
||||
static STTS_EN_IDLING = 1;
|
||||
static STTS_EN_MOVING = 2;
|
||||
static STTS_EN_STOPING = 3;
|
||||
|
||||
static STTS_IGNITION_DFT = 0;
|
||||
static STTS_IGNITION_ON = 1;
|
||||
static STTS_IGNITION_OFF = 2;
|
||||
static STTS_IGNITION_LOW = 3;
|
||||
static STTS_IGNITION_HIGH = 4;
|
||||
|
||||
static STTS_GPS_DFT = 0; // default
|
||||
static STTS_GPS_ON = 1;
|
||||
static STTS_GPS_OFF = 2;
|
||||
|
||||
// realtime GPS or differential positioning
|
||||
static STTS_POS_TYPE_GPS_DFT = 0; // default
|
||||
static STTS_POS_TYPE_GPS_DIFF = 1;
|
||||
static STTS_POS_TYPE_GPS_RLTM = 2;
|
||||
|
||||
// GPS has been positioned or not
|
||||
static STTS_IS_POS_GPS_DFT = 0; // default
|
||||
static STTS_IS_POS_GPS_NOT = 1; // not positioning
|
||||
static STTS_IS_POS_GPS_HAS = 2; // positioning
|
||||
|
||||
// 1=>no signal, 2=>extremely weak signal 3=>very weak signal, 4=>good signal, 5=>strong signal
|
||||
static STTS_GSM_DFT = 0; // default
|
||||
static STTS_GSM_NO_SIGNAL = 1;
|
||||
static STTS_GSM_BAD_SIGNAL = 2;
|
||||
static STTS_GSM_WEAK_SIGNAL = 3;
|
||||
static STTS_GSM_GOOD_SIGNAL = 4;
|
||||
static STTS_GSM_STRONG_SIGNAL = 5;
|
||||
|
||||
static STTS_OIL_ELECTRIC_DFT = 0;
|
||||
static STTS_OIL_ELECTRIC_ON = 1;
|
||||
static STTS_OIL_ELECTRIC_OFF = 2;
|
||||
|
||||
static STTS_ALARM_DFT = 0;
|
||||
static STTS_ALARM_NORMAL = 1;
|
||||
static STTS_ALARM_SHOCK = 2;
|
||||
static STTS_ALARM_POWER_CUT = 3;
|
||||
static STTS_ALARM_LOW_BATTERY = 4;
|
||||
static STTS_ALARM_SOS = 5;
|
||||
|
||||
static STTS_CHARGE_DFT = 0;
|
||||
static STTS_CHARGE_OFF = 1;
|
||||
static STTS_CHARGE_ON = 2;
|
||||
|
||||
static STTS_ACC_DFT = 0;
|
||||
static STTS_ACC_LOW = 1;
|
||||
static STTS_ACC_HIGH = 2;
|
||||
|
||||
static STTS_VOLT_DFT = 0;
|
||||
static STTS_VOLT_SHUTDOWN = 1;
|
||||
static STTS_VOLT_EXTREME_LOW_BATTERY = 2;
|
||||
static STTS_VOLT_VERY_LOW_BATTERY = 3;
|
||||
static STTS_VOLT_LOW_BATTERY = 4;
|
||||
static STTS_VOLT_MEDIUM = 5;
|
||||
static STTS_VOLT_HIGH = 6;
|
||||
static STTS_VOLT_VERY_HIGH = 7;
|
||||
|
||||
static STTS_SWITCH_DFT = 0;
|
||||
static STTS_SWITCH_OFF = 1;
|
||||
static STTS_SWITCH_ON = 2;
|
||||
|
||||
static STTS_ENTER_ZONE = 1;
|
||||
static STTS_LEAVE_ZONE = 2;
|
||||
|
||||
// type source
|
||||
static SOURCE_GPS_TRACKER = 1;
|
||||
static SOURCE_SMARTPHONE = 2;
|
||||
|
||||
static PROTOCOL_SMARTPHONE = 'smartphone';
|
||||
|
||||
static ACT_LOGIN = 'login';
|
||||
static ACT_HEARTBEAT = 'heartbeat';
|
||||
static ACT_LOCATION = 'location';
|
||||
static ACT_OTHER = 'other';
|
||||
|
||||
static async create2(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO t_gps_tracks SET ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, data, function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Number(resp.insertId);
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static bundleCreate2 (logs = {}, rltm = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let rltmLength = Object.keys(rltm).length;
|
||||
let resLogs = undefined;
|
||||
|
||||
if (Object.keys(logs).length > 0) resLogs = await MysqlHelpers.queryTrx(conn, `INSERT INTO t_gps_tracks SET ?;`, [logs]);
|
||||
|
||||
if (rltmLength > 0 && typeof resLogs !== 'undefined') rltm.master_id = resLogs.insertId;
|
||||
if (rltmLength > 0 && rltm.latitude !== null && rltm.longitude !== null) {
|
||||
let devices = await MysqlHelpers.queryTrx(conn, `SELECT id FROM t_gps_tracks_rltm as rltm WHERE rltm.device_id = ?`, [rltm.device_id]);
|
||||
if (devices.length > 1) await MysqlHelpers.queryTrx(conn, `DELETE from t_gps_tracks_rltm WHERE device_id = ?;`, [rltm.device_id]);
|
||||
|
||||
if (rltm.vhc_id != 0) {
|
||||
let vhcs = await MysqlHelpers.queryTrx(conn, `SELECT id FROM t_gps_tracks_rltm as rltm WHERE rltm.vhc_id = ?`, [rltm.vhc_id]);
|
||||
if (vhcs.length > 1) await MysqlHelpers.queryTrx(conn, `DELETE from t_gps_tracks_rltm WHERE vhc_id = ?;`, [rltm.vhc_id]);
|
||||
}
|
||||
|
||||
if (rltm.drv_id != 0) {
|
||||
let drvs = await MysqlHelpers.queryTrx(conn, `SELECT id FROM t_gps_tracks_rltm as rltm WHERE rltm.drv_id = ?`, [rltm.drv_id]);
|
||||
if (drvs.length > 1) await MysqlHelpers.queryTrx(conn, `DELETE from t_gps_tracks_rltm WHERE drv_id = ?;`, [rltm.drv_id]);
|
||||
}
|
||||
|
||||
await MysqlHelpers.queryTrx(conn, `INSERT INTO t_gps_tracks_rltm SET ? ON DUPLICATE KEY UPDATE ?;`, [rltm, rltm]);
|
||||
}
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
resolve({
|
||||
type: 'success',
|
||||
result: resLogs,
|
||||
})
|
||||
} catch (err) {
|
||||
console.log('err');
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static async get2() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_gps_tracks ORDER BY id DESC LIMIT 1000';
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async get2ForReverseGeo(limit) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_gps_tracks WHERE latitude is not null AND longitude is not null AND stts_reverse_geo = ? ORDER BY id ASC LIMIT ?';
|
||||
params.push(GpsTracksModels.STTS_REVERSE_GEO_NOT, limit);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async get2LastDevice(device_id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_gps_tracks WHERE device_id = ? ORDER BY id DESC LIMIT 1';
|
||||
params.push(device_id);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async get2LastLocByDeviceId(device_id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
// let query = 'SELECT * FROM t_gps_tracks WHERE device_id = ? AND latitude is not null AND longitude != 0 ORDER BY id DESC LIMIT 1';
|
||||
let query = 'SELECT * FROM t_gps_tracks WHERE action IN ("location","alarm") AND device_id = ? AND latitude is not null AND longitude != 0 ORDER BY id DESC LIMIT 1'; // kalo gamau ngambil data heartbeat(idling)
|
||||
params.push(device_id);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async get2LastLoc(filter = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [], where = '';
|
||||
if (filter['device_id']) {
|
||||
where += ' AND device_id = ?';
|
||||
params.push(filter['device_id']);
|
||||
|
||||
} else if (filter['vhc_id']) {
|
||||
where += ' AND vhc_id = ?';
|
||||
params.push(filter['vhc_id']);
|
||||
|
||||
} else if (filter['drv_id']) {
|
||||
where += ' AND drv_id = ?';
|
||||
params.push(filter['drv_id']);
|
||||
|
||||
} else {
|
||||
reject(false);
|
||||
return false;
|
||||
}
|
||||
let query = `SELECT * FROM t_gps_tracks WHERE latitude is not null AND longitude != 0 ${where} ORDER BY id DESC LIMIT 1`;
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getLastLocAndAddrByDid(filter = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [], where = '', limit = '';
|
||||
|
||||
if (typeof filter['did'] !== 'undefined') {
|
||||
where += ' AND tr.drv_id = ?';
|
||||
params.push(filter['did']);
|
||||
}
|
||||
|
||||
if (typeof filter['limit'] !== 'undefined') {
|
||||
limit += ' LIMIT ?';
|
||||
params.push(filter['limit']);
|
||||
}
|
||||
|
||||
let query = `SELECT tr.*,tra.state_text,tra.city_text,tra.district_text,tra.village_text,tra.postcode,tra.streets,tra.fulladdress FROM t_gps_tracks as tr LEFT JOIN t_gps_tracks_address as tra ON tr.id = tra.master_id WHERE latitude is not null AND longitude != 0 ${where} ORDER BY id DESC ${limit}`;
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async checkSttsEngineBetweenDate(device_id, stts_engine, start, end) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_gps_tracks WHERE device_id = ? AND stts_engine = ? AND crt BETWEEN ? AND ? ORDER BY id ASC LIMIT 1';
|
||||
params.push(device_id, stts_engine, start, end);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async get2LastHeartbeatOrAlarm(device_id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_gps_tracks WHERE device_id = ? AND action IN ("heartbeat","alarm") AND stts_gps != 0 AND stts_gsm != 0 ORDER BY id DESC LIMIT 1';
|
||||
params.push(device_id);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getLastHeartbeatToDeterminIdling(device_id, lst_pos_crt, now) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_gps_tracks WHERE device_id = ? AND action IN ("heartbeat") AND stts_gps != 0 AND crt BETWEEN '+lst_pos_crt+' AND '+now+' ORDER BY id DESC;';
|
||||
params.push(device_id);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async update2(id, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `UPDATE t_gps_tracks SET ? WHERE id = ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, [data, id], function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async select2Address(lat = '', lng = '') {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_gps_tracks_address WHERE stts_reverse_geo = '+GpsTracksModels.STTS_REVERSE_GEO_SC+' AND lat = ? AND lng = ? ORDER BY id DESC LIMIT 1;';
|
||||
params.push(lat, lng);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async create2Address(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO t_gps_tracks_address SET ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, data, function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Number(resp.insertId);
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async create2SpawnZone(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO t_gps_tracks_spawn SET ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, data, function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Number(resp.insertId);
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async updt2SpawnZone(data, id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `UPDATE t_gps_tracks_spawn SET ? WHERE id = ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, [data, id], function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Number(resp.insertId);
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static listSpawnZone(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select = '', where = '', join = '', order_by = '', group_by = '', limit = '';
|
||||
|
||||
if (filter['zone_id']) {
|
||||
where += ' AND spawn.zone_id = ?';
|
||||
params.push(filter['zone_id']);
|
||||
}
|
||||
if (filter['ord_id']) {
|
||||
where += ' AND spawn.ord_id = ?';
|
||||
params.push(filter['ord_id']);
|
||||
}
|
||||
if (filter['ord_pck_drop_id']) {
|
||||
where += ' AND spawn.ord_pck_drop_id = ?';
|
||||
params.push(filter['ord_pck_drop_id']);
|
||||
}
|
||||
if (filter['drv_id']) {
|
||||
where += ' AND spawn.drv_id = ?';
|
||||
params.push(filter['drv_id']);
|
||||
}
|
||||
if (filter['vhc_id']) {
|
||||
where += ' AND spawn.vhc_id = ?';
|
||||
params.push(filter['vhc_id']);
|
||||
}
|
||||
if (filter['source']) {
|
||||
where += ' AND spawn.source = ?';
|
||||
params.push(filter['source']);
|
||||
}
|
||||
if (typeof filter['leave_at_d'] != undefined) {
|
||||
where += ' AND spawn.leave_at_d = ?';
|
||||
params.push(filter['leave_at_d']);
|
||||
}
|
||||
|
||||
if (filter['group_by']) {
|
||||
group_by = filter['group_by'];
|
||||
}
|
||||
if (filter['order_by']) {
|
||||
order_by = filter['order_by'];
|
||||
}
|
||||
if (filter['limit']) {
|
||||
limit = ' LIMIT ' + filter['limit'];
|
||||
}
|
||||
|
||||
let query = `SELECT
|
||||
spawn.*
|
||||
${select}
|
||||
FROM t_gps_tracks_spawn as spawn
|
||||
${join}
|
||||
WHERE spawn.master_id != 0
|
||||
${where}
|
||||
${group_by}
|
||||
${order_by}
|
||||
${limit}
|
||||
;`;
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = GpsTracksModels;
|
||||
155
models/LogbookKeysModels.js
Normal file
155
models/LogbookKeysModels.js
Normal file
@ -0,0 +1,155 @@
|
||||
// const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class LogbookKeysModels {
|
||||
|
||||
static IS_INACTIVE = 0;
|
||||
static IS_ACTIVE = 1;
|
||||
|
||||
// t_datatypes;
|
||||
static TEXT = 'string';
|
||||
static NUMBER = 'int';
|
||||
static IMG_BASE64 = 'img_base64';
|
||||
static COMMA = 'double';
|
||||
|
||||
static list(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select = '', where = '', join = '', order_by = '', group_by = '', limit = '';
|
||||
|
||||
if (filter['lgb_id']) {
|
||||
where += ' AND lgb_key.id = ?';
|
||||
params.push(filter['lgb_id']);
|
||||
}
|
||||
if (filter['is_active']) {
|
||||
where += ' AND lgb_key.is_active = ?';
|
||||
params.push(filter['is_active']);
|
||||
}
|
||||
|
||||
if (filter['join_type']) {
|
||||
select += ',lgb_type.name as type_name';
|
||||
join += ' LEFT JOIN t_lgb_types as lgb_type ON lgb_key.type = lgb_type.id';
|
||||
}
|
||||
|
||||
if (filter['group_by']) group_by = ' GROUP BY ' + filter['group_by'];
|
||||
if (filter['order_by']) order_by = ' ORDER BY ' + filter['order_by'];
|
||||
if (filter['limit']) limit = ' LIMIT ' + filter['limit'];
|
||||
|
||||
let query = `SELECT
|
||||
lgb_key.*,lgb_key.id as lgb_id
|
||||
${select}
|
||||
FROM t_lgb_keys as lgb_key
|
||||
${join}
|
||||
WHERE lgb_key.dlt is null
|
||||
${where}
|
||||
${group_by}
|
||||
${order_by}
|
||||
${limit}
|
||||
;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static gets() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_lgb_keys WHERE dlt is null;';
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static ins(ins = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
if (Object.keys(ins).length > 0) result = await MysqlHelpers.queryTrx(conn, `INSERT t_lgb_keys SET ?;`, [ins]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static updt(updt = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
if (Object.keys(updt).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_lgb_keys SET ? WHERE id = ?;`, [updt, updt.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static del(del = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
if (Object.keys(del).length > 0) result = await MysqlHelpers.queryTrx(conn, `DELETE t_lgb_keys WHERE id = ?;`, [del.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LogbookKeysModels;
|
||||
144
models/LogbookOrdersModels.js
Normal file
144
models/LogbookOrdersModels.js
Normal file
@ -0,0 +1,144 @@
|
||||
// const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class LogbookOrdersModels {
|
||||
|
||||
static IS_INACTIVE = 0;
|
||||
static IS_ACTIVE = 1;
|
||||
|
||||
static list(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select = '', where = '', join = '', order_by = '', group_by = '', limit = '';
|
||||
|
||||
if (filter['ord_lgb_id']) {
|
||||
where += ' AND ord_lgb.id = ?';
|
||||
params.push(filter['ord_lgb_id']);
|
||||
}
|
||||
if (filter['is_active']) {
|
||||
where += ' AND ord_lgb.is_active = ?';
|
||||
params.push(filter['is_active']);
|
||||
}
|
||||
|
||||
if (filter['group_by']) group_by = ' GROUP BY ' + filter['group_by'];
|
||||
if (filter['order_by']) order_by = ' ORDER BY ' + filter['order_by'];
|
||||
if (filter['limit']) limit = ' LIMIT ' + filter['limit'];
|
||||
|
||||
let query = `SELECT
|
||||
ord_lgb.*,ord_lgb.id as ord_lgb_id,COLUMN_JSON(ord_lgb.dy_cols) as dy_cols_json
|
||||
${select}
|
||||
FROM t_orders_lgb as ord_lgb
|
||||
${join}
|
||||
WHERE ord_lgb.dlt is null
|
||||
${where}
|
||||
${group_by}
|
||||
${order_by}
|
||||
${limit}
|
||||
;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static gets() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_orders_lgb WHERE dlt is null;';
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static ins(ins = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
if (Object.keys(ins).length > 0) result = await MysqlHelpers.queryTrx(conn, `INSERT t_orders_lgb SET ?;`, ins);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static updt(updt = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
if (Object.keys(updt).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_lgb SET ? WHERE id = ?;`, [updt, updt.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static del(del = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
if (Object.keys(del).length > 0) result = await MysqlHelpers.queryTrx(conn, `DELETE t_orders_lgb WHERE id = ?;`, [del.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LogbookOrdersModels;
|
||||
144
models/LogbookTypesModels.js
Normal file
144
models/LogbookTypesModels.js
Normal file
@ -0,0 +1,144 @@
|
||||
// const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class LogbookTypesModels {
|
||||
|
||||
static IS_INACTIVE = 0;
|
||||
static IS_ACTIVE = 1;
|
||||
|
||||
static list(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select = '', where = '', join = '', order_by = '', group_by = '', limit = '';
|
||||
|
||||
if (filter['lgb_type_id']) {
|
||||
where += ' AND lgb_type.id = ?';
|
||||
params.push(filter['lgb_type_id']);
|
||||
}
|
||||
if (filter['is_active']) {
|
||||
where += ' AND lgb_type.is_active = ?';
|
||||
params.push(filter['is_active']);
|
||||
}
|
||||
|
||||
if (filter['group_by']) group_by = ' GROUP BY ' + filter['group_by'];
|
||||
if (filter['order_by']) order_by = ' ORDER BY ' + filter['order_by'];
|
||||
if (filter['limit']) limit = ' LIMIT ' + filter['limit'];
|
||||
|
||||
let query = `SELECT
|
||||
lgb_type.*,lgb_type.id as lgb_type_id
|
||||
${select}
|
||||
FROM t_lgb_types as lgb_type
|
||||
${join}
|
||||
WHERE lgb_type.dlt is null
|
||||
${where}
|
||||
${group_by}
|
||||
${order_by}
|
||||
${limit}
|
||||
;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static gets() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_lgb_types WHERE dlt is null;';
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static ins(ins = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
if (Object.keys(ins).length > 0) result = await MysqlHelpers.queryTrx(conn, `INSERT t_lgb_types SET ?;`, [ins]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static updt(updt = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
if (Object.keys(updt).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_lgb_types SET ? WHERE id = ?;`, [updt, updt.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static del(del = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
if (Object.keys(del).length > 0) result = await MysqlHelpers.queryTrx(conn, `DELETE t_lgb_types WHERE id = ?;`, [del.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LogbookTypesModels;
|
||||
91
models/LogsSchNotifModels.js
Normal file
91
models/LogsSchNotifModels.js
Normal file
@ -0,0 +1,91 @@
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class LogsSchNotifModels {
|
||||
|
||||
static list(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select = '', join = '', where = '', group_by = '', order_by = '', limit = '';
|
||||
|
||||
if (filter['fcm_token']) {
|
||||
where += ' AND lognot.fcm_token = ?';
|
||||
params.push(filter['id']);
|
||||
}
|
||||
if (filter['device_id']) {
|
||||
where += ' AND lognot.device_id = ?';
|
||||
params.push(filter['device_id']);
|
||||
}
|
||||
if (filter['drv_id']) {
|
||||
where += ' AND lognot.drv_id = ?';
|
||||
params.push(filter['drv_id']);
|
||||
}
|
||||
|
||||
const query = `SELECT lognot.*${select} FROM t_logs_sch_notif as lognot ${join} WHERE lognot.crt != 0 ${where} ${group_by} ${order_by} ${limit};`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.getDbMysqlConn();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static insLog (insLog = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
|
||||
if (Object.keys(insLog).length > 0) result = await MysqlHelpers.queryTrx(conn, `INSERT INTO t_logs_sch_notif SET ?;`, [insLog]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static delLogs (condition = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], where = '';
|
||||
|
||||
if (condition['fcm_token']) {
|
||||
where += ' AND fcm_token = ?';
|
||||
params.push(condition['id']);
|
||||
}
|
||||
if (condition['device_id']) {
|
||||
where += ' AND device_id = ?';
|
||||
params.push(condition['device_id']);
|
||||
}
|
||||
if (condition['drv_id']) {
|
||||
where += ' AND drv_id = ?';
|
||||
params.push(condition['drv_id']);
|
||||
}
|
||||
if (condition['notif_type']) {
|
||||
where += ' AND notif_type = ?';
|
||||
params.push(condition['notif_type']);
|
||||
}
|
||||
|
||||
const query = `DELETE from t_logs_sch_notif WHERE crt is not null ${where};`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
const result = await MysqlHelpers.queryTrx(conn, query, params);
|
||||
await MysqlHelpers.commit(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LogsSchNotifModels;
|
||||
88
models/OrdersAItemsModels.js
Normal file
88
models/OrdersAItemsModels.js
Normal file
@ -0,0 +1,88 @@
|
||||
// const db = require(`../config/dbMysqlConn`);
|
||||
// const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class OrdersAItemsModels {
|
||||
|
||||
static FLOW_TYPE_PAYMENT = 1;
|
||||
static FLOW_TYPE_BILLING = 2;
|
||||
static FLOW_TYPE_HYBRID = 3;
|
||||
|
||||
static TYPE_CASH_OUT = 1;
|
||||
static TYPE_CASH_IN = 2;
|
||||
static TYPE_CASH_HYBRID = 3;
|
||||
|
||||
static A_TYPE_PRIMARY = 1;
|
||||
static A_TYPE_SECONDARY = 2;
|
||||
|
||||
static AMT_TYPE_FLAT = 1;
|
||||
static AMT_TYPE_PERCENT = 2;
|
||||
|
||||
// 1=>refer ddln_pay_at, 2=>refer to order finish(pengantaran selesai)
|
||||
static DDLN_PAY_TYPE_TIME = 1;
|
||||
static DDLN_PAY_TYPE_ORD_FINISH = 2;
|
||||
|
||||
static IS_PAID_NO = 0;
|
||||
static IS_PAID_YES = 1;
|
||||
|
||||
static IS_HIDDEN_NO = 0;
|
||||
static IS_HIDDEN_YES = 1;
|
||||
|
||||
// tax yang berlaku utk 1 row saja
|
||||
static IS_TAX_NO = 0;
|
||||
static IS_TAX_YES = 1;
|
||||
|
||||
static IS_DISC_NO = 0;
|
||||
static IS_DISC_YES = 1;
|
||||
|
||||
static IS_SUBTRACT_NO = 0;
|
||||
static IS_SUBTRACT_YES = 1;
|
||||
|
||||
// 1=>transfer
|
||||
static PAID_TYPE_TF = 1;
|
||||
|
||||
static INVC_TO_CLIENT_YES = 1;
|
||||
static INVC_TO_CLIENT_NO = 2;
|
||||
|
||||
static CALC_TO_VDR_YES = 1;
|
||||
static CALC_TO_VDR_NO = 2;
|
||||
|
||||
static ONLY_CLIENT_YES = 1;
|
||||
static ONLY_CLIENT_NO = 2;
|
||||
|
||||
static ONLY_VDR_YES = 1;
|
||||
static ONLY_VDR_NO = 2;
|
||||
|
||||
static IS_ADM_PRICE_NO = 0;
|
||||
static IS_ADM_PRICE_YES = 1;
|
||||
|
||||
static IS_APRV_NO = 0;
|
||||
static IS_APRV_YES = 1;
|
||||
|
||||
static IS_ACTIVE_NO = 0;
|
||||
static IS_ACTIVE_YES = 1;
|
||||
|
||||
// tax yang include dengan itemnya
|
||||
static AMT_TAX_TYPE_WITHOUT = 0; // tanpa pajak
|
||||
static AMT_TAX_TYPE_INCLUDE = 1; // termasuk pajak || pajak dibayarkan sendiri oleh (client/vendor)
|
||||
static AMT_TAX_TYPE_EXCLUDE = 2; // belum termasuk pajak || pajak dibayarkan oleh bonceng
|
||||
static PPN_PERCENT = 1.1;
|
||||
static PPN_PERCENT_INCLUDE = 1.011;
|
||||
static PPH_PERCENT = 2;
|
||||
|
||||
// merge satuan
|
||||
static IS_MERGE_NO = 0;
|
||||
static IS_MERGE_YES = 1;
|
||||
|
||||
// merge per trx
|
||||
static STTS_MERGE_NO = 0;
|
||||
static STTS_MERGE_TO = 1;
|
||||
static STTS_MERGE_RESULT = 2;
|
||||
|
||||
// 0=>system, 1=>admin, 2=>finance
|
||||
static CRT_TYPE_SYSTEM = 0;
|
||||
static CRT_TYPE_ADMIN = 1;
|
||||
static CRT_TYPE_FINANCE = 2;
|
||||
|
||||
}
|
||||
|
||||
module.exports = OrdersAItemsModels;
|
||||
120
models/OrdersCheckpointsModels.js
Normal file
120
models/OrdersCheckpointsModels.js
Normal file
@ -0,0 +1,120 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class OrdersCheckpointsModels {
|
||||
|
||||
static IS_UNPAID = 0;
|
||||
static IS_PAID_OFF = 1;
|
||||
static IS_TF_FAIL = 2;
|
||||
|
||||
static TF_METHOD_MANUAL = 1;
|
||||
static TF_METHOD_DANA = 2;
|
||||
|
||||
static list(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select = '', where = '', join = '', order_by = '', group_by = '', limit = '';
|
||||
|
||||
if (filter['checkpoint_id']) {
|
||||
where += ' AND checkpoint.id = ?';
|
||||
params.push(filter['checkpoint_id']);
|
||||
}
|
||||
if (filter['ord_id']) {
|
||||
where += ' AND checkpoint.ord_id = ?';
|
||||
params.push(filter['ord_id']);
|
||||
}
|
||||
if (filter['ord_pocket_id']) {
|
||||
where += ' AND checkpoint.ord_pocket_id = ?';
|
||||
params.push(filter['ord_pocket_id']);
|
||||
}
|
||||
if (filter['pck_id']) {
|
||||
where += ' AND checkpoint.pck_id = ?';
|
||||
params.push(filter['pck_id']);
|
||||
}
|
||||
|
||||
if (filter['did']) {
|
||||
where += ' AND ord_drv.drv_id = ?';
|
||||
params.push(filter['did']);
|
||||
}
|
||||
|
||||
if (filter['is_paid']) {
|
||||
where += ' AND checkpoint.pocket_is_paid = ?';
|
||||
params.push(filter['is_paid']);
|
||||
}
|
||||
|
||||
if (filter['select_paid_by']) {
|
||||
where += ' ,(SELECT first_name FROM t_users WHERE id = checkpoint.pocket_paid_by LIMIT 1) as pocket_paid_by_name';
|
||||
params.push(filter['is_paid']);
|
||||
}
|
||||
|
||||
if (filter['group_by']) {
|
||||
group_by = filter['group_by'];
|
||||
}
|
||||
|
||||
if (filter['limit']) {
|
||||
limit = ' LIMIT ' + filter['limit'];
|
||||
}
|
||||
|
||||
let query = `SELECT
|
||||
ord.id as ord_id,ord.code as ord_code
|
||||
,checkpoint.id as checkpoint_id,checkpoint.ord_pocket_id,checkpoint.pocket_sort,checkpoint.pocket_total
|
||||
,checkpoint.pocket_is_paid,checkpoint.pocket_paid_at,checkpoint.pocket_paid_by
|
||||
,ord_drv.drv_id,ord_drv.drv_name,ord_drv.drv_phone_code,ord_drv.drv_phone_val,ord_drv.drv_mail,ord_drv.drv_addr
|
||||
,ord_drv.drv_name2,ord_drv.drv_phone2_code,ord_drv.drv_phone2_val
|
||||
${select}
|
||||
FROM t_orders_checkpoints as checkpoint
|
||||
INNER JOIN t_orders as ord ON checkpoint.ord_id = ord.id
|
||||
INNER JOIN t_orders_drivers as ord_drv ON checkpoint.ord_id = ord_drv.ord_id
|
||||
${join}
|
||||
WHERE checkpoint.dlt is null
|
||||
${where}
|
||||
${group_by}
|
||||
${order_by}
|
||||
${limit}
|
||||
;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static bundleUpdt (updtOrdCheckpoint = {}, insOrdAItems = {}, insOrdLogsTf = {}, updtDana = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
|
||||
if (Object.keys(updtOrdCheckpoint).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_checkpoints SET ? WHERE id = ?;`, [updtOrdCheckpoint, updtOrdCheckpoint.id]);
|
||||
if (Object.keys(insOrdAItems).length > 0) result = await MysqlHelpers.queryTrx(conn, `INSERT INTO t_orders_a_items SET ?;`, [insOrdAItems]);
|
||||
if (Object.keys(insOrdLogsTf).length > 0) result = await MysqlHelpers.queryTrx(conn, `INSERT INTO t_orders_logs_tf SET ?;`, [insOrdLogsTf]);
|
||||
if (Object.keys(updtDana).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_dana SET ? WHERE id = ?;`, [updtDana, updtDana.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = OrdersCheckpointsModels;
|
||||
68
models/OrdersDriversUploadsModels.js
Normal file
68
models/OrdersDriversUploadsModels.js
Normal file
@ -0,0 +1,68 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
// const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class OrdersDriversUploadsModels {
|
||||
|
||||
// t_orders_drivers_uploads
|
||||
static PHOTO_STATUS_OTW_PICKUP = 1;
|
||||
static PHOTO_STATUS_ARRIVED_PICKUP = 2;
|
||||
static PHOTO_STATUS_PROCESS_PICKUP = 3;
|
||||
static PHOTO_STATUS_FINISH_PICKUP = 4;
|
||||
static PHOTO_STATUS_TRAVEL_DOCUMENT = 5;
|
||||
static PHOTO_STATUS_OTW_DROP = 6;
|
||||
static PHOTO_STATUS_ARRIVED_DROP = 7;
|
||||
static PHOTO_STATUS_PROCESS_DROP = 8;
|
||||
static PHOTO_STATUS_FINISH_DROP = 9;
|
||||
static PHOTO_STATUS_HANDOVER_DOCUMENT = 10;
|
||||
static PHOTO_STATUS_ACCIDENT = 11;
|
||||
|
||||
static IS_INACTIVE = 0;
|
||||
static IS_ACTIVE = 1;
|
||||
|
||||
static list(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select = '', where = '', join = '', limit = '';
|
||||
|
||||
if (filter['id']) {
|
||||
where += ' AND drv_up.id = ?';
|
||||
params.push(filter['id']);
|
||||
}
|
||||
if (filter['ord_id']) {
|
||||
where += ' AND drv_up.ord_id = ?';
|
||||
params.push(filter['ord_id']);
|
||||
}
|
||||
if (filter['ord_code']) {
|
||||
where += ' AND drv_up.ord_code = ?';
|
||||
params.push(filter['ord_code']);
|
||||
}
|
||||
if (filter['did']) {
|
||||
where += ' AND drv_up.did = ?';
|
||||
params.push(filter['did']);
|
||||
}
|
||||
if (filter['pck_id']) {
|
||||
where += ' AND drv_up.pck_id = ?';
|
||||
params.push(filter['pck_id']);
|
||||
}
|
||||
if (filter['drop_id']) {
|
||||
where += ' AND drv_up.drop_id = ?';
|
||||
params.push(filter['drop_id']);
|
||||
}
|
||||
if (filter['ord_pck_drop_id']) {
|
||||
where += ' AND drv_up.ord_pck_drop_id = ?';
|
||||
params.push(filter['ord_pck_drop_id']);
|
||||
}
|
||||
|
||||
const query = `SELECT drv_up.*${select} FROM t_orders_drivers_uploads as drv_up ${join} WHERE drv_up.dlt is null ${where} ${limit};`;
|
||||
db.query(query, params, (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = OrdersDriversUploadsModels;
|
||||
36
models/OrdersDropsModels.js
Normal file
36
models/OrdersDropsModels.js
Normal file
@ -0,0 +1,36 @@
|
||||
// const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class OrdersDropsModels {
|
||||
|
||||
// t_orders_drops
|
||||
static STTS_DROP_WAIT = 1;
|
||||
static STTS_DROP_DROPPING = 2;
|
||||
static STTS_DROP_DROPED = 3;
|
||||
static STTS_DROP_FAIL = 4;
|
||||
|
||||
static updt (updtDrop = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
|
||||
if (Object.keys(updtDrop).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_drops SET ? WHERE id = ?;`, [updtDrop, updtDrop.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = OrdersDropsModels;
|
||||
129
models/OrdersLogsTfModels.js
Normal file
129
models/OrdersLogsTfModels.js
Normal file
@ -0,0 +1,129 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class OrdersLogsTfModels {
|
||||
|
||||
static TYPE_TF_CHECKPOINT = 1;
|
||||
|
||||
static STTS_UNPAID = 0;
|
||||
static STTS_PAID = 1;
|
||||
static STTS_FAIL = 2;
|
||||
static STTS_PENDING = 3;
|
||||
|
||||
static METHOD_MANUAL = 1;
|
||||
static METHOD_DANA = 2;
|
||||
|
||||
static list(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select = '', where = '', join = '', order_by = '', group_by = '', limit = '';
|
||||
|
||||
if (filter['log_tf_id']) {
|
||||
where += ' AND log_tf.id = ?';
|
||||
params.push(filter['log_tf_id']);
|
||||
}
|
||||
if (filter['ord_id']) {
|
||||
where += ' AND log_tf.ord_id = ?';
|
||||
params.push(filter['ord_id']);
|
||||
}
|
||||
if (filter['ord_code']) {
|
||||
where += ' AND log_tf.ord_code = ?';
|
||||
params.push(filter['ord_code']);
|
||||
}
|
||||
if (filter['checkpoint_id']) {
|
||||
where += ' AND log_tf.checkpoint_id = ?';
|
||||
params.push(filter['checkpoint_id']);
|
||||
}
|
||||
if (filter['type']) {
|
||||
where += ' AND log_tf.type = ?';
|
||||
params.push(filter['type']);
|
||||
}
|
||||
if (filter['method']) {
|
||||
where += ' AND log_tf.method = ?';
|
||||
params.push(filter['method']);
|
||||
}
|
||||
|
||||
if (filter['group_by']) {
|
||||
group_by = filter['group_by'];
|
||||
}
|
||||
|
||||
if (filter['limit']) {
|
||||
limit = ' LIMIT ' + filter['limit'];
|
||||
}
|
||||
|
||||
let query = `SELECT
|
||||
log_tf.*
|
||||
${select}
|
||||
FROM t_orders_logs_tf as log_tf
|
||||
${join}
|
||||
WHERE log_tf.dlt is null
|
||||
${where}
|
||||
${group_by}
|
||||
${order_by}
|
||||
${limit}
|
||||
;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static bundleIns (insOrdLogsTf = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
|
||||
if (Object.keys(insOrdLogsTf).length > 0) result = await MysqlHelpers.queryTrx(conn, `INSERT INTO t_orders_logs_tf SET ?;`, [insOrdLogsTf]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static bundleUpdt (updtOrdLogsTf = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
|
||||
if (Object.keys(updtOrdLogsTf).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_logs_tf SET ? WHERE id = ?;`, [updtOrdLogsTf, updtOrdLogsTf.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = OrdersLogsTfModels;
|
||||
702
models/OrdersModels.js
Normal file
702
models/OrdersModels.js
Normal file
@ -0,0 +1,702 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
const OrdersVendors = require('./OrdersVendorsModels');
|
||||
const UsersModels = require('./UsersModels');
|
||||
|
||||
class OrdersModels {
|
||||
|
||||
static ONE_KG_ONE_CBM = 1328;
|
||||
|
||||
static TYPE_FCL = 1;
|
||||
static TYPE_LCL = 2;
|
||||
|
||||
static STTS_WAIT = 1;
|
||||
static STTS_CONFIRM = 21;
|
||||
static STTS_HAVE_GET_VHC = 22;
|
||||
static STTS_PCK = 2;
|
||||
static STTS_GO = 3;
|
||||
static STTS_ARV = 4;
|
||||
static STTS_DROP = 5;
|
||||
static STTS_CLIENT_PAY = 6;
|
||||
static STTS_VENDOR_PAYED = 8;
|
||||
static STTS_CLOSE = 10;
|
||||
static STTS_CANCEL = 11;
|
||||
|
||||
static IS_FIX_PRICE_NO = 0;
|
||||
static IS_FIX_PRICE_YES = 1;
|
||||
|
||||
static IS_INACTIVE = 0;
|
||||
static IS_ACTIVE = 1;
|
||||
|
||||
static IS_ACCIDENT = 1;
|
||||
|
||||
static CANCEL_TYPE_IGNORE = 1;
|
||||
static CANCEL_TYPE_CLIENT = 2;
|
||||
static CANCEL_TYPE_VDR_NOT_READY = 3;
|
||||
|
||||
static listOrders(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select_order = '', where_order = '', join_order = '', order_by = '', group_by = '';
|
||||
|
||||
if (filter['ord_id']) {
|
||||
where_order += ' AND ord.id = ?';
|
||||
params.push(filter['ord_id']);
|
||||
}
|
||||
if (filter['pck_id']) {
|
||||
where_order += ' AND ord_pck.id = ?';
|
||||
params.push(filter['pck_id']);
|
||||
}
|
||||
if (filter['drop_id']) {
|
||||
where_order += ' AND ord_drop.id = ?';
|
||||
params.push(filter['drop_id']);
|
||||
}
|
||||
|
||||
if (filter['did']) {
|
||||
where_order += ' AND ord_drv.drv_id = ?';
|
||||
params.push(filter['did']);
|
||||
}
|
||||
|
||||
if (filter['is_active']) {
|
||||
where_order += ' AND ord.is_active = ?';
|
||||
params.push(filter['is_active']);
|
||||
}
|
||||
|
||||
if (filter['order_status'] && filter['order_status'].length > 0) {
|
||||
where_order += ' AND ord.status IN (';
|
||||
for (const order_status of filter['order_status']) {
|
||||
where_order += '?,';
|
||||
params.push(order_status);
|
||||
}
|
||||
where_order = where_order.slice(0, -1) + ')';
|
||||
}
|
||||
|
||||
if (filter['delivery_statuses'] && filter['delivery_statuses'].length > 0) {
|
||||
where_order += ' AND ord_pck_drop.stts IN (';
|
||||
for (const delivery_statuses of filter['delivery_statuses']) {
|
||||
where_order += '?,';
|
||||
params.push(delivery_statuses);
|
||||
}
|
||||
where_order = where_order.slice(0, -1) + ')';
|
||||
}
|
||||
|
||||
if (filter['center_pck']) {
|
||||
select_order += ',ST_AsText(ST_Centroid(pck_points)) as pck_center';
|
||||
}
|
||||
|
||||
if (filter['get_prefer_type_truck']) {
|
||||
select_order += ',tt.name as prefer_truck_type_name';
|
||||
join_order += ' LEFT JOIN t_vehicles_types as tt ON ord_c.prefer_truck_type = tt.id';
|
||||
}
|
||||
|
||||
if (filter['get_pic_zone']) {
|
||||
select_order += ',ord_pck.pic_name as pck_pic_name,ord_pck.pic_phone_code as pck_pic_phone_code,ord_pck.pic_phone_val as pck_pic_phone_val,ord_pck.pic_mail as pck_pic_mail';
|
||||
select_order += ',ord_drop.pic_name as drop_pic_name,ord_drop.pic_phone_code as drop_pic_phone_code,ord_drop.pic_phone_val as drop_pic_phone_val,ord_drop.pic_mail as drop_pic_mail';
|
||||
}
|
||||
if (filter['get_client_pt']) {
|
||||
select_order += ',ord_c.c_pt_id,ord_c.c_pt_name,ord_c.c_pt_phone_code,ord_c.c_pt_phone_val,ord_c.c_pt_mail,ord_c.c_pt_addr';
|
||||
select_order += ',ord_c.c_pt_pic_name,ord_c.c_pt_pic_phone_code,ord_c.c_pt_pic_phone_val,ord_c.c_pt_pic_mail,ord_c.c_pt_pic_addr';
|
||||
}
|
||||
|
||||
if (filter['get_exp_vendor']) {
|
||||
select_order += ',ord_vdr.is_exp as vdr_is_exp,ord_vdr.exp_at as vdr_exp_at';
|
||||
}
|
||||
if (filter['vdr_id']) {
|
||||
select_order += ',ord_vdr.find_vhcs';
|
||||
where_order += ' AND ord_vdr.vdr_id = ?';
|
||||
params.push(filter['vdr_id']);
|
||||
join_order += " LEFT JOIN t_orders_vendors as ord_vdr ON ord.id = ord_vdr.ord_id";
|
||||
} else {
|
||||
// join_order += `
|
||||
// LEFT JOIN ( SELECT MIN(respond_at) as respond_at,ord_id,vdr_id FROM t_orders_vendors WHERE status = ${OrdersVendors.STTS_ACC} GROUP BY ord_id ) AS ord_vdr1 ON (ord.id = ord_vdr1.ord_id)
|
||||
// LEFT JOIN t_orders_vendors as ord_vdr ON ( ord_vdr.respond_at = ord_vdr1.respond_at)
|
||||
// `;
|
||||
}
|
||||
|
||||
if (filter['get_drv_bank']) {
|
||||
select += ',ord_drv.drv_bank_id,ord_drv.drv_bank_code,ord_drv.drv_bank_name,ord_drv.drv_bank_short_name,ord_drv.drv_bank_branch_name,ord_drv.drv_bank_acc_number,ord_drv.drv_bank_acc_name';
|
||||
}
|
||||
|
||||
if (filter['couple_pck_drop']) {
|
||||
select_order += ' ,ord_pck_drop.id as ord_pck_drop_id,ord_pck_drop.stts as stts_delivery,ord_pck_drop.is_aprv_pck,ord_pck_drop.aprv_pck_by,ord_pck_drop.aprv_pck_at,ord_pck_drop.drv_app_lock_menu_otw_drop_at';
|
||||
join_order += " INNER JOIN t_orders_pck_drop as ord_pck_drop ON ord.id = ord_pck_drop.ord_id";
|
||||
join_order += " INNER JOIN t_orders_pickups as ord_pck ON ord_pck_drop.pck_id = ord_pck.id";
|
||||
join_order += " INNER JOIN t_orders_drops as ord_drop ON ord_pck_drop.drop_id = ord_drop.id";
|
||||
} else {
|
||||
join_order += " INNER JOIN t_orders_pickups as ord_pck ON ord.id = ord_pck.ord_id";
|
||||
join_order += " INNER JOIN t_orders_drops as ord_drop ON ord.id = ord_drop.ord_id";
|
||||
}
|
||||
|
||||
if (filter['ord_pck_drop_id']) {
|
||||
where_order += ' AND ord_pck_drop.id = ?';
|
||||
params.push(filter['ord_pck_drop_id']);
|
||||
}
|
||||
|
||||
if (filter['get_stts_checker']) {
|
||||
select_order += ' ,ord_pck.chk_id as pck_chk_id,ord_pck.chk_at as pck_chk_at,ord_pck.chk_stts as pck_chk_stts';
|
||||
select_order += ' ,ord_drop.chk_id as drop_chk_id,ord_drop.chk_at as drop_chk_at,ord_drop.chk_stts as drop_chk_stts';
|
||||
}
|
||||
if (filter['chk_id']) {
|
||||
if (filter['chk_type'] == UsersModels.CHK_TYPE_PICKUP) {
|
||||
where_order += ' AND (ord_pck.chk_id = ? OR ord_pck.chk_id = 0) ';
|
||||
params.push(filter['chk_id']);
|
||||
} else if (filter['chk_type'] == UsersModels.CHK_TYPE_DROP) {
|
||||
where_order += ' AND (ord_drop.chk_id = ? OR ord_drop.chk_id = 0) ';
|
||||
params.push(filter['chk_id']);
|
||||
}
|
||||
}
|
||||
|
||||
if (filter['get_bid_info']) {
|
||||
select_order += ' ,ord_vdr.is_mailing_bid,ord_vdr.is_mailing_bid_at,ord_vdr.is_want,ord_vdr.is_want_at';
|
||||
}
|
||||
|
||||
if (filter['inner_join_phone_devices']) {
|
||||
select_order += ' ,phn_drv.device_id as drv_device_id,phn_drv.fcm_token as drv_fcm_token';
|
||||
join_order += ' INNER JOIN t_phone_devices as phn_drv ON phn_drv.did = ord_drv.drv_id';
|
||||
}
|
||||
if (filter['phone_devices_is_login']) {
|
||||
where_order += ' AND phn_drv.is_login = ?';
|
||||
params.push(filter['phone_devices_is_login']);
|
||||
}
|
||||
|
||||
if (filter['last_tracks_phone_drv']) {
|
||||
// get last updated row from many rows
|
||||
select_order += ' ,tr.id as tr_id,tr.device_id as tr_device_id,tr.latitude as tr_latitude,tr.longitude as tr_longitude,tr.speed as tr_speed,tr.drv_id as tr_drv_id,tr.crt as tr_crt,tr.crt_d as tr_crt_d';
|
||||
join_order += ' LEFT JOIN ( SELECT MAX(crt) max_crt, device_id, drv_id FROM t_gps_tracks WHERE latitude is not null AND longitude is not null GROUP BY drv_id ORDER BY crt DESC ) AS tr1 ON (ord_drv.drv_id = tr1.drv_id)';
|
||||
join_order += ' LEFT JOIN t_gps_tracks AS tr ON (tr.crt = tr1.max_crt)';
|
||||
}
|
||||
|
||||
if (filter['group_by']) {
|
||||
group_by = filter['group_by'];
|
||||
}
|
||||
if (filter['order_by']) {
|
||||
order_by = filter['order_by'];
|
||||
}
|
||||
|
||||
let query = `SELECT
|
||||
ord.*
|
||||
,ord.id as ord_id,ord.code as ord_code
|
||||
,ord_pck.id as ord_pck_id,ord_pck.pck_id,ord_pck.pck_name,ord_pck.pck_addr,ord_pck.set_pck_at,ord_pck.pck_at,ord_pck.pck_enter_at,ord_pck.pck_leave_at
|
||||
,ord_drop.id as ord_drop_id,ord_drop.drop_id,ord_drop.drop_name,ord_drop.drop_addr,ord_drop.drop_at,ord_drop.drop_enter_at,ord_drop.drop_leave_at
|
||||
,ord_c.id as ord_client_id,ord_c.c_id,ord_c.c_name,ord_c.c_phone_code,ord_c.c_phone_val,ord_c.c_mail,ord_c.prefer_truck_type
|
||||
,ord_vdr.id as ord_vdr_id,ord_vdr.vdr_id,ord_vdr.vdr_name,ord_vdr.vdr_phone_code,ord_vdr.vdr_phone_val,ord_vdr.vdr_mail,ord_vdr.vdr_addr,ord_vdr.status as vdr_status,ord_vdr.respond_at as vdr_respond_at,ord_vdr.crt as vdr_crt
|
||||
,ord_drv.drv_id,ord_drv.drv_name,ord_drv.drv_phone_code,ord_drv.drv_phone_val,ord_drv.drv_mail,ord_drv.drv_addr
|
||||
,ord_drv.drv_name2,ord_drv.drv_phone2_code,ord_drv.drv_phone2_val
|
||||
,ord_vhc.vhc_id,ord_vhc.vhc_name,ord_vhc.vhc_nopol1,ord_vhc.vhc_nopol2,ord_vhc.vhc_nopol3
|
||||
${select_order}
|
||||
FROM t_orders as ord
|
||||
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||
LEFT JOIN ( SELECT MIN(respond_at) as respond_at,ord_id,vdr_id FROM t_orders_vendors WHERE status = ${OrdersVendors.STTS_ACC} GROUP BY ord_id ) AS ord_vdr1 ON (ord.id = ord_vdr1.ord_id)
|
||||
LEFT JOIN t_orders_vendors as ord_vdr ON ( ord_vdr.respond_at = ord_vdr1.respond_at)
|
||||
LEFT JOIN t_orders_drivers as ord_drv ON ord.id = ord_drv.ord_id
|
||||
LEFT JOIN t_orders_vehicles as ord_vhc ON ord.id = ord_vhc.ord_id
|
||||
${join_order}
|
||||
WHERE ord.dlt is null
|
||||
${where_order}
|
||||
${group_by}
|
||||
ORDER BY ord.id ASC
|
||||
;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static listActiveOrdVhc(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select_order = '', where_order = '', join_order = '';
|
||||
|
||||
if (filter['did']) {
|
||||
where_order += ' AND ord_drv.drv_id = ?';
|
||||
params.push(filter['did']);
|
||||
}
|
||||
|
||||
if (filter['order_status'] && filter['order_status'].length > 0) {
|
||||
where_order += ' AND ord.status IN (';
|
||||
for (const order_status of filter['order_status']) {
|
||||
where_order += '?,';
|
||||
params.push(order_status);
|
||||
}
|
||||
where_order = where_order.slice(0, -1) + ')';
|
||||
}
|
||||
|
||||
let query = `SELECT
|
||||
ord.*
|
||||
,ord.id as ord_id,ord.code as ord_code
|
||||
,ord_vdr.id as ord_vdr_id,ord_vdr.vdr_id,ord_vdr.vdr_name,ord_vdr.vdr_phone_code,ord_vdr.vdr_phone_val,ord_vdr.vdr_mail,ord_vdr.vdr_addr,ord_vdr.status as vdr_status,ord_vdr.respond_at as vdr_respond_at,ord_vdr.crt as vdr_crt
|
||||
,ord_drv.drv_id,ord_drv.drv_name,ord_drv.drv_phone_code,ord_drv.drv_phone_val,ord_drv.drv_mail,ord_drv.drv_addr
|
||||
,ord_drv.drv_name2,ord_drv.drv_phone2_code,ord_drv.drv_phone2_val
|
||||
,ord_vhc.vhc_id,ord_vhc.vhc_name,ord_vhc.vhc_nopol1,ord_vhc.vhc_nopol2,ord_vhc.vhc_nopol3
|
||||
${select_order}
|
||||
FROM t_orders as ord
|
||||
LEFT JOIN t_orders_vendors as ord_vdr ON ord.id = ord_vdr.ord_id
|
||||
LEFT JOIN t_orders_drivers as ord_drv ON ord.id = ord_drv.ord_id
|
||||
LEFT JOIN t_orders_vehicles as ord_vhc ON ord.id = ord_vhc.ord_id
|
||||
${join_order}
|
||||
WHERE ord.dlt is null
|
||||
AND ord.is_active = 1
|
||||
${where_order}
|
||||
ORDER BY ord.id ASC
|
||||
;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static showOrder(filter) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let params = [], select_order = '', where_order = '', join_order = '';
|
||||
|
||||
if (filter['id']) {
|
||||
where_order += ' AND ord.id = ? ';
|
||||
params.push(filter['id']);
|
||||
} else if (filter['code']) {
|
||||
where_order += ' AND ord.code = ? ';
|
||||
params.push(filter['code']);
|
||||
} else {
|
||||
reject(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (filter['is_active']) {
|
||||
where_order += ' AND ord.is_active = ?';
|
||||
params.push(filter['is_active']);
|
||||
}
|
||||
|
||||
if (filter['center_pck']) {
|
||||
select_order += ',ST_AsText(ST_Centroid(pck_points)) as pck_center';
|
||||
}
|
||||
|
||||
if (filter['get_prefer_type_truck']) {
|
||||
select_order += ',tt.name as prefer_truck_type_name';
|
||||
join_order += ' LEFT JOIN t_vehicles_types as tt ON ord_c.prefer_truck_type = tt.id';
|
||||
}
|
||||
|
||||
if (filter['get_pic_zone']) {
|
||||
select_order += ',ord_pck.pic_name as pck_pic_name,ord_pck.pic_phone_code as pck_pic_phone_code,ord_pck.pic_phone_val as pck_pic_phone_val,ord_pck.pic_mail as pck_pic_mail';
|
||||
select_order += ',ord_drop.pic_name as drop_pic_name,ord_drop.pic_phone_code as drop_pic_phone_code,ord_drop.pic_phone_val as drop_pic_phone_val,ord_drop.pic_mail as drop_pic_mail';
|
||||
}
|
||||
if (filter['get_client_pt']) {
|
||||
select_order += ',ord_c.c_pt_id,ord_c.c_pt_name,ord_c.c_pt_phone_code,ord_c.c_pt_phone_val,ord_c.c_pt_mail,ord_c.c_pt_addr';
|
||||
select_order += ',ord_c.c_pt_pic_name,ord_c.c_pt_pic_phone_code,ord_c.c_pt_pic_phone_val,ord_c.c_pt_pic_mail,ord_c.c_pt_pic_addr';
|
||||
}
|
||||
|
||||
if (filter['get_exp_vendor']) {
|
||||
select_order += ',ord_vdr.is_exp as vdr_is_exp,ord_vdr.exp_at as vdr_exp_at';
|
||||
}
|
||||
if (filter['vdr_id']) {
|
||||
select_order += ',ord_vdr.find_vhcs';
|
||||
where_order += ' AND ord_vdr.vdr_id = ?';
|
||||
params.push(filter['vdr_id']);
|
||||
join_order += " LEFT JOIN t_orders_vendors as ord_vdr ON ord.id = ord_vdr.ord_id";
|
||||
} else {
|
||||
// join_order += `
|
||||
// LEFT JOIN ( SELECT MIN(respond_at) as respond_at,ord_id,vdr_id FROM t_orders_vendors WHERE status = ${OrdersVendors.STTS_ACC} GROUP BY ord_id ) AS ord_vdr1 ON (ord.id = ord_vdr1.ord_id)
|
||||
// LEFT JOIN t_orders_vendors as ord_vdr ON ( ord_vdr.respond_at = ord_vdr1.respond_at)
|
||||
// `;
|
||||
}
|
||||
|
||||
if (filter['get_stts_checker']) {
|
||||
select_order += ' ,ord_pck.chk_id as pck_chk_id,ord_pck.chk_at as pck_chk_at,ord_pck.chk_stts as pck_chk_stts';
|
||||
select_order += ' ,ord_drop.chk_id as drop_chk_id,ord_drop.chk_at as drop_chk_at,ord_drop.chk_stts as drop_chk_stts';
|
||||
}
|
||||
if (filter['chk_id']) {
|
||||
if (filter['chk_type'] == UsersModels.CHK_TYPE_PICKUP) {
|
||||
where_order += ' AND (ord_pck.chk_id = ? OR ord_pck.chk_id = 0) ';
|
||||
params.push(filter['chk_id']);
|
||||
} else if (filter['chk_type'] == UsersModels.CHK_TYPE_DROP) {
|
||||
where_order += ' AND (ord_drop.chk_id = ? OR ord_drop.chk_id = 0) ';
|
||||
params.push(filter['chk_id']);
|
||||
}
|
||||
}
|
||||
|
||||
if (filter['get_bid_info']) {
|
||||
select_order += ' ,ord_vdr.is_mailing_bid,ord_vdr.is_mailing_bid_at,ord_vdr.is_want,ord_vdr.is_want_at';
|
||||
}
|
||||
|
||||
let query = `SELECT
|
||||
ord.*
|
||||
,ord.id as ord_id,ord.code as ord_code
|
||||
,ord_pck.id as ord_pck_id,ord_pck.pck_id,ord_pck.pck_name,ord_pck.pck_addr,ord_pck.set_pck_at,ord_pck.pck_at,ord_pck.pck_enter_at,ord_pck.pck_leave_at
|
||||
,ord_drop.id as ord_drop_id,ord_drop.drop_id,ord_drop.drop_name,ord_drop.drop_addr,ord_drop.drop_at,ord_drop.drop_enter_at,ord_drop.drop_leave_at
|
||||
,ord_c.id as ord_client_id,ord_c.c_id,ord_c.c_name,ord_c.c_phone_code,ord_c.c_phone_val,ord_c.c_mail,ord_c.prefer_truck_type
|
||||
,ord_vdr.id as ord_vdr_id,ord_vdr.vdr_id,ord_vdr.vdr_name,ord_vdr.vdr_phone_code,ord_vdr.vdr_phone_val,ord_vdr.vdr_mail,ord_vdr.vdr_addr,ord_vdr.status as vdr_status,ord_vdr.respond_at as vdr_respond_at,ord_vdr.crt as vdr_crt
|
||||
,ord_drv.drv_id,ord_drv.drv_name,ord_drv.drv_phone_code,ord_drv.drv_phone_val,ord_drv.drv_mail,ord_drv.drv_addr
|
||||
,ord_vhc.vhc_id,ord_vhc.vhc_name,ord_vhc.vhc_nopol1,ord_vhc.vhc_nopol2,ord_vhc.vhc_nopol3
|
||||
${select_order}
|
||||
FROM t_orders as ord
|
||||
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||
INNER JOIN t_orders_pickups as ord_pck ON ord.id = ord_pck.ord_id
|
||||
INNER JOIN t_orders_drops as ord_drop ON ord.id = ord_drop.ord_id
|
||||
LEFT JOIN ( SELECT MIN(respond_at) as respond_at,ord_id,vdr_id FROM t_orders_vendors WHERE status = ${OrdersVendors.STTS_ACC} GROUP BY ord_id ) AS ord_vdr1 ON (ord.id = ord_vdr1.ord_id)
|
||||
LEFT JOIN t_orders_vendors as ord_vdr ON ( ord_vdr.respond_at = ord_vdr1.respond_at)
|
||||
LEFT JOIN t_orders_drivers as ord_drv ON ord.id = ord_drv.ord_id
|
||||
LEFT JOIN t_orders_vehicles as ord_vhc ON ord.id = ord_vhc.ord_id
|
||||
${join_order}
|
||||
WHERE ord.dlt is null
|
||||
${where_order}
|
||||
;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
} catch (e) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static gets() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_orders WHERE dlt is null;';
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static getOrderById(ord_id) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_orders WHERE dlt is null AND id = ? LIMIT 1;';
|
||||
params.push(ord_id);
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static getOrderByCode(ord_code) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_orders WHERE dlt is null AND code = ? LIMIT 1;';
|
||||
params.push(ord_code);
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static getOrdersClientActive(client_id) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [];
|
||||
let stts = OrdersModels.STTS_WAIT + ',' + OrdersModels.STTS_CONFIRM + ',' + OrdersModels.STTS_HAVE_GET_VHC + ',' + OrdersModels.STTS_PCK + ',' + OrdersModels.STTS_GO + ',' + OrdersModels.STTS_ARV + ',' + OrdersModels.STTS_DROP;
|
||||
let query = `SELECT
|
||||
ord.*,ord_c.*
|
||||
,ord_c.pay_at as client_pay_at,ord_c.is_pay as client_is_pay
|
||||
FROM t_orders as ord
|
||||
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||
WHERE ord.dlt is null AND ord.status IN (?) AND ord_c.c_id = ?
|
||||
;`;
|
||||
params.push(stts, client_id);
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static getOrdersByClient(client_id, limit = 1000) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [];
|
||||
let query = `SELECT
|
||||
ord.*,ord_c.*
|
||||
,ord_c.pay_at as client_pay_at,ord_c.is_pay as client_is_pay
|
||||
FROM t_orders as ord
|
||||
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||
WHERE ord.dlt is null AND ord_c.c_id = ?
|
||||
LIMIT ?
|
||||
;`;
|
||||
params.push(client_id, limit);
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
static add(data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `INSERT INTO t_orders SET ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, data, function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Number(resp.insertId);
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static updt(id, data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `UPDATE t_orders SET ? WHERE id = ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, [data, id], function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static dlt(id) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const query = `DELETE t_orders WHERE id = ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, [id], function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static bundleInsDrvUploads (insUploads = [], updtOrd = {}, updtPck = {}, updtDrop = {}, updtPckDrop = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
for (const insUpload of insUploads) {
|
||||
await MysqlHelpers.queryTrx(conn, `INSERT INTO t_orders_drivers_uploads SET ?`, [insUpload]);
|
||||
}
|
||||
|
||||
if (Object.keys(updtOrd).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders SET ? WHERE id = ?;`, [updtOrd, updtOrd.id]);
|
||||
if (Object.keys(updtPck).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_pickups SET ? WHERE id = ?;`, [updtPck, updtPck.id]);
|
||||
if (Object.keys(updtDrop).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_drops SET ? WHERE id = ?;`, [updtDrop, updtDrop.id]);
|
||||
if (Object.keys(updtPckDrop).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_pck_drop SET ? WHERE id = ?;`, [updtPckDrop, updtPckDrop.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static bundleUpdtTrxDriverAps (updtOrd = {}, updtPck = {}, updtDrop = {}, updtOrdAcdnt = {}, updtPckDrop = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
|
||||
if (Object.keys(updtOrd).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders SET ? WHERE id = ?;`, [updtOrd, updtOrd.id]);
|
||||
if (Object.keys(updtPck).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_pickups SET ? WHERE id = ?;`, [updtPck, updtPck.id]);
|
||||
if (Object.keys(updtDrop).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_drops SET ? WHERE id = ?;`, [updtDrop, updtDrop.id]);
|
||||
if (Object.keys(updtOrdAcdnt).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_accidents SET ? WHERE id = ?;`, [updtOrdAcdnt, updtOrdAcdnt.id]);
|
||||
if (Object.keys(updtPckDrop).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_pck_drop SET ? WHERE id = ?;`, [updtPckDrop, updtPckDrop.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = OrdersModels;
|
||||
90
models/OrdersPckDropsModels.js
Normal file
90
models/OrdersPckDropsModels.js
Normal file
@ -0,0 +1,90 @@
|
||||
// const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class OrdersPckDropsModels {
|
||||
|
||||
// t_orders_pck_drop
|
||||
static STTS_DELIVERY_OTW_PICKUP = 1;
|
||||
static STTS_DELIVERY_ARRIVED_PICKUP = 2;
|
||||
static STTS_DELIVERY_PROCESS_PICKUP = 3;
|
||||
static STTS_DELIVERY_FINISH_PICKUP = 4;
|
||||
static STTS_DELIVERY_TRAVEL_DOC = 5;
|
||||
static STTS_DELIVERY_OTW_DROP = 6;
|
||||
static STTS_DELIVERY_ARRIVED_DROP = 7;
|
||||
static STTS_DELIVERY_PROCESS_DROP = 8;
|
||||
static STTS_DELIVERY_FINISH_DROP = 9;
|
||||
static STTS_DELIVERY_HANDOVER_DOC = 10;
|
||||
|
||||
static IS_APRV_NO = 0;
|
||||
static IS_APRV_YES = 1;
|
||||
|
||||
static listOrdPckDrop(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select = '', where = '', join = '', order_by = '', group_by = '';
|
||||
|
||||
if (filter['ord_pck_drop_id']) {
|
||||
where += ' AND ord_pck_drop.id = ?';
|
||||
params.push(filter['ord_pck_drop_id']);
|
||||
}
|
||||
if (filter['ord_id']) {
|
||||
where += ' AND ord_pck_drop.ord_id = ?';
|
||||
params.push(filter['ord_id']);
|
||||
}
|
||||
if (filter['pck_id']) {
|
||||
where += ' AND ord_pck_drop.pck_id = ?';
|
||||
params.push(filter['pck_id']);
|
||||
}
|
||||
if (filter['drop_id']) {
|
||||
where += ' AND ord_pck_drop.drop_id = ?';
|
||||
params.push(filter['drop_id']);
|
||||
}
|
||||
|
||||
if (filter['stts'] && filter['stts'].length > 0) {
|
||||
where += ' AND ord_pck_drop.stts IN (';
|
||||
for (const stts of filter['stts']) {
|
||||
where += '?,';
|
||||
params.push(stts);
|
||||
}
|
||||
where = where.slice(0, -1) + ')';
|
||||
}
|
||||
|
||||
if (filter['not_stts'] && filter['not_stts'].length > 0) {
|
||||
where += ' AND ord_pck_drop.stts NOT IN (';
|
||||
for (const stts of filter['not_stts']) {
|
||||
where += '?,';
|
||||
params.push(stts);
|
||||
}
|
||||
where = where.slice(0, -1) + ')';
|
||||
}
|
||||
|
||||
if (filter['group_by']) {
|
||||
group_by = filter['group_by'];
|
||||
}
|
||||
if (filter['order_by']) {
|
||||
order_by = filter['order_by'];
|
||||
}
|
||||
|
||||
let query = `SELECT
|
||||
ord_pck_drop.*
|
||||
${select}
|
||||
FROM t_orders_pck_drop as ord_pck_drop
|
||||
${join}
|
||||
WHERE ord_pck_drop.dlt is null
|
||||
${where}
|
||||
${group_by}
|
||||
${order_by}
|
||||
;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = OrdersPckDropsModels;
|
||||
36
models/OrdersPickupsModels.js
Normal file
36
models/OrdersPickupsModels.js
Normal file
@ -0,0 +1,36 @@
|
||||
// const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class OrdersPickupsModels {
|
||||
|
||||
// t_orders_pickups
|
||||
static STTS_PCK_WAIT = 1;
|
||||
static STTS_PCK_PICKING = 2;
|
||||
static STTS_PCK_PICKED = 3;
|
||||
static STTS_PCK_FAIL = 4;
|
||||
|
||||
static updt(updtPck = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
await MysqlHelpers.createTrx(conn);
|
||||
|
||||
let result = undefined;
|
||||
|
||||
if (Object.keys(updtPck).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_pickups SET ? WHERE id = ?;`, [updtPck, updtPck.id]);
|
||||
|
||||
await MysqlHelpers.commit(conn);
|
||||
|
||||
resolve({
|
||||
type: 'success',
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = OrdersPickupsModels;
|
||||
121
models/OrdersTerminsModels.js
Normal file
121
models/OrdersTerminsModels.js
Normal file
@ -0,0 +1,121 @@
|
||||
// const db = require(`../config/dbMysqlConn`);
|
||||
const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class OrdersTerminsModels {
|
||||
|
||||
static FLOW_TYPE_PAYMENT = 1;
|
||||
static FLOW_TYPE_BILLING = 2;
|
||||
static FLOW_TYPE_HYBRID = 3;
|
||||
|
||||
static TYPE_CASH_OUT = 1;
|
||||
static TYPE_CASH_IN = 2;
|
||||
static TYPE_CASH_HYBRID = 3;
|
||||
|
||||
static AMT_TYPE_FLAT = 1;
|
||||
static AMT_TYPE_PERCENT = 2;
|
||||
|
||||
// 1=>refer termin_ddln_at, 2=>refer to order finish(pengantaran selesai)
|
||||
static DDLN_TERMIN_TYPE_TIME = 1;
|
||||
static DDLN_TERMIN_TYPE_ORD_FINISH = 2;
|
||||
|
||||
static IS_PAID_NO = 0;
|
||||
static IS_PAID_YES = 1;
|
||||
|
||||
// 1=>transfer
|
||||
static PAID_TYPE_TF = 1;
|
||||
|
||||
// 1=>admin, 2=>finance
|
||||
static CRT_TYPE_SYSTEM = 0;
|
||||
static CRT_TYPE_ADMIN = 1;
|
||||
static CRT_TYPE_FINANCE = 2;
|
||||
|
||||
static IS_ACTIVE_NO = 0;
|
||||
static IS_ACTIVE_YES = 1;
|
||||
|
||||
// 1=>client, 2=>vendor
|
||||
static TERMIN_FOR_CLIENT = 1;
|
||||
static TERMIN_FOR_VENDOR = 2;
|
||||
|
||||
// merge per trx
|
||||
static STTS_MERGE_NO = 0;
|
||||
static STTS_MERGE_TO = 1;
|
||||
static STTS_MERGE_RESULT = 2;
|
||||
|
||||
static listWithFilter(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select = '', where = '', join = '', order_by = '', group_by = '', limit = '';
|
||||
|
||||
if (filter['ord_id']) {
|
||||
where += ' AND ord_termin.ord_id = ?';
|
||||
params.push(filter['ord_id']);
|
||||
} else if (filter['ord_code']) {
|
||||
where += ' AND ord_code = ?';
|
||||
params.push(filter['ord_code']);
|
||||
}
|
||||
|
||||
if (filter['termin_for']) {
|
||||
where += ' AND termin_for = ?';
|
||||
params.push(filter['termin_for']);
|
||||
}
|
||||
|
||||
if (filter['crt_type']) {
|
||||
where += ' AND crt_type = ?';
|
||||
params.push(filter['crt_type']);
|
||||
}
|
||||
|
||||
if (filter['termin_is_paid']) {
|
||||
where += ' AND termin_is_paid = ?';
|
||||
params.push(filter['termin_is_paid']);
|
||||
}
|
||||
|
||||
|
||||
if (filter['in_stts_merge'] && filter['in_stts_merge'].length > 0) {
|
||||
where += ' AND ord_termin.stts_merge IN (';
|
||||
for (const in_stts_merge of filter['in_stts_merge']) {
|
||||
where += '?,';
|
||||
params.push(in_stts_merge);
|
||||
}
|
||||
where = where.slice(0, -1) + ')';
|
||||
}
|
||||
|
||||
if (filter['group_by']) {
|
||||
group_by = filter['group_by'];
|
||||
}
|
||||
|
||||
if (filter['limit']) {
|
||||
limit = ' LIMIT ' + filter['limit'];
|
||||
}
|
||||
|
||||
let query = `SELECT
|
||||
ord_termin.*
|
||||
${select}
|
||||
FROM t_orders_termins as ord_termin
|
||||
${join}
|
||||
WHERE ord_termin.dlt is null
|
||||
${where}
|
||||
${group_by}
|
||||
${order_by}
|
||||
${limit}
|
||||
;`;
|
||||
try {
|
||||
const conn = await MysqlHelpers.createConnection();
|
||||
const result = await MysqlHelpers.query(conn, query, params);
|
||||
await MysqlHelpers.releaseConnection(conn);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
// db.query(query, params, function (err, resp) {
|
||||
// if (err) {
|
||||
// reject(err);
|
||||
// return false;
|
||||
// }
|
||||
// resolve(resp);
|
||||
// return true;
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = OrdersTerminsModels;
|
||||
277
models/OrdersVendorsModels.js
Normal file
277
models/OrdersVendorsModels.js
Normal file
@ -0,0 +1,277 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
|
||||
class OrdersVendorsModels {
|
||||
|
||||
static STTS_WAIT = 1;
|
||||
static STTS_ACC = 2;
|
||||
static STTS_REJECT = 3;
|
||||
static STTS_IGNORE = 4;
|
||||
static STTS_NOT_READY = 5; // want order but expired, bcs not fill data
|
||||
|
||||
static IS_NOT_PAY = 1;
|
||||
static IS_PAYED = 2;
|
||||
|
||||
static LINK_WILL_EXP = 1;
|
||||
static LINK_NOT_EXP = 2;
|
||||
|
||||
static IS_MAILING_BID_NOT = 0;
|
||||
static IS_MAILING_BID_SEND = 1;
|
||||
|
||||
static IS_WANT_IGNORE = 0;
|
||||
static IS_WANT_NO = 1;
|
||||
static IS_WANT_YES = 2;
|
||||
|
||||
static async gets() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_orders_vendors;';
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getById(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_orders_vendors WHERE id = ? LIMIT 1;';
|
||||
params.push(id);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getByOrdCode(code) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_orders_vendors WHERE ord_code = ? LIMIT 1;';
|
||||
params.push(code);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getByOrdCodeByStatus(code, status) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_orders_vendors WHERE ord_code = ? AND status = ? LIMIT 1;';
|
||||
params.push(code, status);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getByOrdIdByStatus(id, status) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_orders_vendors WHERE ord_id = ? AND status = ? LIMIT 1;';
|
||||
params.push(id, status);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getByOrdId(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_orders_vendors WHERE ord_id = ? LIMIT 1;';
|
||||
params.push(id);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getNextVendorsByOrdId(ord_id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_orders_vendors WHERE ord_id = ? AND status = ' + OrdersVendorsModels.STTS_WAIT + ' AND is_want = ' + OrdersVendorsModels.IS_WANT_IGNORE + ' ORDER BY distance ASC;';
|
||||
params.push(ord_id);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getByBidToken(tkn) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_orders_vendors WHERE bid_token = ? LIMIT 1;';
|
||||
params.push(tkn);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async add(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO t_orders_vendors SET ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, data, function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Number(resp.insertId);
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async updt(id, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `UPDATE t_orders_vendors SET ? WHERE id = ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, [data, id], function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async dlt(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `DELETE t_orders_vendors WHERE id = ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, [id], function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = OrdersVendorsModels;
|
||||
85
models/PatientsStatusModels.js
Normal file
85
models/PatientsStatusModels.js
Normal file
@ -0,0 +1,85 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
|
||||
class PatientsStatusModels {
|
||||
|
||||
static async all() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `SELECT * FROM t_patients_status;`;
|
||||
db.query(query, (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async find(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `SELECT * FROM t_patients_status WHERE id = ? LIMIT 1;`;
|
||||
db.query(query, [id], (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async findName(name) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `SELECT * FROM t_patients_status WHERE name = ? LIMIT 1;`;
|
||||
db.query(query, [name], (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async create(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO t_patients_status SET ?;`;
|
||||
db.query(query, data, (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async update(data, id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `UPDATE t_patients_status SET ? WHERE id = ?;`;
|
||||
db.query(query, [data, id], (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async delete(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `DELETE FROM t_patients_status WHERE id = ?;`;
|
||||
db.query(query, [id], (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = PatientsStatusModels;
|
||||
57
models/RegionModels.js
Normal file
57
models/RegionModels.js
Normal file
@ -0,0 +1,57 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
// const MysqlHelpers = require(`../library/LibMysqlHelper`);
|
||||
|
||||
class RegionModels {
|
||||
|
||||
static whereLike(filter = {}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = [], select = '', where = '', join = '', limit = '';
|
||||
|
||||
if (filter['nmProvinsiKel']) {
|
||||
where += ' AND region.nmProvinsiKel LIKE ?';
|
||||
params.push('%'+filter['nmProvinsiKel']+'%');
|
||||
}
|
||||
if (filter['nmKotamadyaKel']) {
|
||||
where += ' AND region.nmKotamadyaKel LIKE ?';
|
||||
params.push('%'+filter['nmKotamadyaKel']+'%');
|
||||
}
|
||||
if (filter['nmKecamatanKel']) {
|
||||
where += ' AND region.nmKecamatanKel LIKE ?';
|
||||
params.push('%'+filter['nmKecamatanKel']+'%');
|
||||
}
|
||||
if (filter['nmKelurahan']) {
|
||||
where += ' AND region.nmKelurahan LIKE ?';
|
||||
params.push('%'+filter['nmKelurahan']+'%');
|
||||
}
|
||||
|
||||
if (filter['kodeProv']) {
|
||||
where += ' AND region.kodeProv LIKE ?';
|
||||
params.push('%'+filter['kodeProv']+'%');
|
||||
}
|
||||
if (filter['kodeKab']) {
|
||||
where += ' AND region.kodeKab LIKE ?';
|
||||
params.push('%'+filter['kodeKab']+'%');
|
||||
}
|
||||
if (filter['kodeKec']) {
|
||||
where += ' AND region.kodeKec LIKE ?';
|
||||
params.push('%'+filter['kodeKec']+'%');
|
||||
}
|
||||
if (filter['kodeKel']) {
|
||||
where += ' AND region.kodeKel LIKE ?';
|
||||
params.push('%'+filter['kodeKel']+'%');
|
||||
}
|
||||
|
||||
const query = `SELECT region.*${select} FROM t_region as region ${join} WHERE region.kodeKel is not null ${where} ${limit};`;
|
||||
db.query(query, params, (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = RegionModels;
|
||||
121
models/UsersModels.js
Normal file
121
models/UsersModels.js
Normal file
@ -0,0 +1,121 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
|
||||
class UsersModels {
|
||||
|
||||
static ROLE_SU = 1; // unused
|
||||
static ROLE_SUPERADMIN = 7;
|
||||
static ROLE_ADMIN = 2;
|
||||
static ROLE_VENDOR = 8;
|
||||
static ROLE_CHECKER = 9;
|
||||
static ROLE_USER = 3; // unused
|
||||
static ROLE_CLIENT_ADMIN = 4;
|
||||
static ROLE_CLIENT_STAFF = 5; // unused
|
||||
static ROLE_CLIENT_USER = 6; // unused
|
||||
static ROLE_SPECIAL_TRACKING = 10;
|
||||
static ROLE_FINANCE = 11;
|
||||
|
||||
static STATUS_ACTIVE = 1;
|
||||
static STATUS_NOT_ACTIVE = 2;
|
||||
static STATUS_SUSPEND = 3;
|
||||
|
||||
static CHK_TYPE_PICKUP = 1;
|
||||
static CHK_TYPE_DROP = 2;
|
||||
|
||||
static DEFAULT_UID = 1; // swanusa account
|
||||
|
||||
static DEFAULT_PHONE_CODE = 62;
|
||||
|
||||
static async all() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `SELECT * FROM t_users;`;
|
||||
db.query(query, (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getUsersActiveByRole(role) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `SELECT * FROM t_users WHERE dlt is null AND status = ${UsersModels.STATUS_ACTIVE} AND role = ?;`;
|
||||
db.query(query, [role], (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async find(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `SELECT * FROM t_users WHERE id = ? LIMIT 1;`;
|
||||
db.query(query, [id], (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async findEmail(email) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `SELECT * FROM t_users WHERE email = ? LIMIT 1;`;
|
||||
db.query(query, [email], (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async create(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO t_users SET ?;`;
|
||||
db.query(query, data, (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async update(data, id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `UPDATE t_users SET ? WHERE id = ?;`;
|
||||
db.query(query, [data, id], (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async delete(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `DELETE FROM t_users WHERE id = ?;`;
|
||||
db.query(query, [id], (err, results) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = UsersModels;
|
||||
101
models/VhcModels.js
Normal file
101
models/VhcModels.js
Normal file
@ -0,0 +1,101 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
|
||||
class VhcModels {
|
||||
|
||||
static STTS_ACTIVE = 1;
|
||||
static STTS_INACTIVE = 2;
|
||||
|
||||
static IN_ORD_YES = 1;
|
||||
static IN_ORD_NO = 2;
|
||||
|
||||
static async getVhcByDeviceId(device_id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT';
|
||||
query += ' v.id as vid,v.nopol1,v.nopol2,v.nopol3,v.sum_milleage,vd.speed_limit';
|
||||
query += ' ,da.fullname as da_name,da.phone as da_phone,da.phone_code as da_phone_code';
|
||||
query += ' FROM t_vehicles AS v';
|
||||
query += ' INNER JOIN t_vehicles_detail AS vd ON v.id = vd.vid';
|
||||
query += ' LEFT JOIN t_drivers AS da ON v.a_did = da.id';
|
||||
query += ' WHERE v.dlt is null AND v.status = ? AND v.device_id = ?';
|
||||
params.push(VhcModels.STTS_ACTIVE, device_id);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getVhcById(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT';
|
||||
query += ' v.id as vid,v.nopol1,v.nopol2,v.nopol3,v.sum_milleage,vd.speed_limit';
|
||||
query += ' ,da.fullname as da_name,da.phone as da_phone,da.phone_code as da_phone_code';
|
||||
query += ' ,v.is_in_ord,v.ord_id,v.ord_code,v.ord_ids';
|
||||
query += ' FROM t_vehicles AS v';
|
||||
query += ' INNER JOIN t_vehicles_detail AS vd ON v.id = vd.vid';
|
||||
query += ' LEFT JOIN t_drivers AS da ON v.a_did = da.id';
|
||||
// query += ' WHERE v.dlt is null AND v.status = ? AND v.id = ?';
|
||||
query += ' WHERE v.dlt is null AND v.id = ?';
|
||||
query += ' LIMIT 1';
|
||||
params.push(id);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async update(id, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `UPDATE t_vehicles SET ? WHERE id = ?;`;
|
||||
db.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
conn.beginTransaction(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.query(query, [data, id], function (err, resp) {
|
||||
if (err) {
|
||||
conn.rollback(async function () {
|
||||
conn.release();
|
||||
reject(err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
conn.commit(async function (err) {
|
||||
if (err) {
|
||||
conn.release();
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
conn.release();
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = VhcModels;
|
||||
313
models/ZoneModels.js
Normal file
313
models/ZoneModels.js
Normal file
@ -0,0 +1,313 @@
|
||||
const db = require(`../config/dbMysqlConn`);
|
||||
|
||||
const defaultSelectGetInZone = `
|
||||
z.id as zid,z.name,z.desc,z.type,zt.name as type_name,z.workflow_type,zw.name as workflow_type_name
|
||||
,z.shiptocode,z.fulladdress,z.boundary_type,z.boundary_radius,z.boundary_latlngs,ST_AsText(boundary_points) as points
|
||||
,z.client_group_id,c.c_name,c_mail,c.pic_name,c.pic_mail
|
||||
`;
|
||||
|
||||
class ZoneModels {
|
||||
|
||||
static STTS_ACTIVE = 1;
|
||||
static STTS_INACTIVE = 2;
|
||||
|
||||
static ZONE_BOUNDARY_CIRCLE = 'circle';
|
||||
static ZONE_BOUNDARY_POLYGON = 'polygon';
|
||||
static ZONE_BOUNDARY_RECTANGLE = 'rectangle';
|
||||
|
||||
static async getNearest(lat, lng, meters) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT';
|
||||
query += defaultSelectGetInZone;
|
||||
query += ` ,ST_Distance_Sphere( ST_GeomFromText('POINT(${lng} ${lat})'), z.boundary_points) AS distance_meters`;
|
||||
// params.push(lng, lat);
|
||||
query += ' FROM t_zones AS z';
|
||||
query += ' INNER JOIN t_zones_types AS zt ON z.type = zt.id';
|
||||
query += ' INNER JOIN t_zones_workflows AS zw ON z.workflow_type = zw.id';
|
||||
query += ' LEFT JOIN t_clients AS c ON z.client_group_id = c.id';
|
||||
query += ' WHERE z.dlt is null AND z.status = ?';
|
||||
params.push(ZoneModels.STTS_ACTIVE);
|
||||
query += ' HAVING distance_meters <= ?';
|
||||
params.push(meters);
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getInCircle(lat, lng, filter = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT';
|
||||
query += defaultSelectGetInZone;
|
||||
query += ` ,ST_Distance_Sphere( ST_GeomFromText('POINT(${lng} ${lat})'), z.boundary_points) AS distance_meters`;
|
||||
// params.push(lng, lat);
|
||||
query += ' FROM t_zones AS z';
|
||||
query += ' INNER JOIN t_zones_types AS zt ON z.type = zt.id';
|
||||
query += ' INNER JOIN t_zones_workflows AS zw ON z.workflow_type = zw.id';
|
||||
query += ' LEFT JOIN t_clients AS c ON z.client_group_id = c.id';
|
||||
query += ' WHERE z.dlt is null AND z.status = ? AND z.boundary_type = ?';
|
||||
params.push(ZoneModels.STTS_ACTIVE, ZoneModels.ZONE_BOUNDARY_CIRCLE);
|
||||
if (filter['zid']) {
|
||||
query += ' AND z.id = ?';
|
||||
params.push(filter['zid']);
|
||||
}
|
||||
query += ' HAVING boundary_radius >= distance_meters';
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getInShape(lat, lng, filter = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT';
|
||||
query += defaultSelectGetInZone;
|
||||
query += ` ,ST_Distance_Sphere( ST_GeomFromText('POINT(${lng} ${lat})'), z.boundary_points) AS distance_meters`;
|
||||
query += ` ,MBRContains( boundary_points, ST_GeomFromText('POINT(${lng} ${lat})') ) as is_contain`;
|
||||
query += ` ,MBRWithin( ST_GeomFromText('POINT(${lng} ${lat})'), boundary_points ) as is_within`;
|
||||
// params.push(lng, lat);
|
||||
query += ' FROM t_zones AS z';
|
||||
query += ' INNER JOIN t_zones_types AS zt ON z.type = zt.id';
|
||||
query += ' INNER JOIN t_zones_workflows AS zw ON z.workflow_type = zw.id';
|
||||
query += ' LEFT JOIN t_clients AS c ON z.client_group_id = c.id';
|
||||
query += ' WHERE z.dlt is null AND z.status = ? AND z.boundary_type IN (?,?)';
|
||||
params.push(ZoneModels.STTS_ACTIVE, ZoneModels.ZONE_BOUNDARY_POLYGON, ZoneModels.ZONE_BOUNDARY_RECTANGLE);
|
||||
if (filter['zid']) {
|
||||
query += ' AND z.id = ?';
|
||||
params.push(filter['zid']);
|
||||
}
|
||||
query += ' HAVING is_within = 1';
|
||||
query += ' AND is_contain = 1';
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getOrdInCircle(lat, lng, filter = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT';
|
||||
query += defaultSelectGetInZone;
|
||||
query += ` ,ST_Distance_Sphere( ST_GeomFromText('POINT(${lng} ${lat})'), z.boundary_points) AS distance_meters`;
|
||||
// params.push(lng, lat);
|
||||
query += ' FROM t_zones AS z';
|
||||
query += ' INNER JOIN t_zones_types AS zt ON z.type = zt.id';
|
||||
query += ' INNER JOIN t_zones_workflows AS zw ON z.workflow_type = zw.id';
|
||||
query += ' LEFT JOIN t_clients AS c ON z.client_group_id = c.id';
|
||||
query += ' WHERE z.boundary_type = ?';
|
||||
params.push(ZoneModels.ZONE_BOUNDARY_CIRCLE);
|
||||
if (filter['zid']) {
|
||||
query += ' AND z.id = ?';
|
||||
params.push(filter['zid']);
|
||||
}
|
||||
query += ' HAVING boundary_radius >= distance_meters';
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getOrdInShape(lat, lng, filter = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let query = 'SELECT';
|
||||
query += defaultSelectGetInZone;
|
||||
query += ` ,ST_Distance_Sphere( ST_GeomFromText('POINT(${lng} ${lat})'), z.boundary_points) AS distance_meters`;
|
||||
query += ` ,MBRContains( boundary_points, ST_GeomFromText('POINT(${lng} ${lat})') ) as is_contain`;
|
||||
query += ` ,MBRWithin( ST_GeomFromText('POINT(${lng} ${lat})'), boundary_points ) as is_within`;
|
||||
// params.push(lng, lat);
|
||||
query += ' FROM t_zones AS z';
|
||||
query += ' INNER JOIN t_zones_types AS zt ON z.type = zt.id';
|
||||
query += ' INNER JOIN t_zones_workflows AS zw ON z.workflow_type = zw.id';
|
||||
query += ' LEFT JOIN t_clients AS c ON z.client_group_id = c.id';
|
||||
query += ' WHERe z.boundary_type IN (?,?)';
|
||||
params.push(ZoneModels.ZONE_BOUNDARY_POLYGON, ZoneModels.ZONE_BOUNDARY_RECTANGLE);
|
||||
if (filter['zid']) {
|
||||
query += ' AND z.id = ?';
|
||||
params.push(filter['zid']);
|
||||
}
|
||||
query += ' HAVING is_within = 1';
|
||||
query += ' AND is_contain = 1';
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async testZoning() {
|
||||
return new Promise((resolve, reject) => {
|
||||
`
|
||||
-- in mysql using x,y => longitude,latitude
|
||||
|
||||
-- ST_GeomFromText(col) => convert text to blob, ST_AsText(col) convert blob to text
|
||||
SELECT id,name,boundary_type,boundary_radius,ST_AsText(boundary_points) FROM db_trucking.t_zones;
|
||||
|
||||
-- nearest zone from this latLng for circle. if radius less than meters, it mean this loc in this zone
|
||||
SELECT id,name,boundary_type,boundary_radius as radius,ST_AsText(boundary_points) AS zonasi
|
||||
,ST_Distance_Sphere( ST_GeomFromText('POINT(106.834916 -6.161736)'), boundary_points) AS meters
|
||||
FROM db_trucking.t_zones WHERE boundary_type='circle'
|
||||
HAVING radius >= meters;
|
||||
|
||||
-- id:3 => -6.57538126,106.63426234
|
||||
-- id:5 => -6.244811,106.865669
|
||||
-- nearest zone from this latLng for polygon,rectangle
|
||||
SELECT id,name,boundary_type
|
||||
,MBRContains( boundary_points, ST_GeomFromText('POINT(106.865669 -6.244811)') ) as contain
|
||||
,MBRWithin( ST_GeomFromText('POINT(106.865669 -6.244811)'), boundary_points ) as within
|
||||
,ST_AsText(boundary_points) as zonasi
|
||||
,ST_Distance_Sphere( ST_GeomFromText('POINT(106.865669 -6.244811)'), boundary_points) AS meters
|
||||
FROM db_trucking.t_zones WHERE boundary_type IN ('polygon','rectangle')
|
||||
HAVING within >= 1;
|
||||
`
|
||||
let params = [];
|
||||
let query = 'SELECT * FROM t_zones';
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getCheckpointsInCircle(lat, lng, filter = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let where = '';
|
||||
let query = 'SELECT';
|
||||
query += defaultSelectGetInZone;
|
||||
query += `
|
||||
,ord.id as ord_id,ord.code as ord_code,ord_pck_drop.id as ord_pck_drop_id
|
||||
,ord.status as stts_order,ord_pck_drop.stts as stts_delivery
|
||||
,ord.crt as ord_crt,ord_pck_drop.crt as ord_pck_drop_crt
|
||||
,checkpoint.id as checkpoint_id,checkpoint.pocket_sort,checkpoint.pocket_is_paid,checkpoint.pocket_total
|
||||
,ord_drv.drv_id,ord_drv.drv_name,ord_drv.drv_bank_id,ord_drv.drv_bank_code,ord_drv.drv_bank_name,ord_drv.drv_bank_short_name,ord_drv.drv_bank_acc_number,ord_drv.drv_bank_acc_name
|
||||
`;
|
||||
query += ` ,ST_Distance_Sphere( ST_GeomFromText('POINT(${lng} ${lat})'), z.boundary_points) AS distance_meters`;
|
||||
// params.push(lng, lat);
|
||||
query += ' FROM t_zones AS z';
|
||||
query += ' INNER JOIN t_zones_types AS zt ON z.type = zt.id';
|
||||
query += ' INNER JOIN t_zones_workflows AS zw ON z.workflow_type = zw.id';
|
||||
query += ' LEFT JOIN t_clients AS c ON z.client_group_id = c.id';
|
||||
query += ' INNER JOIN t_orders_checkpoints AS checkpoint ON z.id = checkpoint.pck_id';
|
||||
query += ' INNER JOIN t_orders AS ord ON checkpoint.ord_id = ord.id';
|
||||
query += ' INNER JOIN t_orders_pck_drop AS ord_pck_drop ON checkpoint.ord_id = ord_pck_drop.ord_id';
|
||||
query += ' INNER JOIN t_orders_drivers AS ord_drv ON checkpoint.ord_id = ord_drv.ord_id';
|
||||
query += ' WHERE ord.dlt is null AND checkpoint.dlt is null AND z.boundary_type = ?';
|
||||
params.push(ZoneModels.ZONE_BOUNDARY_CIRCLE);
|
||||
if (typeof filter['pocket_is_paid'] !== 'undefined') query += ' AND checkpoint.pocket_is_paid = ' + filter['pocket_is_paid'];
|
||||
if (typeof filter['where_not_pocket_is_paid'] !== 'undefined') query += ' AND checkpoint.pocket_is_paid != ' + filter['where_not_pocket_is_paid'];
|
||||
if (typeof filter['pocket_sort'] !== 'undefined') query += ' AND checkpoint.pocket_sort != 1';
|
||||
if (typeof filter['drv_id'] !== 'undefined') query += ' AND ord_drv.drv_id = ' + filter['drv_id'];
|
||||
|
||||
if (filter['stts_delivery'] && filter['stts_delivery'].length > 0) {
|
||||
where += ' AND ord_pck_drop.stts IN (';
|
||||
for (const stts_delivery of filter['stts_delivery']) {
|
||||
where += '?,';
|
||||
params.push(stts_delivery);
|
||||
}
|
||||
where = where.slice(0, -1) + ')';
|
||||
}
|
||||
|
||||
query += where;
|
||||
query += ' HAVING boundary_radius >= distance_meters';
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async getCheckpointsInShape(lat, lng, filter = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params = [];
|
||||
let where = '';
|
||||
let query = 'SELECT';
|
||||
query += defaultSelectGetInZone;
|
||||
query += `
|
||||
,ord.id as ord_id,ord.code as ord_code,ord_pck_drop.id as ord_pck_drop_id
|
||||
,ord.status as stts_order,ord_pck_drop.stts as stts_delivery
|
||||
,ord.crt as ord_crt,ord_pck_drop.crt as ord_pck_drop_crt
|
||||
,checkpoint.id as checkpoint_id,checkpoint.pocket_sort,checkpoint.pocket_is_paid,checkpoint.pocket_total
|
||||
,ord_drv.drv_id,ord_drv.drv_name,ord_drv.drv_bank_id,ord_drv.drv_bank_code,ord_drv.drv_bank_name,ord_drv.drv_bank_short_name,ord_drv.drv_bank_branch_name,ord_drv.drv_bank_acc_number,ord_drv.drv_bank_acc_name
|
||||
`;
|
||||
query += ` ,ST_Distance_Sphere( ST_GeomFromText('POINT(${lng} ${lat})'), z.boundary_points) AS distance_meters`;
|
||||
query += ` ,MBRContains( boundary_points, ST_GeomFromText('POINT(${lng} ${lat})') ) as is_contain`;
|
||||
query += ` ,MBRWithin( ST_GeomFromText('POINT(${lng} ${lat})'), boundary_points ) as is_within`;
|
||||
// params.push(lng, lat);
|
||||
query += ' FROM t_zones AS z';
|
||||
query += ' INNER JOIN t_zones_types AS zt ON z.type = zt.id';
|
||||
query += ' INNER JOIN t_zones_workflows AS zw ON z.workflow_type = zw.id';
|
||||
query += ' LEFT JOIN t_clients AS c ON z.client_group_id = c.id';
|
||||
query += ' INNER JOIN t_orders_checkpoints AS checkpoint ON z.id = checkpoint.pck_id';
|
||||
query += ' INNER JOIN t_orders AS ord ON checkpoint.ord_id = ord.id';
|
||||
query += ' INNER JOIN t_orders_pck_drop AS ord_pck_drop ON checkpoint.ord_id = ord_pck_drop.ord_id';
|
||||
query += ' INNER JOIN t_orders_drivers AS ord_drv ON checkpoint.ord_id = ord_drv.ord_id';
|
||||
query += ' WHERE ord.dlt is null AND checkpoint.dlt is null AND z.boundary_type IN (?,?)';
|
||||
params.push(ZoneModels.ZONE_BOUNDARY_POLYGON, ZoneModels.ZONE_BOUNDARY_RECTANGLE);
|
||||
if (typeof filter['pocket_is_paid'] !== 'undefined') query += ' AND checkpoint.pocket_is_paid = ' + filter['pocket_is_paid'];
|
||||
if (typeof filter['where_not_pocket_is_paid'] !== 'undefined') query += ' AND checkpoint.pocket_is_paid != ' + filter['where_not_pocket_is_paid'];
|
||||
if (typeof filter['pocket_sort'] !== 'undefined') query += ' AND checkpoint.pocket_sort != 1';
|
||||
if (typeof filter['drv_id'] !== 'undefined') query += ' AND ord_drv.drv_id = ' + filter['drv_id'];
|
||||
|
||||
if (filter['stts_delivery'] && filter['stts_delivery'].length > 0) {
|
||||
where += ' AND ord_pck_drop.stts IN (';
|
||||
for (const stts_delivery of filter['stts_delivery']) {
|
||||
where += '?,';
|
||||
params.push(stts_delivery);
|
||||
}
|
||||
where = where.slice(0, -1) + ')';
|
||||
}
|
||||
|
||||
query += where;
|
||||
query += ' HAVING is_within = 1';
|
||||
query += ' AND is_contain = 1';
|
||||
db.query(query, params, function (err, resp) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return false;
|
||||
}
|
||||
resolve(resp);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = ZoneModels;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user