chore(useremails): use table helper for primary key
This commit is contained in:
@@ -36,7 +36,7 @@ export const getUsersBaseQuery = (
|
||||
queryBuilder
|
||||
.where((qb) => {
|
||||
qb.where(UserEmails.col.email, 'ILIKE', `%${searchQuery}%`).where({
|
||||
primary: true
|
||||
[UserEmails.col.primary]: true
|
||||
})
|
||||
})
|
||||
.orWhere(Users.col.name, 'ILIKE', `%${searchQuery}%`)
|
||||
|
||||
@@ -54,7 +54,7 @@ export async function getUsers(
|
||||
|
||||
const q = Users.knex<UserWithOptionalRole[]>().whereIn(Users.col.id, userIds)
|
||||
q.leftJoin(UserEmails.name, UserEmails.col.userId, Users.col.id).where({
|
||||
primary: true
|
||||
[UserEmails.col.primary]: true
|
||||
})
|
||||
|
||||
const columns: (Knex.Raw<UserRecord> | string)[] = [
|
||||
@@ -106,7 +106,7 @@ export async function listUsers({
|
||||
])
|
||||
.leftJoin(ServerAcl.name, ServerAcl.col.userId, Users.col.id)
|
||||
.leftJoin(UserEmails.name, UserEmails.col.userId, Users.col.id)
|
||||
.where({ primary: true })
|
||||
.where({ [UserEmails.col.primary]: true })
|
||||
.groupBy(Users.col.id)
|
||||
if (cursor) q.where(Users.col.createdAt, '<', cursor)
|
||||
const users: UserWithRole[] = await getUsersBaseQuery(q, { searchQuery: query, role })
|
||||
@@ -148,7 +148,7 @@ export async function getUserByEmail(
|
||||
|
||||
const q = Users.knex<UserWithOptionalRole[]>().where(Users.col.id, userEmail.userId)
|
||||
q.leftJoin(UserEmails.name, UserEmails.col.userId, Users.col.id).where({
|
||||
primary: true
|
||||
[UserEmails.col.primary]: true
|
||||
})
|
||||
const columns: (Knex.Raw<UserRecord> | string)[] = [
|
||||
...Object.values(omit(Users.col, ['email', 'verified'])),
|
||||
|
||||
@@ -38,9 +38,6 @@ const {
|
||||
findEmailFactory
|
||||
} = require('@/modules/core/repositories/userEmails')
|
||||
const { db } = require('@/db/knex')
|
||||
const {
|
||||
findUserByTargetFactory
|
||||
} = require('@/modules/serverinvites/repositories/serverInvites')
|
||||
|
||||
const _changeUserRole = async ({ userId, role }) =>
|
||||
await Acl().where({ userId }).update({ role })
|
||||
@@ -158,7 +155,7 @@ module.exports = {
|
||||
const user = await Users()
|
||||
.where({ [UsersSchema.col.id]: userId })
|
||||
.leftJoin(UserEmails.name, UserEmails.col.userId, UsersSchema.col.id)
|
||||
.where({ primary: true, [UserEmails.col.userId]: userId })
|
||||
.where({ [UserEmails.col.primary]: true, [UserEmails.col.userId]: userId })
|
||||
.columns([
|
||||
...Object.values(omit(UsersSchema.col, ['email', 'verified'])),
|
||||
knex.raw(`(array_agg("user_emails"."email"))[1] as email`),
|
||||
@@ -175,7 +172,7 @@ module.exports = {
|
||||
const user = await Users()
|
||||
.where({ [UsersSchema.col.id]: id })
|
||||
.leftJoin(UserEmails.name, UserEmails.col.userId, UsersSchema.col.id)
|
||||
.where({ primary: true, [UserEmails.col.userId]: id })
|
||||
.where({ [UserEmails.col.primary]: true, [UserEmails.col.userId]: id })
|
||||
.columns([
|
||||
...Object.values(omit(UsersSchema.col, ['email', 'verified'])),
|
||||
knex.raw(`(array_agg("user_emails"."email"))[1] as email`),
|
||||
@@ -190,7 +187,7 @@ module.exports = {
|
||||
async getUserByEmail({ email }) {
|
||||
const user = await Users()
|
||||
.leftJoin(UserEmails.name, UserEmails.col.userId, UsersSchema.col.id)
|
||||
.where({ primary: true })
|
||||
.where({ [UserEmails.col.primary]: true })
|
||||
.whereRaw('lower("user_emails"."email") = lower(?)', [email])
|
||||
.columns([
|
||||
...Object.values(omit(UsersSchema.col, ['email', 'verified'])),
|
||||
|
||||
Reference in New Issue
Block a user