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 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)