How to use the server/models/User.query function in server

To help you get started, we’ve selected a few 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 argos-ci / argos / src / server / graphql / definitions / Owner.js View on Github external
export async function getOwner({ login }) {
  let owner = await Organization.query()
    .where({ login })
    .limit(1)
    .first()

  if (owner) {
    owner.type = OWNER_TYPES.organization
    return owner
  }

  owner = await User.query()
    .where({ login })
    .limit(1)
    .first()

  if (owner) {
    owner.type = OWNER_TYPES.user
    return owner
  }

  return null
}
github argos-ci / argos / src / modules / synchronizer / GitHubSynchronizer.js View on Github external
async synchronizeUser(githubUser) {
    const data = { githubId: githubUser.id, login: githubUser.login }
    let user = await User.query()
      .where({ githubId: githubUser.id })
      .limit(1)
      .first()

    if (user) {
      await user.$query().patchAndFetch(data)
    } else {
      user = await User.query().insert(data)
    }

    return user
  }
github argos-ci / argos / src / modules / synchronizer / GitHubSynchronizer.js View on Github external
async synchronizeUser(githubUser) {
    const data = { githubId: githubUser.id, login: githubUser.login }
    let user = await User.query()
      .where({ githubId: githubUser.id })
      .limit(1)
      .first()

    if (user) {
      await user.$query().patchAndFetch(data)
    } else {
      user = await User.query().insert(data)
    }

    return user
  }
github argos-ci / argos / src / server / graphql / utils.js View on Github external
export async function getOwner({ login }) {
  let owner = await Organization.query()
    .where({ login })
    .limit(1)
    .first()
  if (owner) {
    owner.type = 'organization'
    return owner
  }

  owner = await User.query()
    .where({ login })
    .limit(1)
    .first()
  if (owner) {
    owner.type = 'user'
    return owner
  }

  return null
}
github argos-ci / argos / src / server / routes / configurePassport.js View on Github external
accessToken,
                previousAccessToken: user.accessToken,
                privateSync,
              })
              user = await user.$query().patchAndFetch({
                ...authorizationState,
                privateSync,
                ...getDataFromProfile(profile),
              })
            } else {
              const privateSync = type === 'private'
              const authorizationState = await getUserAuthorizationState({
                accessToken,
                privateSync,
              })
              user = await User.query().insert({
                ...authorizationState,
                privateSync,
                ...getDataFromProfile(profile),
              })
            }

            syncFromUserId(user.id)

            done(null, user)
          } catch (err) {
            Sentry.captureException(err)
            done(err)
          }
        },
      ),
github argos-ci / argos / src / server / models / Build.js View on Github external
static getUsers(buildId) {
    return User.query()
      .select('users.*')
      .join(
        'user_repository_rights',
        'users.id',
        '=',
        'user_repository_rights.userId',
      )
      .join(
        'repositories',
        'user_repository_rights.repositoryId',
        '=',
        'repositories.id',
      )
      .join('builds', 'repositories.id', '=', 'builds.repositoryId')
      .where('builds.id', buildId)
  }
github argos-ci / argos / src / server / routes / configurePassport.js View on Github external
passport.deserializeUser(async (id, done) => {
    try {
      done(null, await User.query().findById(id))
    } catch (err) {
      Sentry.captureException(err)
      done(err)
    }
  })
}
github argos-ci / argos / src / server / graphql / definitions / Owner.js View on Github external
async owners(rootObj, args, context) {
      const organizations = await context.user.$relatedQuery('organizations')
      const users = await User.query()
        .distinct('users.id')
        .select('users.*')
        .innerJoin('repositories', 'repositories.userId', 'users.id')
        .innerJoin(
          'user_repository_rights',
          'user_repository_rights.repositoryId',
          'repositories.id',
        )
        .where('user_repository_rights.userId', context.user.id)

      return [
        ...organizations.map(organization => ({
          ...organization,
          type: OWNER_TYPES.organization,
        })),
        ...users.map(user => ({ ...user, type: OWNER_TYPES.user })),