added change in user_id posting to server

This commit is contained in:
Mohamed Nouffer
2022-11-15 19:01:42 +05:30
parent 6199e4f558
commit 4cb27b3b25
5 changed files with 78 additions and 2 deletions

View File

@ -35,6 +35,7 @@
"classnames": "^2.2.6",
"core-js": "^3.9.1",
"cors": "^2.8.5",
"csv": "^6.2.2",
"enzyme": "^3.11.0",
"js-cookie": "^3.0.0",
"js-file-download": "^0.4.12",

View File

@ -4,6 +4,8 @@ var multer = require('multer')
var cors = require('cors');
var bodyParser = require("body-parser");
var https = require('https')
var csv = require('csv');
const { parse } = require("csv-parse");
const util = require('util');
const fs = require('fs');
@ -121,7 +123,9 @@ app.post('/upload', function(req, res, next) {
const converter = require('json-2-csv');
app.post('/csv', (req, res, next) => {
let _res = "";
const csv = req;
userData = req.body;
@ -129,12 +133,44 @@ app.post('/csv', (req, res, next) => {
if (err) {
throw err;
}
let _userData = JSON.parse(userData);
_userEmail = _userData.mailadress;
//check for record alredy exist
try {
const path = '/var/www/html/appexe/natnats/23/bin/mobileweb2/resources/database/user_record.csv';
if (fs.existsSync(path)) {
fs.createReadStream(path)
.pipe(parse({ delimiter: ",", from_line: 1 }))
.on("data", function (row) {
for(r in row){
if(r[0] === _userEmail){
_res = r[2];
break;
}
}
if(_res === ""){
fs.appendFile(path, csv, function (err) {
if (err) throw err;
console.log('The "data to append" was appended to file!');
});
_res = 'OK';
res.send(_res);
}
});
}
} catch(err) {
console.error(err)
}
writetoFile(csv);
// print CSV string
console.log(csv);
});
res.send("OK");
res.send(_res);
});
function writetoFile(csv) {
@ -147,7 +183,6 @@ function writetoFile(csv) {
}
app.listen(8000, function() {
console.log('App running on port 8000');
});

View File

@ -53,6 +53,13 @@ const TheContent = () => {
.catch((err) => {
console.log("AXIOS ERROR: ", err);
});
if(result === "OK"){
}else{
setUserData(result);
}
console.log("user data posted");
}

3
test.csv Normal file
View File

@ -0,0 +1,3 @@
a@a.a,bbbb,ccc,dddd
e@e.e,ffff,ggg,hhhh
i@i.i,jjjj,kkk,llll
1 a@a.a bbbb ccc dddd
2 e@e.e ffff ggg hhhh
3 i@i.i jjjj kkk llll

View File

@ -4185,6 +4185,31 @@
"resolved" "https://registry.npmjs.org/csstype/-/csstype-3.0.8.tgz"
"version" "3.0.8"
"csv-generate@^4.2.1":
"integrity" "sha512-w6GFHjvApv6bcJ2xdi9JGsH6ZvUBfC+vUdfefnEzurXG6hMRwzkBLnhztU2H7v7+zfCk1I/knnQ+tGbgpxWrBw=="
"resolved" "https://registry.npmjs.org/csv-generate/-/csv-generate-4.2.1.tgz"
"version" "4.2.1"
"csv-parse@^5.3.2":
"integrity" "sha512-3jQ/JMs+voKxr4vwpmElS1d37J0o6rQdQyEKoPyA9HG8fYczpLaBJnmp5ykvkXL8ZeEGVP0qwLU645BZVykXKw=="
"resolved" "https://registry.npmjs.org/csv-parse/-/csv-parse-5.3.2.tgz"
"version" "5.3.2"
"csv-stringify@^6.2.1":
"integrity" "sha512-+DT/YEgqRy82aMPMA7yUUpFJPx9X8iZy7UhfyTE2bHmFJcjDiz1j29wzTFkYTtuNVceNgz8efsjICch+O1WcLQ=="
"resolved" "https://registry.npmjs.org/csv-stringify/-/csv-stringify-6.2.1.tgz"
"version" "6.2.1"
"csv@^6.2.2":
"integrity" "sha512-flTUz/J1VZ6n5+PJmxO7EImbt+tmk2aVgYxeo5UkC/f/beo9OQ7uFMVm53xOsS+/8+5gFN+MQwCdYtYzRXhrRg=="
"resolved" "https://registry.npmjs.org/csv/-/csv-6.2.2.tgz"
"version" "6.2.2"
dependencies:
"csv-generate" "^4.2.1"
"csv-parse" "^5.3.2"
"csv-stringify" "^6.2.1"
"stream-transform" "^3.2.1"
"cyclist@^1.0.1":
"integrity" "sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk="
"resolved" "https://registry.npmjs.org/cyclist/-/cyclist-1.0.1.tgz"
@ -11249,6 +11274,11 @@
"resolved" "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.1.tgz"
"version" "1.0.1"
"stream-transform@^3.2.1":
"integrity" "sha512-ApK+WTJ5bCOf0A2tlec1qhvr8bGEBM/sgXXB7mysdCYgZJO5DZeaV3h3G+g0HnAQ372P5IhiGqnW29zoLOfTzQ=="
"resolved" "https://registry.npmjs.org/stream-transform/-/stream-transform-3.2.1.tgz"
"version" "3.2.1"
"streamsearch@0.1.2":
"integrity" "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
"resolved" "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz"