Fix add property mapping

This commit is contained in:
Hou Samnang 2021-03-31 10:11:48 +07:00
parent 384404dbc7
commit e5f439bffd

View File

@ -41,10 +41,13 @@ app.post('/upload', async function (req, res) {
let wb = XLSX.read(input, { type: 'binary' }); let wb = XLSX.read(input, { type: 'binary' });
let xlData = XLSX.utils.sheet_to_json(wb.Sheets['Sheet2']); 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) res.send(data)
var fileData = JSON.stringify(data)
console.log(fileData)
axios({ axios({
url: 'http://localhost:4000/graphql', url: 'http://localhost:4000/graphql',
method: 'post', method: 'post',
@ -54,9 +57,9 @@ app.post('/upload', async function (req, res) {
data: { data: {
query: ` query: `
mutation{ mutation{
createManyProducts(file: "${JSON.stringify(data)}") createManyProducts(file: ${JSON.stringify(fileData)})
} }
` `,
} }
}).then((result) => { }).then((result) => {
console.log(result.data) console.log(result.data)