Skip to content

Commit

Permalink
Merge pull request #33 from NewcastleRSE/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
markdturner authored May 20, 2024
2 parents eee0f1f + df8d089 commit 2117489
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 262 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"dependencies": {
"@hubspot/api-client": "^9.0.0",
"@pdf-lib/fontkit": "^1.1.1",
"@strapi/plugin-documentation": "^4.21.0",
"@strapi/plugin-i18n": "^4.21.0",
"@strapi/plugin-sentry": "^4.21.0",
"@strapi/plugin-users-permissions": "^4.21.0",
"@strapi/strapi": "^4.21.0",
"@strapi/plugin-documentation": "^4.24.2",
"@strapi/plugin-i18n": "^4.24.2",
"@strapi/plugin-sentry": "^4.24.2",
"@strapi/plugin-users-permissions": "^4.24.2",
"@strapi/strapi": "^4.24.2",
"axios": "1.4.0",
"camelcase": "5.2.0",
"camelcase-keys": "5.2.0",
Expand Down
30 changes: 18 additions & 12 deletions src/api/transaction/services/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = createCoreService('api::transaction.transaction', ({ strapi })
await workbook.xlsx.readFile(file.path)
const transactionSheet = workbook.getWorksheet(TransactionsWorksheetName)

let transactions = []
let transactions = [],
errorCount = 0

// clear all previous transactions; ID is always not null
await strapi.db.query('api::transaction.transaction').deleteMany({
Expand All @@ -42,14 +43,14 @@ module.exports = createCoreService('api::transaction.transaction', ({ strapi })
documentNumber: Number(row.values[5]),
documentHeader: row.values[6],
name: row.values[7],
fiscalYear: Number(row.values[8]),
fiscalPeriod: Number(row.values[9]),
documentDate: DateTime.fromJSDate(new Date(row.values[10])).toISODate(),
postedDate: DateTime.fromJSDate(new Date(row.values[11])).toISODate(),
fiscalYear: Number(row.values[9]),
fiscalPeriod: Number(row.values[10]),
documentDate: DateTime.fromJSDate(new Date(row.values[11])).toISODate(),
postedDate: DateTime.fromJSDate(new Date(row.values[12])).toISODate(),
// SAP gets the debit and credit wrong way around, times -1 to fix
value: (row.values[12].hasOwnProperty('result') ? parseFloat(row.values[12].result) : parseFloat(row.values[12])) * -1,
bwCategory: row.values[13].hasOwnProperty('result') ? row.values[13].result : row.values[13],
ieCategory: row.values[14].hasOwnProperty('result') ? row.values[14].result : row.values[14],
value: (row.values[13].hasOwnProperty('result') ? parseFloat(row.values[13].result) : parseFloat(row.values[13])) * -1,
bwCategory: row.values[14].hasOwnProperty('result') ? row.values[14].result : row.values[14],
ieCategory: row.values[15].hasOwnProperty('result') ? row.values[15].result : row.values[15],
internalCategory: null
}

Expand All @@ -61,6 +62,7 @@ module.exports = createCoreService('api::transaction.transaction', ({ strapi })
isNaN(transaction.fiscalPeriod) ||
isNaN(transaction.value)
) {
errorCount++
console.error(transaction)
}

Expand Down Expand Up @@ -129,9 +131,13 @@ module.exports = createCoreService('api::transaction.transaction', ({ strapi })
}
})

let count = await strapi.db.query('api::transaction.transaction').createMany({ data: transactions })

return { message: 'Successfully uploaded transaction data', count }

try {
await strapi.db.query('api::transaction.transaction').createMany({ data: transactions })
return { message: 'Successfully uploaded transaction data' }
}
catch (error) {
console.error(`Failed to add ${transactions.length} transactions to the database. Encountered ${errorCount} errors.`)
console.error(error)
}
},
}))
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "2024-03-23T20:30:19.850Z"
"x-generation-date": "2024-05-14T21:37:58.814Z"
},
"x-strapi-config": {
"path": "/documentation",
Expand Down
Loading

0 comments on commit 2117489

Please sign in to comment.