Initial commit
This commit is contained in:
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;
|
||||
Reference in New Issue
Block a user