本文整理汇总了TypeScript中decentraland-server.server.extractFromReq方法的典型用法代码示例。如果您正苦于以下问题:TypeScript server.extractFromReq方法的具体用法?TypeScript server.extractFromReq怎么用?TypeScript server.extractFromReq使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类decentraland-server.server
的用法示例。
在下文中一共展示了server.extractFromReq方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getString
function getString(req: Request, param: string, defaultValue: any = null) {
try {
return server.extractFromReq(req, param)
} catch (error) {
return defaultValue
}
}
示例2: getTranslations
async getTranslations(req: express.Request): Promise<TranslationData> {
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)
}
示例3: getPollVotes
async getPollVotes(req: express.Request) {
const pollId = server.extractFromReq(req, 'id')
return Option.find<OptionAttributes>({ poll_id: Number(pollId) })
}
示例4: getReceipt
async getReceipt(req: express.Request) {
const id = server.extractFromReq(req, 'id')
return Receipt.findOne(id)
}
示例5: getAccountReceipts
async getAccountReceipts(req: express.Request) {
const address = server.extractFromReq(req, 'address')
return Receipt.find<ReceiptAttributes>({ account_address: address })
}
示例6: getAccountBalances
async getAccountBalances(req: express.Request) {
const address = server.extractFromReq(req, 'address')
return AccountBalance.find<AccountBalanceAttributes>({ address })
}
示例7: getPoll
async getPoll(req: express.Request) {
const id = server.extractFromReq(req, 'id')
const poll = await Poll.findByIdWithAssociations(id)
return utils.omit(poll, blacklist.poll)
}
示例8: createVote
async createVote(req: express.Request): Promise<string | undefined> {
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()
if (poll.isDistrictPoll()) {
// Disallow fake contributions
const account = await AccountBalance.findOne<AccountBalanceAttributes>({
address,
token_address: poll.get('token_address')
})
balance = account ? account.balance : '0'
}
const vote = new Vote({
id,
account_balance: balance,
account_address: address,
poll_id: pollId,
option_id: optionId,
timestamp,
message,
signature,
created_at: new Date(Number(timestamp)),
updated_at: new Date(Number(timestamp))
})
const account = new AccountBalance({
address,
token_address: poll.get('token_address'),
balance
})
await account.upsert({ target: ['address', 'token_address'] })
await vote.upsert({ target: ['account_address', 'poll_id'] })
if (vote.get('id') !== id) {
throw new Error(`Something went wrong inserting vote ${id}`)
}
const option = await Option.findOne(optionId)
const castVote: CastVoteOption = {
...vote.getAll(),
id,
option
}
const receipt = await Receipt.createFromVote(castVote)
if (receipt) {
return receipt.id
}
}
示例9: getPollVotes
async getPollVotes(req: express.Request) {
const pollId = server.extractFromReq(req, 'id')
return Vote.find({ poll_id: pollId })
}
示例10: getVote
async getVote(req: express.Request) {
const id = server.extractFromReq(req, 'id')
return Vote.findCastVoteById(id)
}