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