How to use decentraland-server - 10 common examples

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 / specs / utils.ts View on Github external
export function mockModelDbOperations(operations: { [key: string]: Function }) {
  const log = new Log('Query')
  const toJSON = obj => JSON.stringify(obj) // Formatting aid

  const _query = Model.db.query
  const _count = Model.db.count

  operations = {
    query: async function(query, args) {
      const rows = await _query.call(this, query, args)
      log.info(`Executing:\n${query} ${toJSON(args)} => ${rows.length} rows`)
      return rows
    },
    count: async function(tableName, conditions) {
      const count = await _count.call(this, tableName, conditions)
      log.info(
        `Counting: ${toJSON(conditions)} on ${tableName} => ${toJSON(count)}`
      )
      return count
    },
    insert: (tableName, row) => {
github decentraland / agora / specs / utils.ts View on Github external
export function mockModelDbOperations(operations: { [key: string]: Function }) {
  const log = new Log('Query')
  const toJSON = obj => JSON.stringify(obj) // Formatting aid

  const _query = Model.db.query
  const _count = Model.db.count

  operations = {
    query: async function(query, args) {
      const rows = await _query.call(this, query, args)
      log.info(`Executing:\n${query} ${toJSON(args)} => ${rows.length} rows`)
      return rows
    },
    count: async function(tableName, conditions) {
      const count = await _count.call(this, tableName, conditions)
      log.info(
        `Counting: ${toJSON(conditions)} on ${tableName} => ${toJSON(count)}`
      )
      return count
    },
    insert: (tableName, row) => {
      log.info(`Inserting: ${toJSON(row)} on ${tableName}`)
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 / scripts / initDb.ts View on Github external
export async function initializeDatabase() {
  const shouldContinue = await cli.confirm(
    `Careful! this will DROP 'projects' and 'district_entries,
  upsert 'account_balances' and a district token.
Do you wish to continue?`
  )
  if (!shouldContinue) return process.exit()

  log.info('Connecting database')
  await db.connect()

  log.info('Initializing state')
  await dropDumps()

  log.info('Restoring district_entries')
  execSync(runpsql('../dumps/districts.20180105.sql'))

  log.info('Restoring projects')
github decentraland / agora / src / lib / Model.queries.ts View on Github external
jsonAgg: (tableName: string, params: JSONAggParams = {}): SQLStatement => {
    const { columnName, filterColumn, orderColumn } = Object.assign(
      { columnName: '*', filterColumn: 'id', orderColumn: 'id' },
      params
    )
    const column = raw(`${tableName}.${columnName}`)
    const filter = raw(`${tableName}.${filterColumn}`)
    const order = raw(`${tableName}.${orderColumn}`)

    return SQL`COALESCE(
            json_agg(${column} ORDER BY ${order}) FILTER (WHERE ${filter} IS NOT NULL),
            '[]'
        )`
  }
})
github decentraland / agora / src / Vote / Vote.model.ts View on Github external
static async findCastVoteById(id: string) {
    return this.query(SQL`
      SELECT v.*,
            row_to_json(p.*) as poll,
            row_to_json(o.*) as option,
            row_to_json(t.*) as token
        FROM ${raw(this.tableName)} v
          JOIN ${raw(Poll.tableName)} p ON p.id = v.poll_id
          JOIN ${raw(Option.tableName)} o ON o.id = v.option_id
          JOIN ${raw(Token.tableName)} t ON t.address = p.token_address
        WHERE v.id = ${id}`)
  }
github decentraland / agora / src / Poll / Poll.queries.ts View on Github external
findWithAssociations: (whereStatement: SQLStatement = SQL``): SQLStatement =>
    SQL`
      SELECT p.*,
          row_to_json(t.*) as token,
          (SELECT ${ModelQueries.jsonAgg('v', {
            orderColumn: 'timestamp DESC'
          })} AS votes FROM ${raw(Vote.tableName)} v WHERE v.poll_id = p.id),
          (SELECT ${ModelQueries.jsonAgg('o', {
            orderColumn: 'value ASC'
          })} AS options FROM ${raw(Option.tableName)} o WHERE o.poll_id = p.id)
        FROM polls p
          JOIN ${raw(Token.tableName)} t ON t.address = p.token_address
        ${whereStatement}
        GROUP BY p.id, t.address`
})
github decentraland / agora / src / Vote / Vote.model.ts View on Github external
static async findCastVoteById(id: string) {
    return this.query(SQL`
      SELECT v.*,
            row_to_json(p.*) as poll,
            row_to_json(o.*) as option,
            row_to_json(t.*) as token
        FROM ${raw(this.tableName)} v
          JOIN ${raw(Poll.tableName)} p ON p.id = v.poll_id
          JOIN ${raw(Option.tableName)} o ON o.id = v.option_id
          JOIN ${raw(Token.tableName)} t ON t.address = p.token_address
        WHERE v.id = ${id}`)
  }
github decentraland / agora / src / Vote / Vote.model.ts View on Github external
static async findCastVoteById(id: string) {
    return this.query(SQL`
      SELECT v.*,
            row_to_json(p.*) as poll,
            row_to_json(o.*) as option,
            row_to_json(t.*) as token
        FROM ${raw(this.tableName)} v
          JOIN ${raw(Poll.tableName)} p ON p.id = v.poll_id
          JOIN ${raw(Option.tableName)} o ON o.id = v.option_id
          JOIN ${raw(Token.tableName)} t ON t.address = p.token_address
        WHERE v.id = ${id}`)
  }