2021-12-21 01:27:45 +01:00
|
|
|
const shared_consts = require('../tools/shared_nodejs');
|
|
|
|
|
|
|
|
|
|
const tools = require('../tools/general');
|
|
|
|
|
|
|
|
|
|
const countryCodes = require('country-codes-list');
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
|
2022-01-20 00:39:06 +01:00
|
|
|
async executeQueryPickup(idapp, params) {
|
2021-12-21 01:27:45 +01:00
|
|
|
|
|
|
|
|
const table = params.table;
|
|
|
|
|
const strfind = params.search;
|
|
|
|
|
|
|
|
|
|
if (strfind === '') {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let myCountryArr = [];
|
|
|
|
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
|
|
|
|
if (table === shared_consts.TAB_COUNTRY) {
|
|
|
|
|
// '[{countryCode}] {countryNameLocal}: +{countryCallingCode}'
|
|
|
|
|
out = {
|
|
|
|
|
id: '{countryCode}',
|
|
|
|
|
value: '{countryNameLocal}',
|
|
|
|
|
flag: '{flag}',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} else if (table === shared_consts.TAB_PHONES) {
|
|
|
|
|
out = {
|
|
|
|
|
id: '{countryCode}',
|
|
|
|
|
value: '{countryNameLocal} +{countryCallingCode}',
|
|
|
|
|
code: '+{countryCallingCode}',
|
|
|
|
|
flag: '{flag}',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// const myCountryArr = countryCodes.filter('countryNameLocal', strfind);
|
|
|
|
|
// const myCountryArr = countryCodes.customList.filter()
|
|
|
|
|
|
|
|
|
|
// myCountryArr = countryCodes.customList('countryCode', lavueout, { filter: ((countryData) => { return countryData['countryNameLocal'].toLocaleLowerCase().indexOf(strfind) >= 0 })} );
|
|
|
|
|
myCountryArr = countryCodes.customArray(out, {
|
|
|
|
|
filter: ((countryData) => {
|
|
|
|
|
return countryData['countryNameLocal'].toLocaleLowerCase().
|
|
|
|
|
startsWith(strfind) || countryData['countryNameEn'].toLocaleLowerCase().
|
|
|
|
|
startsWith(strfind);
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log('err', e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return myCountryArr;
|
|
|
|
|
},
|
|
|
|
|
};
|