How to use the decentraland-server.server.extractFromReq function in decentraland-server

To help you get started, we’ve selected a few decentraland-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github decentraland / agora / src / Translation / Translation.router.ts View on Github external
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)
  }
}
github decentraland / agora / src / Poll / Poll.router.ts View on Github external
async getPoll(req: express.Request) {
    const id = server.extractFromReq(req, 'id')
    const poll = await Poll.findByIdWithAssociations(id)
    return utils.omit(poll, blacklist.poll)
  }
}
github decentraland / agora / src / Vote / Vote.router.ts View on Github external
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()
github decentraland / agora / src / Vote / Vote.router.ts View on Github external
async getVote(req: express.Request) {
    const id = server.extractFromReq(req, 'id')
    return Vote.findCastVoteById(id)
  }
github decentraland / agora / src / Vote / Vote.router.ts View on Github external
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')
github decentraland / agora / src / Receipt / Receipt.router.ts View on Github external
async getReceipt(req: express.Request) {
    const id = server.extractFromReq(req, 'id')
    return Receipt.findOne(id)
  }
github decentraland / agora / src / Vote / Vote.router.ts View on Github external
async getPollVotes(req: express.Request) {
    const pollId = server.extractFromReq(req, 'id')
    return Vote.find({ poll_id: pollId })
  }
github decentraland / agora / src / Vote / Vote.router.ts View on Github external
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')
github decentraland / agora / src / Receipt / Receipt.router.ts View on Github external
async getAccountReceipts(req: express.Request) {
    const address = server.extractFromReq(req, 'address')
    return Receipt.find({ account_address: address })
  }
}
github decentraland / agora / src / Option / Option.router.ts View on Github external
async getPollVotes(req: express.Request) {
    const pollId = server.extractFromReq(req, 'id')
    return Option.find({ poll_id: Number(pollId) })
  }
}