From e5f439bffda43ff935837ed394ee17affe7cdca4 Mon Sep 17 00:00:00 2001 From: Hou Samnang Date: Wed, 31 Mar 2021 10:11:48 +0700 Subject: [PATCH] Fix add property mapping --- src/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 737eb00..dd37ff9 100644 --- a/src/index.js +++ b/src/index.js @@ -41,10 +41,13 @@ app.post('/upload', async function (req, res) { let wb = XLSX.read(input, { type: 'binary' }); 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 })) + let data = xlData.map((row) => ({ productName: row['Product name'], smallTypeName: row.SmallTypeName, productCategory: { productCategoryId: row['CategoryID'], newCategory: row['Category'] }, alert: row.alert, cost: row.cost, qtyStock: row.qtystock, sellPrice: row.sellPrice })) res.send(data) + var fileData = JSON.stringify(data) + console.log(fileData) + axios({ url: 'http://localhost:4000/graphql', method: 'post', @@ -54,9 +57,9 @@ app.post('/upload', async function (req, res) { data: { query: ` mutation{ - createManyProducts(file: "${JSON.stringify(data)}") + createManyProducts(file: ${JSON.stringify(fileData)}) } - ` + `, } }).then((result) => { console.log(result.data)