From 384404dbc7caf665b7079407579ee6150d91d69f Mon Sep 17 00:00:00 2001 From: Hou Samnang Date: Tue, 30 Mar 2021 17:04:31 +0700 Subject: [PATCH] Add Service to server --- .env | 6 +++++ data.json | 1 + data/config.json | 8 +++++++ ...oduct and Catagory list.xlsx => data.xlsx} | Bin 13537 -> 13561 bytes exported.json | 1 + package.json | 6 ++++- src/index.js | 22 ++++++++++++++++++ src/test.js | 11 +++++++++ 8 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .env create mode 100644 data.json create mode 100644 data/config.json rename data/{Sanagro Product and Catagory list.xlsx => data.xlsx} (77%) create mode 100644 exported.json create mode 100644 src/test.js diff --git a/.env b/.env new file mode 100644 index 0000000..0a152da --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +APP_NAME=custom app name +INPUT_FILE=./data/mydata.xlsx +OUTPUT_PATH=./data/outputs +MAPPER_FILE=./data/mapper.json +SHEET_NAME=Sheet1 +ENCODING=utf-8 \ No newline at end of file diff --git a/data.json b/data.json new file mode 100644 index 0000000..ff8bf73 --- /dev/null +++ b/data.json @@ -0,0 +1 @@ +[{"productName":"សំណាង"},{"productName":"EGG01"},{"productName":"EGG02"},{"productName":"ភាស"},{"productName":"ភាស"},{"productName":"EGG01"}] \ No newline at end of file diff --git a/data/config.json b/data/config.json new file mode 100644 index 0000000..299a03c --- /dev/null +++ b/data/config.json @@ -0,0 +1,8 @@ +{ + "data": [ + { + "dataIndex": "Product name", + "label": "productName" + } + ] +} diff --git a/data/Sanagro Product and Catagory list.xlsx b/data/data.xlsx similarity index 77% rename from data/Sanagro Product and Catagory list.xlsx rename to data/data.xlsx index b47d39d7af70a987bfda7b1a288fa6f9abdd43e7..3d8837ad3b4a6c85cb1e75722585d86ffb363f73 100644 GIT binary patch delta 1687 zcmV;I259-=Y58fe6%q>mCFT050ssI^2$LTYAAeR&bDJ;_y?3VnfzdsDIF4x;AQQ*Q zG>6V)+O&6BEJkBMR8s8Z-*<%qu>oh?o8*0d``)g0?f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7?&dK8P8KkZ{U`8Htc^)G0!S7H23zh9YDrLWUw_5{i&e zfB1}sB4qH3QG^UdD4_@?6rqGRF`)=06rqIHnbIdo(WJ$vQ}{}=k+cY>?Vn{laD<~i z9nq((&qnka>C+IhD3H$X436nUZ|1wZyD%IMi5^A-Cj{dmT(-^XP<38i?(Fc|!@U|_ zH)UtnP5UxbKQ`)ZWwjZyqFfJ9-(6R3e_vM8X;Mzkw$Ikj#q-qj*28=ATWeS9_f$^3 zb)>h7p6gr)#-VfOsOyauS8udHJ#>1gA|X%@ogSj8hfc5Rp(9ieogUIt_0SPhpW7mX z-V&&XjzB$h1nQw9P!F9R!a5^;bczg)PLV;w3DgZIkk$zeCnhb48?MN(;RKI_e+?T> zbP5|ZoR}0gXgDz`Y|wDMNnxXg6PLmU4JRgr4H~YGJ-5IFnDu*VF5d)A8r& z`1^GHt}p*OUw9o}crLqtD3E`C1M)urlfecQlRGpJv&bl#1_jRl=HE-RXD=oJf6Y$A zFc5_ANW4Sjdt%2erC3QS@zWEP5Dfxxv+Qje5j&A>X#4g!NgGmu#L+vm-_EX_EcU7j zzQEYB)+vf3f&$Q@mZdII^pY>bISQ=fTJoyakfH-vw8$fq?q9am@0oi<- zssl)Yp#lZkSsX_({_#36%Kq8VDI=#U-J$V29pjGKQuN~B-rI68?smIqH|b*d{4su8 zJ+8Y|!&0}m5`eNq3MLG2SDWl*{qUUNQK3Cv#jRWUJ8w#mw}))amFBugMeuLQqq^ih z4`kr8us-=od7a$d=S!4PLgSFokWOaPz zumS)8I}HE;6aWAK0000000000006O*6f{8rlap37Istu?ku)P4&j04$O921?Tmk?9 d5dZ)H0000000000002Fc&om?kzcBy+0080^3V;9r diff --git a/exported.json b/exported.json new file mode 100644 index 0000000..3bbe922 --- /dev/null +++ b/exported.json @@ -0,0 +1 @@ +[{"productName":"EGG00"},{"productName":"EGG01"},{"productName":"EGG02"},{"productName":"EGG03"},{"productName":"S700-30K"},{"productName":"S700-5K"},{"productName":"S701-30K"},{"productName":"S701-5K"},{"productName":"S703M"},{"productName":"S703P"},{"productName":"S704M"},{"productName":"S704P"},{"productName":"S705M"},{"productName":"S705P"},{"productName":"S705XM"},{"productName":"S705XP"},{"productName":"S706M"},{"productName":"S706P"},{"productName":"S707M"},{"productName":"S707P"},{"productName":"S710C"},{"productName":"S711C"},{"productName":"S712P"},{"productName":"S715C"},{"productName":"S716C"},{"productName":"S716P"},{"productName":"S719C"},{"productName":"S720C"},{"productName":"S730P"},{"productName":"S731P"},{"productName":"S732P"},{"productName":"S733P"},{"productName":"S736P"},{"productName":"S740-30K"},{"productName":"S740-5K"},{"productName":"S741-30K"},{"productName":"S741-5K"},{"productName":"S743M"},{"productName":"S743P"},{"productName":"S744M"},{"productName":"S744P"},{"productName":"S745M"},{"productName":"S745P"},{"productName":"S745XM"},{"productName":"S745XP"},{"productName":"S746M"},{"productName":"S746P"},{"productName":"S747M"},{"productName":"S747P"},{"productName":"S750C"},{"productName":"S751C"},{"productName":"S752P"},{"productName":"S755C"},{"productName":"S756C"},{"productName":"S756P"},{"productName":"S765P"},{"productName":"S766P"},{"productName":"S767P"},{"productName":"S768P"},{"productName":"S790-30K"},{"productName":"S790-5K"},{"productName":"S797-30K"},{"productName":"S797-5K"},{"productName":"S798-30K"},{"productName":"S798-5K"},{"productName":"S799-30K"},{"productName":"S799-5K"},{"productName":"S803M"},{"productName":"S803P"},{"productName":"Bag"},{"productName":"B700-30K"},{"productName":"B700-5K"},{"productName":"B701-30K"},{"productName":"B701-5K"},{"productName":"B703M"},{"productName":"B703P"},{"productName":"B704M"},{"productName":"B704P"},{"productName":"B705M"},{"productName":"B705P"},{"productName":"B705XM"},{"productName":"B705XP"},{"productName":"B706M"},{"productName":"B706P"},{"productName":"B707M"},{"productName":"B707P"},{"productName":"B710C"},{"productName":"B711C"},{"productName":"B712P"},{"productName":"B715C"},{"productName":"B716C"},{"productName":"B716P"},{"productName":"B719C"},{"productName":"B720C"},{"productName":"B730P"},{"productName":"B731P"},{"productName":"B732P"},{"productName":"B733P"},{"productName":"B736P"},{"productName":"B740-30K"},{"productName":"B740-5K"},{"productName":"B741-30K"},{"productName":"B741-5K"},{"productName":"B743M"},{"productName":"B743P"},{"productName":"B744M"},{"productName":"B744P"},{"productName":"B745M"},{"productName":"B745P"},{"productName":"B745XM"},{"productName":"B745XP"},{"productName":"B746M"},{"productName":"B746P"},{"productName":"B747M"},{"productName":"B747P"},{"productName":"B750C"},{"productName":"B751C"},{"productName":"B752P"},{"productName":"B755C"},{"productName":"B756C"},{"productName":"B756P"},{"productName":"B765P"},{"productName":"B766P"},{"productName":"B767P"},{"productName":"B768P"},{"productName":"B790-30K"},{"productName":"B790-5K"},{"productName":"B797-30K"},{"productName":"B797-5K"},{"productName":"B798-30K"},{"productName":"B798-5K"},{"productName":"B799-30K"},{"productName":"B799-5K"},{"productName":"B803M"},{"productName":"B803P"},{"productName":"POO"}] \ No newline at end of file diff --git a/package.json b/package.json index d0a9b6f..c5b25d9 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "test": "jest", - "start": "nodemon src/index.js" + "start": "nodemon src/index.js", + "export": "nodemon src/test.js" }, "repository": { "type": "git", @@ -25,9 +26,12 @@ }, "homepage": "https://github.com/CUBETIQ/data-migration-nodejs#readme", "dependencies": { + "axios": "^0.21.1", + "excel2json-xlsx": "^1.0.5", "express": "^4.17.1", "jest": "^26.6.3", "multer": "^1.4.2", + "node-fetch": "^2.6.1", "nodemon": "^2.0.7", "read-excel-file": "^5.0.0", "xlsx": "^0.16.9" diff --git a/src/index.js b/src/index.js index bad0cbf..737eb00 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,5 @@ const express = require('express') +const axios = require("axios") // const file = require('fs') // file.readFile('./data/people.csv', 'utf-8', (err, data) => { @@ -31,6 +32,7 @@ app.listen(port, () => { }) var multer = require('multer'); +const { default: fetch } = require('node-fetch'); var upload = multer(); var XLSX = require('xlsx') app.use(upload.none()); @@ -41,6 +43,26 @@ app.post('/upload', async function (req, res) { let xlData = XLSX.utils.sheet_to_json(wb.Sheets['Sheet2']); let data = xlData.map((row) => ({ productName: row['Product name'], smallTypeName: row.smallTypeName, productCategory: { productCategoryId: row['CategoryID'] }, alert: row.alert, cost: row.cost, qtyStock: row.qtystock, sellPrice: row.sellPrice })) res.send(data) + + + axios({ + url: 'http://localhost:4000/graphql', + method: 'post', + headers: { + "authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTYxNzA3OTYyOCwiZXhwIjoxNjE3MzM4ODI4fQ.p5oAaT3htRbBgKimfr7hxfjNwjWPc5X1finX2zBZ9aM" + }, + data: { + query: ` + mutation{ + createManyProducts(file: "${JSON.stringify(data)}") + } + ` + } + }).then((result) => { + console.log(result.data) + }); }) + + diff --git a/src/test.js b/src/test.js new file mode 100644 index 0000000..a308c38 --- /dev/null +++ b/src/test.js @@ -0,0 +1,11 @@ +const excel2json = require("excel2json-xlsx") +const data = excel2json( + { + inputFile: "data/data.xlsx", + mapperFile: "data/config.json", + outputFile: "data.json", + sheetName: "Sheet2", + } +) + +console.log(data) \ No newline at end of file