tracksolidCamera
This commit is contained in:
@ -10,6 +10,7 @@ const { nanoid } = require("nanoid")
|
||||
const VhcModels = require("../models/VhcModels")
|
||||
const ZoneModels = require("../models/ZoneModels")
|
||||
const LibHelper = require("../library/LibHelper")
|
||||
const db = require("../config/dbConnCron")
|
||||
|
||||
Validator.useLang("en")
|
||||
|
||||
@ -550,6 +551,48 @@ class ListenController {
|
||||
return res.status(500).json(apiRes)
|
||||
}
|
||||
}
|
||||
|
||||
async tracksolidCamera(req, res) {
|
||||
/*{
|
||||
"imei": "866888046130754",
|
||||
"picture_at": 1678888888,
|
||||
"file": "http://example.com/image.jpg",
|
||||
}*/
|
||||
let apiRes = {}
|
||||
try {
|
||||
const data = req.body
|
||||
const now = moment().unix()
|
||||
|
||||
const vhc_id = (await VhcModels.getVhcByDeviceId(data.imei))?.[0]?.vid
|
||||
console.log("vhc_id", vhc_id)
|
||||
|
||||
if (!vhc_id) {
|
||||
apiRes = JSON.parse(JSON.stringify(response[400]))
|
||||
apiRes.meta.message = "Device ID not registered to any vehicle"
|
||||
return res.status(400).json(apiRes)
|
||||
}
|
||||
|
||||
const insQ = `
|
||||
insert into t_camera
|
||||
set
|
||||
vhc_id = ?,
|
||||
crt_d = ?,
|
||||
image = ?,
|
||||
crt_s = ?
|
||||
`
|
||||
const insD = [vhc_id, data.picture_at, data.file, now]
|
||||
const insR = await db.query(insQ, insD)
|
||||
|
||||
apiRes = JSON.parse(JSON.stringify(response[200]))
|
||||
apiRes.meta.message = "success"
|
||||
return res.status(200).json(apiRes)
|
||||
} catch (err) {
|
||||
console.error("❌ error:", err.message)
|
||||
apiRes = JSON.parse(JSON.stringify(response[500]))
|
||||
apiRes.meta.message += Helper.setErrMsg(": " + err.message)
|
||||
return res.status(500).json(apiRes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const object = new ListenController()
|
||||
|
||||
@ -5,4 +5,5 @@ exports.use = function (app) {
|
||||
// LISTEN
|
||||
app.post(PATH_URL + "/listen/gps", ListenController.gps)
|
||||
app.post(PATH_URL + "/listen/teltonika", ListenController.teltonika)
|
||||
app.post(PATH_URL + "/listen/tracksolid/camera", ListenController.tracksolidCamera)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user