Skip to content

Instantly share code, notes, and snippets.

@rostikowb
Created February 4, 2020 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rostikowb/566b7a525676fa254c4fab71c5bb84f6 to your computer and use it in GitHub Desktop.
Save rostikowb/566b7a525676fa254c4fab71c5bb84f6 to your computer and use it in GitHub Desktop.
const rl = readline.createInterface({
input: req,
// output: process.stdout
});
//
rl.on('line', (input) => {
req.pause();
addToDB(input).then(()=>{
req.resume();
});
});
req.on('end', function () {
rl.close();
res.status(200).json({result: true})
});
req.on('error', function (err) {
console.log('stream', err);
});
export default async (data) => {
let arrItem;
let result;
arrItem = data.replace(/"/g, '').split(';');
if (arrItem.length === 19) {
const _id = new Types.ObjectId();
const infoObj = {
person: arrItem[0],
oper_code: arrItem[2],
oper_name: arrItem[3],
d_reg: arrItem[4],
dep_code: arrItem[5],
dep: arrItem[6],
brand: arrItem[7],
model: arrItem[8],
make_year: arrItem[9],
color: arrItem[10],
kind: arrItem[11],
body: arrItem[12],
purpose: arrItem[13],
n_reg_new: arrItem[18]
};
arrItem[1] !== 'NULL' ? infoObj.reg_addr_koatuu = arrItem[1] : null;
arrItem[14] !== 'NULL' ? infoObj.fuel = arrItem[14] : null;
arrItem[15] !== 'NULL' ? infoObj.capacity = arrItem[15] : null;
arrItem[16] !== 'NULL' ? infoObj.own_weight = arrItem[16] : null;
arrItem[17] !== 'NULL' ? infoObj.total_weight = arrItem[17] : null;
try {
result = await Info.countDocuments(infoObj);
if (!result) {
infoObj['_id'] = _id;
await new Info(infoObj).save();
}
} catch (e) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment