Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async getTranslations(req: express.Request): Promise {
let locale = server.extractFromReq(req, 'locale')
locale = locale.slice(0, 2) // We support base locales for now, like en, it, etc
return new Translation().fetch(locale)
}
}
async getPoll(req: express.Request) {
const id = server.extractFromReq(req, 'id')
const poll = await Poll.findByIdWithAssociations(id)
return utils.omit(poll, blacklist.poll)
}
}
async createVote(req: express.Request): Promise {
const id = server.extractFromReq(req, 'id')
const message = server.extractFromReq(req, 'message')
const signature = server.extractFromReq(req, 'signature')
const signedMessage = new SignedMessage(message, signature)
let [pollId, optionId, balance, timestamp] = signedMessage.extract([
'Poll Id',
'Option Id',
'Current Balance',
'Timestamp'
])
const poll = new Poll()
await poll.retreive({ id: pollId })
if (poll.isEmpty()) throw new Error(`Poll not found for id ${pollId}`)
if (poll.isFinished()) throw new Error('Poll already finished')
const address = signedMessage.getAddress().toLowerCase()
async getVote(req: express.Request) {
const id = server.extractFromReq(req, 'id')
return Vote.findCastVoteById(id)
}
async createVote(req: express.Request): Promise {
const id = server.extractFromReq(req, 'id')
const message = server.extractFromReq(req, 'message')
const signature = server.extractFromReq(req, 'signature')
const signedMessage = new SignedMessage(message, signature)
let [pollId, optionId, balance, timestamp] = signedMessage.extract([
'Poll Id',
'Option Id',
'Current Balance',
'Timestamp'
])
const poll = new Poll()
await poll.retreive({ id: pollId })
if (poll.isEmpty()) throw new Error(`Poll not found for id ${pollId}`)
if (poll.isFinished()) throw new Error('Poll already finished')
async getReceipt(req: express.Request) {
const id = server.extractFromReq(req, 'id')
return Receipt.findOne(id)
}
async getPollVotes(req: express.Request) {
const pollId = server.extractFromReq(req, 'id')
return Vote.find({ poll_id: pollId })
}
async createVote(req: express.Request): Promise {
const id = server.extractFromReq(req, 'id')
const message = server.extractFromReq(req, 'message')
const signature = server.extractFromReq(req, 'signature')
const signedMessage = new SignedMessage(message, signature)
let [pollId, optionId, balance, timestamp] = signedMessage.extract([
'Poll Id',
'Option Id',
'Current Balance',
'Timestamp'
])
const poll = new Poll()
await poll.retreive({ id: pollId })
if (poll.isEmpty()) throw new Error(`Poll not found for id ${pollId}`)
if (poll.isFinished()) throw new Error('Poll already finished')
async getAccountReceipts(req: express.Request) {
const address = server.extractFromReq(req, 'address')
return Receipt.find({ account_address: address })
}
}
async getPollVotes(req: express.Request) {
const pollId = server.extractFromReq(req, 'id')
return Option.find({ poll_id: Number(pollId) })
}
}