91 lines
2.6 KiB
JavaScript
Executable File
91 lines
2.6 KiB
JavaScript
Executable File
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; |