当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript server.extractFromReq方法代码示例

本文整理汇总了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
  }
}
开发者ID:decentraland,项目名称:agora,代码行数:7,代码来源:extractFromReq.ts

示例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)
 }
开发者ID:decentraland,项目名称:agora,代码行数:5,代码来源:Translation.router.ts

示例3: getPollVotes

 async getPollVotes(req: express.Request) {
   const pollId = server.extractFromReq(req, 'id')
   return Option.find<OptionAttributes>({ poll_id: Number(pollId) })
 }
开发者ID:decentraland,项目名称:agora,代码行数:4,代码来源:Option.router.ts

示例4: getReceipt

 async getReceipt(req: express.Request) {
   const id = server.extractFromReq(req, 'id')
   return Receipt.findOne(id)
 }
开发者ID:decentraland,项目名称:agora,代码行数:4,代码来源:Receipt.router.ts

示例5: getAccountReceipts

 async getAccountReceipts(req: express.Request) {
   const address = server.extractFromReq(req, 'address')
   return Receipt.find<ReceiptAttributes>({ account_address: address })
 }
开发者ID:decentraland,项目名称:agora,代码行数:4,代码来源:Receipt.router.ts

示例6: getAccountBalances

 async getAccountBalances(req: express.Request) {
   const address = server.extractFromReq(req, 'address')
   return AccountBalance.find<AccountBalanceAttributes>({ address })
 }
开发者ID:decentraland,项目名称:agora,代码行数:4,代码来源:AccountBalance.router.ts

示例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)
 }
开发者ID:decentraland,项目名称:agora,代码行数:5,代码来源:Poll.router.ts

示例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
    }
  }
开发者ID:decentraland,项目名称:agora,代码行数:69,代码来源:Vote.router.ts

示例9: getPollVotes

 async getPollVotes(req: express.Request) {
   const pollId = server.extractFromReq(req, 'id')
   return Vote.find({ poll_id: pollId })
 }
开发者ID:decentraland,项目名称:agora,代码行数:4,代码来源:Vote.router.ts

示例10: getVote

 async getVote(req: express.Request) {
   const id = server.extractFromReq(req, 'id')
   return Vote.findCastVoteById(id)
 }
开发者ID:decentraland,项目名称:agora,代码行数:4,代码来源:Vote.router.ts


注:本文中的decentraland-server.server.extractFromReq方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。