-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bnonni
committed
May 7, 2022
1 parent
1bda121
commit e92c329
Showing
7 changed files
with
50 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
const debug = require('../../utils/debug'); | ||
const accountService = require('./accountService'); | ||
|
||
const getAccountBalance = async (req, res) => { | ||
const getAccountAllowance = async (req, res) => { | ||
try { | ||
const username = req._parsedUrl.query.split('=')[1]; | ||
username, passphrase, alias, start | ||
const response = await accountService.getAccountBalance(username); | ||
const response = await accountService.getAccountAllowance(); | ||
|
||
debug.info(`Invoice Creation Response: ${JSON.stringify(response)}`); | ||
debug.info(`Account Allowance Response: ${JSON.stringify(response)}`); | ||
|
||
if (!response.success) res.status(500).json(response); | ||
else res.status(200).json(response); | ||
|
||
} catch (error) { | ||
debug.error(error.stack); | ||
res.status(500).json({ message: error.message, error: error.stack }); | ||
} | ||
}; | ||
|
||
module.exports = { getAccountBalance }; | ||
module.exports = { getAccountAllowance }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
const express = require('express'); | ||
const router = express(); | ||
|
||
const { getAccountBalance } = require('./accountController'); | ||
const { getAccountAllowance } = require('./accountController'); | ||
|
||
router.get('/allowance', getAccountBalance); | ||
router.get('/allowance', getAccountAllowance); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,4 @@ | ||
const debug = require('../../utils/debug'); | ||
const accounts = require('../../db/collection'); | ||
|
||
// replace spots with accounts | ||
const spots = require('../../db/collection'); | ||
|
||
|
||
// replace all functions | ||
const getParkingSpotDetails = async (uuid) => { | ||
try { | ||
return { success: true, message: (await spots.doc(uuid).get()).data() }; | ||
} catch (error) { | ||
debug.error(error.stack); | ||
throw new Error(error); | ||
} | ||
}; | ||
|
||
const reserveParkingSpot = async (uuid, licensePlate, duration) => { | ||
try { | ||
const spot = spots.doc(uuid); | ||
const startTime = Math.floor(new Date().getTime() / 1000); | ||
if (!spot.occupied) { | ||
var response = await spot.update({ | ||
duration: duration, | ||
expirationTime: startTime + duration, | ||
expired: false, | ||
licensePlate: licensePlate, | ||
occupied: true, | ||
startTime: startTime, | ||
}); | ||
|
||
return { success: true, message: response }; | ||
} | ||
} catch (error) { | ||
debug.error(error.stack); | ||
throw new Error(error); | ||
} | ||
}; | ||
|
||
const shouldBeEmpty = async () => { | ||
try { | ||
const shouldBeEmptySpots = {} | ||
const expiredSpots = []; | ||
const emptySpots = []; | ||
const now = Math.floor(new Date().getTime() / 1000); | ||
const unoccupiedSpots = await spots | ||
.where('occupied', '==', false) | ||
.get(); | ||
|
||
unoccupiedSpots.forEach(spot => { | ||
emptySpots.push(spot.data()) | ||
}) | ||
shouldBeEmptySpots.unoccupiedSpots = emptySpots; | ||
|
||
const occupiedSpots = await spots | ||
.where('occupied', '==', true) | ||
.get(); | ||
|
||
occupiedSpots.forEach((spot) => { | ||
const spotData = spot.data() | ||
if((spotData.expirationTime - now) <= 0){ | ||
spots.doc(spot.id).update({ | ||
expired: true | ||
}) | ||
spotData.expired = true; | ||
expiredSpots.push(spotData) | ||
} | ||
}) | ||
shouldBeEmptySpots.expiredSpots = expiredSpots; | ||
|
||
return { success: true, message: shouldBeEmptySpots }; | ||
} catch (error) { | ||
debug.error(error.stack); | ||
throw new Error(error); | ||
} | ||
}; | ||
|
||
module.exports = { getParkingSpotDetails, reserveParkingSpot, shouldBeEmpty }; | ||
module.exports = { }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
const express = require('express'); | ||
const router = express(); | ||
|
||
const { getAllBalances } = require('./adminController'); | ||
const { getAllBalances, addNewAccount, keysend } = require('./adminController'); | ||
|
||
router.get('/details', getAllBalances); | ||
router.get('/balances', getAllBalances); | ||
router.post('/add', addNewAccount); | ||
router.post('/transfer', keysend); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters