Skip to content

Commit

Permalink
return -1 if clock value not found, not undefined (#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicky-g committed Jul 8, 2021
1 parent 1223a3b commit 0509340
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions creator-node/src/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,32 @@ module.exports = function (app) {
*/
app.post('/users/batch_clock_status', handleResponse(async (req, res) => {
const { walletPublicKeys } = req.body
const walletPublicKeysSet = new Set(walletPublicKeys)

// Fetch clock values for input wallets
const cnodeUsers = await models.CNodeUser.findAll({
where: {
walletPublicKey: {
[models.Sequelize.Op.in]: walletPublicKeys
}
}
})
return successResponse({
users: cnodeUsers.map(cnodeUser => ({

// For found users, return the clock value
let users = cnodeUsers.map(cnodeUser => {
walletPublicKeysSet.delete(cnodeUser.walletPublicKey)
return {
walletPublicKey: cnodeUser.walletPublicKey,
clock: cnodeUser.clock
}))
}
})

// If there are any remaining wallets, default to -1
const remainingWalletPublicKeys = Array.from(walletPublicKeysSet)
remainingWalletPublicKeys.forEach(wallet => {
users.push({ walletPublicKey: wallet, clock: -1 })
})

return successResponse({ users })
}))
}

0 comments on commit 0509340

Please sign in to comment.