Skip to content

Commit

Permalink
Added meterStart to update when creating chargeSession.
Browse files Browse the repository at this point in the history
  • Loading branch information
SweOlle committed Oct 11, 2023
1 parent a7fce4c commit de7278c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
5 changes: 2 additions & 3 deletions backend-app/src/data-access-layer/transactions-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module.exports = function ({ databaseInit }) {
const exports = {}

exports.addTransaction = function (chargeSessionID, userID, payNow, paymentDueDate, paymentMethod, totalPrice, callback) {
console.log("final addTransaction MEthod")
console.log(chargeSessionID + " : " + userID)
const date = (Date.now() / 1000 | 0)
const transaction = {
Expand Down Expand Up @@ -42,8 +41,8 @@ module.exports = function ({ databaseInit }) {
})
}

exports.getTransactionsForCharger = function(connectorID, callback) {
databaseInit.Transactions.findAll({ include: { model: databaseInit.ChargeSessions, where: { 'connectorID' : connectorID }, raw: true }})
exports.getTransactionsForCharger = function (connectorID, callback) {
databaseInit.Transactions.findAll({ include: { model: databaseInit.ChargeSessions, where: { 'connectorID': connectorID }, raw: true } })
.then(transactions => callback([], transactions))
.catch(e => {
console.log(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,24 @@ module.exports = function ({ dataAccessLayerChargeSessions, dataAccessLayerTrans

startTime = (Date.now() / 1000 | 0)

dataAccessLayerChargeSessions.addChargeSession(connectorID, userID, startTime, function (error, chargeSessionID) {
dataAccessLayerChargeSessions.addChargeSession(connectorID, userID, startTime, function (error, chargeSession) {
if (Object.keys(error).length > 0) {
dbErrorCheck.checkError(error, function (errorCode) {
callback(errorCode, [])
})
return
}
else if (chargeSessionID) {
callback([], chargeSessionID)
else if (chargeSession.chargeSessionID) {
dataAccessLayerChargeSessions.updateMeterStart(chargeSession.chargeSessionID, 1, function (error, updatedChargeSession) {
if (Object.keys(error).length > 0) {
dbErrorCheck.checkError(error, function (errorCode) {
callback(errorCode, [])
})
return
}
callback([], chargeSession)
})
}
// Updates MeterStart value in table. Should be set to 0 or 1? Not a variable since we just added the ChargeSession.
// dataAccessLayerChargeSessions.updateMeterStart(chargeSession.chargeSessionID, returnObject.meterStart, (error, updatedChargeSession) => {
// if (Object.keys(error).length > 0) {
// dbErrorCheck.checkError(error, function (errorCode) {
// callback(errorCode, [])
// })
// return
// }

// callback([], updatedChargeSession)
// })
})
}

Expand Down Expand Up @@ -189,7 +186,7 @@ module.exports = function ({ dataAccessLayerChargeSessions, dataAccessLayerTrans

exports.updateMeterStart = function (chargeSessionID, meterStart, callback) {
const validationErrors = chargeSessionValidation.updateMeterStartValidation(chargeSessionID, meterStart)
if(validationErrors.length > 0) { callback(validationErrors, []); return }
if (validationErrors.length > 0) { callback(validationErrors, []); return }

dataAccessLayerChargeSessions.updateMeterStart(chargeSessionID, meterStart, (error, updatedChargingSession) => {
if (Object.keys(error).length > 0) {
Expand Down

0 comments on commit de7278c

Please sign in to comment.