@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 70.5 kB
Source Map (JSON)
{"version":3,"file":"users.mjs","names":["queryBuilder"],"sources":["../../../src/libs/repositories/users.ts"],"sourcesContent":["import { type SelectQueryBuilder, sql } from \"kysely\";\nimport z from \"zod\";\nimport type { GetMultipleQueryParams } from \"../../schemas/users.js\";\nimport type DatabaseAdapter from \"../db/adapter-base.js\";\nimport queryBuilder, {\n\ttype QueryBuilderWhere,\n} from \"../db/query-builder/index.js\";\nimport type { KyselyDB, LucidUsers, Select } from \"../db/types.js\";\nimport StaticRepository from \"./parents/static-repository.js\";\nimport type { QueryProps } from \"./types.js\";\n\nexport default class UsersRepository extends StaticRepository<\"lucid_users\"> {\n\tconstructor(db: KyselyDB, dbAdapter: DatabaseAdapter) {\n\t\tsuper(db, dbAdapter, \"lucid_users\");\n\t}\n\ttableSchema = z.object({\n\t\tid: z.number(),\n\t\tsuper_admin: z.union([\n\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.true),\n\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.false),\n\t\t]),\n\t\temail: z.email(),\n\t\tusername: z.string(),\n\t\tfirst_name: z.string().nullable(),\n\t\tlast_name: z.string().nullable(),\n\t\tpassword: z.string().nullable(),\n\t\tsecret: z.string(),\n\t\ttriggered_password_reset: z.union([\n\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.true),\n\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.false),\n\t\t]),\n\t\tinvitation_accepted: z.union([\n\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.true),\n\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.false),\n\t\t]),\n\t\tis_locked: z.union([\n\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.true),\n\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.false),\n\t\t]),\n\t\tis_deleted: z.union([\n\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.true),\n\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.false),\n\t\t]),\n\t\tis_deleted_at: z.union([z.string(), z.date()]).nullable(),\n\t\tdeleted_by: z.number().nullable(),\n\t\tprofile_picture_media_id: z.number().nullable().optional(),\n\t\tprofile_picture: z\n\t\t\t.array(\n\t\t\t\tz.object({\n\t\t\t\t\tid: z.number(),\n\t\t\t\t\tkey: z.string(),\n\t\t\t\t\torigin: z.enum([\"human\", \"ai_generated\", \"ai_modified\"]),\n\t\t\t\t\tfolder_id: z.number().nullable(),\n\t\t\t\t\te_tag: z.string().nullable(),\n\t\t\t\t\ttype: z.string(),\n\t\t\t\t\tmime_type: z.string(),\n\t\t\t\t\tfile_extension: z.string(),\n\t\t\t\t\tfile_name: z.string().nullable(),\n\t\t\t\t\tfile_size: z.number(),\n\t\t\t\t\twidth: z.number().nullable(),\n\t\t\t\t\theight: z.number().nullable(),\n\t\t\t\t\tfocal_x: z.number().nullable(),\n\t\t\t\t\tfocal_y: z.number().nullable(),\n\t\t\t\t\tcreated_at: z.union([z.string(), z.date()]).nullable(),\n\t\t\t\t\tupdated_at: z.union([z.string(), z.date()]).nullable(),\n\t\t\t\t\tblur_hash: z.string().nullable(),\n\t\t\t\t\taverage_color: z.string().nullable(),\n\t\t\t\t\tbase64: z.string().nullable().optional(),\n\t\t\t\t\tis_dark: z\n\t\t\t\t\t\t.union([\n\t\t\t\t\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.true),\n\t\t\t\t\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.false),\n\t\t\t\t\t\t])\n\t\t\t\t\t\t.nullable(),\n\t\t\t\t\tis_light: z\n\t\t\t\t\t\t.union([\n\t\t\t\t\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.true),\n\t\t\t\t\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.false),\n\t\t\t\t\t\t])\n\t\t\t\t\t\t.nullable(),\n\t\t\t\t\tcrop: z\n\t\t\t\t\t\t.array(\n\t\t\t\t\t\t\tz.object({\n\t\t\t\t\t\t\t\tid: z.number(),\n\t\t\t\t\t\t\t\tkey: z.string(),\n\t\t\t\t\t\t\t\torigin: z.enum([\"human\", \"ai_generated\", \"ai_modified\"]),\n\t\t\t\t\t\t\t\ttype: z.string(),\n\t\t\t\t\t\t\t\tmime_type: z.string(),\n\t\t\t\t\t\t\t\tfile_extension: z.string(),\n\t\t\t\t\t\t\t\tfile_name: z.string().nullable(),\n\t\t\t\t\t\t\t\tfile_size: z.number(),\n\t\t\t\t\t\t\t\twidth: z.number().nullable(),\n\t\t\t\t\t\t\t\theight: z.number().nullable(),\n\t\t\t\t\t\t\t\tfocal_x: z.number().nullable(),\n\t\t\t\t\t\t\t\tfocal_y: z.number().nullable(),\n\t\t\t\t\t\t\t\tcrop_x: z.number(),\n\t\t\t\t\t\t\t\tcrop_y: z.number(),\n\t\t\t\t\t\t\t\tcrop_width: z.number(),\n\t\t\t\t\t\t\t\tcrop_height: z.number(),\n\t\t\t\t\t\t\t\tcrop_rotation: z.number(),\n\t\t\t\t\t\t\t\tcrop_skew_x: z.number(),\n\t\t\t\t\t\t\t\tcrop_skew_y: z.number(),\n\t\t\t\t\t\t\t\tblur_hash: z.string().nullable(),\n\t\t\t\t\t\t\t\taverage_color: z.string().nullable(),\n\t\t\t\t\t\t\t\tbase64: z.string().nullable().optional(),\n\t\t\t\t\t\t\t\tis_dark: z\n\t\t\t\t\t\t\t\t\t.union([\n\t\t\t\t\t\t\t\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.true),\n\t\t\t\t\t\t\t\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.false),\n\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t.nullable(),\n\t\t\t\t\t\t\t\tis_light: z\n\t\t\t\t\t\t\t\t\t.union([\n\t\t\t\t\t\t\t\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.true),\n\t\t\t\t\t\t\t\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.false),\n\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t.nullable(),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.optional(),\n\t\t\t\t\tis_deleted: z.union([\n\t\t\t\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.true),\n\t\t\t\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.false),\n\t\t\t\t\t]),\n\t\t\t\t\tis_deleted_at: z.union([z.string(), z.date()]).nullable(),\n\t\t\t\t\tdeleted_by: z.number().nullable(),\n\t\t\t\t\tpublic: z.union([\n\t\t\t\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.true),\n\t\t\t\t\t\tz.literal(this.dbAdapter.config.defaults.boolean.false),\n\t\t\t\t\t]),\n\t\t\t\t\ttranslations: z\n\t\t\t\t\t\t.array(\n\t\t\t\t\t\t\tz.object({\n\t\t\t\t\t\t\t\ttitle: z.string().nullable(),\n\t\t\t\t\t\t\t\talt: z.string().nullable(),\n\t\t\t\t\t\t\t\tlocale_code: z.string().nullable(),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.optional(),\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.optional(),\n\t\tauth_providers: z\n\t\t\t.array(\n\t\t\t\tz.object({\n\t\t\t\t\tid: z.number(),\n\t\t\t\t\tprovider_key: z.string(),\n\t\t\t\t\tprovider_user_id: z.string(),\n\t\t\t\t\tlinked_at: z.union([z.string(), z.date()]).nullable(),\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.optional(),\n\t\troles: z\n\t\t\t.array(\n\t\t\t\tz.object({\n\t\t\t\t\tid: z.number(),\n\t\t\t\t\tname: z.string().nullable().optional(),\n\t\t\t\t\ttranslations: z\n\t\t\t\t\t\t.array(\n\t\t\t\t\t\t\tz.object({\n\t\t\t\t\t\t\t\tname: z.string().nullable(),\n\t\t\t\t\t\t\t\tlocale_code: z.string().nullable(),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.optional(),\n\t\t\t\t\tpermissions: z\n\t\t\t\t\t\t.array(\n\t\t\t\t\t\t\tz.object({\n\t\t\t\t\t\t\t\tpermission: z.string(),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.optional(),\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.optional(),\n\t\ttenants: z\n\t\t\t.array(\n\t\t\t\tz.object({\n\t\t\t\t\ttenant_key: z.string(),\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.optional(),\n\t\tcreated_at: z.union([z.string(), z.date()]).nullable(),\n\t\tupdated_at: z.union([z.string(), z.date()]).nullable(),\n\t});\n\tcolumnFormats = {\n\t\tid: this.dbAdapter.getDataType(\"primary\"),\n\t\tsuper_admin: this.dbAdapter.getDataType(\"boolean\"),\n\t\temail: this.dbAdapter.getDataType(\"text\"),\n\t\tusername: this.dbAdapter.getDataType(\"text\"),\n\t\tfirst_name: this.dbAdapter.getDataType(\"text\"),\n\t\tlast_name: this.dbAdapter.getDataType(\"text\"),\n\t\tpassword: this.dbAdapter.getDataType(\"text\"),\n\t\tsecret: this.dbAdapter.getDataType(\"text\"),\n\t\ttriggered_password_reset: this.dbAdapter.getDataType(\"boolean\"),\n\t\tinvitation_accepted: this.dbAdapter.getDataType(\"boolean\"),\n\t\tis_locked: this.dbAdapter.getDataType(\"boolean\"),\n\t\tis_deleted: this.dbAdapter.getDataType(\"boolean\"),\n\t\tis_deleted_at: this.dbAdapter.getDataType(\"timestamp\"),\n\t\tdeleted_by: this.dbAdapter.getDataType(\"integer\"),\n\t\tprofile_picture_media_id: this.dbAdapter.getDataType(\"integer\"),\n\t\tcreated_at: this.dbAdapter.getDataType(\"timestamp\"),\n\t\tupdated_at: this.dbAdapter.getDataType(\"timestamp\"),\n\t};\n\tqueryConfig = {\n\t\ttableKeys: {\n\t\t\tfilters: {\n\t\t\t\tfirstName: \"lucid_users.first_name\",\n\t\t\t\tlastName: \"lucid_users.last_name\",\n\t\t\t\temail: \"lucid_users.email\",\n\t\t\t\tusername: \"lucid_users.username\",\n\t\t\t\troleIds: \"lucid_user_roles.role_id\",\n\t\t\t\tid: \"lucid_users.id\",\n\t\t\t\tinvitationAccepted: \"lucid_users.invitation_accepted\",\n\t\t\t\tsuperAdmin: \"lucid_users.super_admin\",\n\t\t\t\ttriggerPasswordReset: \"lucid_users.triggered_password_reset\",\n\t\t\t\tisLocked: \"lucid_users.is_locked\",\n\t\t\t\tisDeleted: \"lucid_users.is_deleted\",\n\t\t\t\tdeletedBy: \"lucid_users.deleted_by\",\n\t\t\t\tcreatedAt: \"lucid_users.created_at\",\n\t\t\t\tupdatedAt: \"lucid_users.updated_at\",\n\t\t\t},\n\t\t\tsorts: {\n\t\t\t\tcreatedAt: \"lucid_users.created_at\",\n\t\t\t\tupdatedAt: \"lucid_users.updated_at\",\n\t\t\t\tfirstName: \"lucid_users.first_name\",\n\t\t\t\tlastName: \"lucid_users.last_name\",\n\t\t\t\temail: \"lucid_users.email\",\n\t\t\t\tusername: \"lucid_users.username\",\n\t\t\t\tisLocked: \"lucid_users.is_locked\",\n\t\t\t},\n\t\t},\n\t\toperators: {\n\t\t\tfirstName: \"contains\",\n\t\t\tlastName: \"contains\",\n\t\t\temail: \"contains\",\n\t\t\tusername: \"contains\",\n\t\t},\n\t} as const;\n\n\t// ----------------------------------------\n\t// queries\n\tasync selectAccessTokenUser<V extends boolean = false>(\n\t\tprops: QueryProps<\n\t\t\tV,\n\t\t\t{\n\t\t\t\twhere: QueryBuilderWhere<\"lucid_users\">;\n\t\t\t\ttenantKey?: string | null;\n\t\t\t}\n\t\t>,\n\t) {\n\t\tlet query = this.db.selectFrom(\"lucid_users\").select((eb) => [\n\t\t\t\"id\",\n\t\t\t\"username\",\n\t\t\t\"email\",\n\t\t\t\"super_admin\",\n\t\t\tthis.dbAdapter\n\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\teb\n\t\t\t\t\t\t.selectFrom(\"lucid_user_roles\")\n\t\t\t\t\t\t.innerJoin(\n\t\t\t\t\t\t\t\"lucid_roles\",\n\t\t\t\t\t\t\t\"lucid_roles.id\",\n\t\t\t\t\t\t\t\"lucid_user_roles.role_id\",\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.select((eb) => [\n\t\t\t\t\t\t\t\"lucid_roles.id\",\n\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\teb\n\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_role_translations\")\n\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_role_translations.name\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_role_translations.locale_code\",\n\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_role_translations.role_id\",\n\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_roles.id\",\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.as(\"translations\"),\n\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\teb\n\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_role_permissions\")\n\t\t\t\t\t\t\t\t\t\t.select([\"permission\"])\n\t\t\t\t\t\t\t\t\t\t.whereRef(\"role_id\", \"=\", \"lucid_roles.id\"),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.as(\"permissions\"),\n\t\t\t\t\t\t])\n\t\t\t\t\t\t.whereRef(\"user_id\", \"=\", \"lucid_users.id\")\n\t\t\t\t\t\t.$call((qb) =>\n\t\t\t\t\t\t\tqueryBuilder.tenantScope(qb, {\n\t\t\t\t\t\t\t\ttenantKey: props.tenantKey,\n\t\t\t\t\t\t\t\tcolumn: \"lucid_roles.tenant_key\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.as(\"roles\"),\n\t\t\tthis.dbAdapter\n\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\teb\n\t\t\t\t\t\t.selectFrom(\"lucid_user_tenants\")\n\t\t\t\t\t\t.select([\"lucid_user_tenants.tenant_key\"])\n\t\t\t\t\t\t.whereRef(\"lucid_user_tenants.user_id\", \"=\", \"lucid_users.id\"),\n\t\t\t\t)\n\t\t\t\t.as(\"tenants\"),\n\t\t]);\n\n\t\tquery = queryBuilder.select(query, props.where);\n\n\t\tconst exec = await this.executeQuery(() => query.executeTakeFirst(), {\n\t\t\tmethod: \"selectAccessTokenUser\",\n\t\t});\n\t\tif (exec.response.error) return exec.response;\n\n\t\treturn this.validateResponse(exec, {\n\t\t\t...props.validation,\n\t\t\tmode: \"single\",\n\t\t\tselect: [\"id\", \"username\", \"email\", \"super_admin\", \"roles\", \"tenants\"],\n\t\t});\n\t}\n\tasync selectAuditActorById<V extends boolean = false>(\n\t\tprops: QueryProps<\n\t\t\tV,\n\t\t\t{\n\t\t\t\tid: number;\n\t\t\t\tdefaultLocale: string;\n\t\t\t}\n\t\t>,\n\t) {\n\t\tconst query = this.db\n\t\t\t.selectFrom(\"lucid_users\")\n\t\t\t.select((eb) => [\n\t\t\t\t\"id\",\n\t\t\t\t\"super_admin\",\n\t\t\t\tthis.dbAdapter\n\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\teb\n\t\t\t\t\t\t\t.selectFrom(\"lucid_user_roles\")\n\t\t\t\t\t\t\t.innerJoin(\n\t\t\t\t\t\t\t\t\"lucid_roles\",\n\t\t\t\t\t\t\t\t\"lucid_roles.id\",\n\t\t\t\t\t\t\t\t\"lucid_user_roles.role_id\",\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.leftJoin(\"lucid_role_translations as translation\", (join) =>\n\t\t\t\t\t\t\t\tjoin\n\t\t\t\t\t\t\t\t\t.onRef(\"translation.role_id\", \"=\", \"lucid_roles.id\")\n\t\t\t\t\t\t\t\t\t.on(\"translation.locale_code\", \"=\", props.defaultLocale),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.select([\"lucid_roles.id\", \"translation.name\"])\n\t\t\t\t\t\t\t.whereRef(\"user_id\", \"=\", \"lucid_users.id\")\n\t\t\t\t\t\t\t.orderBy(\"lucid_roles.id\", \"asc\"),\n\t\t\t\t\t)\n\t\t\t\t\t.as(\"roles\"),\n\t\t\t])\n\t\t\t.where(\"id\", \"=\", props.id);\n\n\t\tconst exec = await this.executeQuery(() => query.executeTakeFirst(), {\n\t\t\tmethod: \"selectAuditActorById\",\n\t\t});\n\t\tif (exec.response.error) return exec.response;\n\n\t\treturn this.validateResponse(exec, {\n\t\t\t...props.validation,\n\t\t\tmode: \"single\",\n\t\t\tselect: [\"id\", \"super_admin\", \"roles\"],\n\t\t});\n\t}\n\tasync selectSinglePreset<V extends boolean = false>(\n\t\tprops: QueryProps<\n\t\t\tV,\n\t\t\t{\n\t\t\t\twhere: QueryBuilderWhere<\"lucid_users\">;\n\t\t\t\ttenantKey?: string | null;\n\t\t\t}\n\t\t>,\n\t) {\n\t\tlet query = this.db.selectFrom(\"lucid_users\").select((eb) => [\n\t\t\t\"email\",\n\t\t\t\"first_name\",\n\t\t\t\"last_name\",\n\t\t\t\"id\",\n\t\t\t\"created_at\",\n\t\t\t\"updated_at\",\n\t\t\t\"username\",\n\t\t\t\"super_admin\",\n\t\t\t\"triggered_password_reset\",\n\t\t\t\"invitation_accepted\",\n\t\t\t\"is_locked\",\n\t\t\t\"is_deleted\",\n\t\t\t\"is_deleted_at\",\n\t\t\t\"password\",\n\t\t\tthis.dbAdapter\n\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\teb\n\t\t\t\t\t\t.selectFrom(\"lucid_user_roles\")\n\t\t\t\t\t\t.innerJoin(\n\t\t\t\t\t\t\t\"lucid_roles\",\n\t\t\t\t\t\t\t\"lucid_roles.id\",\n\t\t\t\t\t\t\t\"lucid_user_roles.role_id\",\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.select((eb) => [\n\t\t\t\t\t\t\t\"lucid_roles.id\",\n\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\teb\n\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_role_translations\")\n\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_role_translations.name\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_role_translations.locale_code\",\n\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_role_translations.role_id\",\n\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_roles.id\",\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.as(\"translations\"),\n\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\teb\n\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_role_permissions\")\n\t\t\t\t\t\t\t\t\t\t.select([\"permission\"])\n\t\t\t\t\t\t\t\t\t\t.whereRef(\"role_id\", \"=\", \"lucid_roles.id\"),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.as(\"permissions\"),\n\t\t\t\t\t\t])\n\t\t\t\t\t\t.whereRef(\"user_id\", \"=\", \"lucid_users.id\")\n\t\t\t\t\t\t.$call((qb) =>\n\t\t\t\t\t\t\tqueryBuilder.tenantScope(qb, {\n\t\t\t\t\t\t\t\ttenantKey: props.tenantKey,\n\t\t\t\t\t\t\t\tcolumn: \"lucid_roles.tenant_key\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.as(\"roles\"),\n\t\t\tthis.dbAdapter\n\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\teb\n\t\t\t\t\t\t.selectFrom(\"lucid_user_auth_providers\")\n\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\"lucid_user_auth_providers.id\",\n\t\t\t\t\t\t\t\"lucid_user_auth_providers.provider_key\",\n\t\t\t\t\t\t\t\"lucid_user_auth_providers.provider_user_id\",\n\t\t\t\t\t\t\t\"lucid_user_auth_providers.linked_at\",\n\t\t\t\t\t\t])\n\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\"lucid_user_auth_providers.user_id\",\n\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\"lucid_users.id\",\n\t\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.as(\"auth_providers\"),\n\t\t\tthis.dbAdapter\n\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\teb\n\t\t\t\t\t\t.selectFrom(\"lucid_media\")\n\t\t\t\t\t\t.select((mediaEb) => [\n\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\"lucid_media.key\",\n\t\t\t\t\t\t\t\"lucid_media.origin\",\n\t\t\t\t\t\t\t\"lucid_media.folder_id\",\n\t\t\t\t\t\t\t\"lucid_media.e_tag\",\n\t\t\t\t\t\t\t\"lucid_media.type\",\n\t\t\t\t\t\t\t\"lucid_media.mime_type\",\n\t\t\t\t\t\t\t\"lucid_media.file_extension\",\n\t\t\t\t\t\t\t\"lucid_media.file_name\",\n\t\t\t\t\t\t\t\"lucid_media.file_size\",\n\t\t\t\t\t\t\t\"lucid_media.width\",\n\t\t\t\t\t\t\t\"lucid_media.height\",\n\t\t\t\t\t\t\t\"lucid_media.focal_x\",\n\t\t\t\t\t\t\t\"lucid_media.focal_y\",\n\t\t\t\t\t\t\t\"lucid_media.created_at\",\n\t\t\t\t\t\t\t\"lucid_media.updated_at\",\n\t\t\t\t\t\t\t\"lucid_media.blur_hash\",\n\t\t\t\t\t\t\t\"lucid_media.average_color\",\n\t\t\t\t\t\t\t\"lucid_media.base64\",\n\t\t\t\t\t\t\t\"lucid_media.is_dark\",\n\t\t\t\t\t\t\t\"lucid_media.is_light\",\n\t\t\t\t\t\t\t\"lucid_media.is_deleted\",\n\t\t\t\t\t\t\t\"lucid_media.is_deleted_at\",\n\t\t\t\t\t\t\t\"lucid_media.deleted_by\",\n\t\t\t\t\t\t\t\"lucid_media.public\",\n\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\tmediaEb\n\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media as profile_crop\")\n\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.id\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.key\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.origin\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.type\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.mime_type\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_extension\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_name\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_size\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.width\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.height\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.focal_x\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.focal_y\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_x\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_y\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_width\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_height\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_rotation\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_skew_x\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_skew_y\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.blur_hash\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.average_color\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.base64\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_dark\",\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_light\",\n\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.parent_media_id\",\n\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\tsql.ref<number>(\"lucid_media.id\"),\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t.where(\"profile_crop.relation_type\", \"=\", \"crop\")\n\t\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_deleted\",\n\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\tthis.dbAdapter.getDefault(\"boolean\", \"false\"),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.as(\"crop\"),\n\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\tmediaEb\n\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media_translations\")\n\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.title\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.alt\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.description\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.summary\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.locale_code\",\n\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.media_id\",\n\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.as(\"translations\"),\n\t\t\t\t\t\t])\n\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\"lucid_users.profile_picture_media_id\",\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\"lucid_media.is_deleted\",\n\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\tthis.dbAdapter.getDefault(\"boolean\", \"false\"),\n\t\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.as(\"profile_picture\"),\n\t\t\tthis.dbAdapter\n\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\teb\n\t\t\t\t\t\t.selectFrom(\"lucid_user_tenants\")\n\t\t\t\t\t\t.select([\"lucid_user_tenants.tenant_key\"])\n\t\t\t\t\t\t.whereRef(\"lucid_user_tenants.user_id\", \"=\", \"lucid_users.id\"),\n\t\t\t\t)\n\t\t\t\t.as(\"tenants\"),\n\t\t]);\n\n\t\tquery = queryBuilder.select(query, props.where);\n\t\tquery = this.applyUserTenantScope(query, props.tenantKey);\n\n\t\tconst exec = await this.executeQuery(() => query.executeTakeFirst(), {\n\t\t\tmethod: \"selectSingleById\",\n\t\t});\n\t\tif (exec.response.error) return exec.response;\n\n\t\treturn this.validateResponse(exec, {\n\t\t\t...props.validation,\n\t\t\tmode: \"single\",\n\t\t\tselect: [\n\t\t\t\t\"email\",\n\t\t\t\t\"first_name\",\n\t\t\t\t\"last_name\",\n\t\t\t\t\"id\",\n\t\t\t\t\"created_at\",\n\t\t\t\t\"updated_at\",\n\t\t\t\t\"username\",\n\t\t\t\t\"super_admin\",\n\t\t\t\t\"triggered_password_reset\",\n\t\t\t\t\"invitation_accepted\",\n\t\t\t\t\"is_locked\",\n\t\t\t\t\"password\",\n\t\t\t\t\"roles\",\n\t\t\t\t\"auth_providers\",\n\t\t\t\t\"profile_picture\",\n\t\t\t\t\"tenants\",\n\t\t\t],\n\t\t});\n\t}\n\tasync selectMultipleByIds<V extends boolean = false>(\n\t\tprops: QueryProps<\n\t\t\tV,\n\t\t\t{\n\t\t\t\tids: number[];\n\t\t\t\ttenantKey?: string | null;\n\t\t\t\twhere?: QueryBuilderWhere<\"lucid_users\">;\n\t\t\t}\n\t\t>,\n\t) {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"lucid_users\")\n\t\t\t.select((eb) => [\n\t\t\t\t\"email\",\n\t\t\t\t\"first_name\",\n\t\t\t\t\"last_name\",\n\t\t\t\t\"id\",\n\t\t\t\t\"created_at\",\n\t\t\t\t\"updated_at\",\n\t\t\t\t\"username\",\n\t\t\t\t\"super_admin\",\n\t\t\t\t\"is_locked\",\n\t\t\t\t\"is_deleted\",\n\t\t\t\t\"is_deleted_at\",\n\t\t\t\t\"invitation_accepted\",\n\t\t\t\tthis.dbAdapter\n\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\teb\n\t\t\t\t\t\t\t.selectFrom(\"lucid_media\")\n\t\t\t\t\t\t\t.select((mediaEb) => [\n\t\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\t\"lucid_media.key\",\n\t\t\t\t\t\t\t\t\"lucid_media.origin\",\n\t\t\t\t\t\t\t\t\"lucid_media.folder_id\",\n\t\t\t\t\t\t\t\t\"lucid_media.e_tag\",\n\t\t\t\t\t\t\t\t\"lucid_media.type\",\n\t\t\t\t\t\t\t\t\"lucid_media.mime_type\",\n\t\t\t\t\t\t\t\t\"lucid_media.file_extension\",\n\t\t\t\t\t\t\t\t\"lucid_media.file_name\",\n\t\t\t\t\t\t\t\t\"lucid_media.file_size\",\n\t\t\t\t\t\t\t\t\"lucid_media.width\",\n\t\t\t\t\t\t\t\t\"lucid_media.height\",\n\t\t\t\t\t\t\t\t\"lucid_media.focal_x\",\n\t\t\t\t\t\t\t\t\"lucid_media.focal_y\",\n\t\t\t\t\t\t\t\t\"lucid_media.created_at\",\n\t\t\t\t\t\t\t\t\"lucid_media.updated_at\",\n\t\t\t\t\t\t\t\t\"lucid_media.blur_hash\",\n\t\t\t\t\t\t\t\t\"lucid_media.average_color\",\n\t\t\t\t\t\t\t\t\"lucid_media.base64\",\n\t\t\t\t\t\t\t\t\"lucid_media.is_dark\",\n\t\t\t\t\t\t\t\t\"lucid_media.is_light\",\n\t\t\t\t\t\t\t\t\"lucid_media.is_deleted\",\n\t\t\t\t\t\t\t\t\"lucid_media.is_deleted_at\",\n\t\t\t\t\t\t\t\t\"lucid_media.deleted_by\",\n\t\t\t\t\t\t\t\t\"lucid_media.public\",\n\t\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\t\tmediaEb\n\t\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media as profile_crop\")\n\t\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.key\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.origin\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.type\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.mime_type\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_extension\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_name\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_size\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.width\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.height\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.focal_x\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.focal_y\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_x\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_y\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_width\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_height\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_rotation\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_skew_x\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_skew_y\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.blur_hash\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.average_color\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.base64\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_dark\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_light\",\n\t\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.parent_media_id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\tsql.ref<number>(\"lucid_media.id\"),\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t.where(\"profile_crop.relation_type\", \"=\", \"crop\")\n\t\t\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_deleted\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\tthis.dbAdapter.getDefault(\"boolean\", \"false\"),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.as(\"crop\"),\n\t\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\t\tmediaEb\n\t\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media_translations\")\n\t\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.title\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.alt\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.description\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.summary\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.locale_code\",\n\t\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.media_id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.as(\"translations\"),\n\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\"lucid_users.profile_picture_media_id\",\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\"lucid_media.is_deleted\",\n\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\tthis.dbAdapter.getDefault(\"boolean\", \"false\"),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.as(\"profile_picture\"),\n\t\t\t])\n\t\t\t.where(\"id\", \"in\", props.ids);\n\n\t\tif (props.where !== undefined && props.where.length > 0) {\n\t\t\tquery = queryBuilder.select(query, props.where);\n\t\t}\n\n\t\tquery = this.applyUserTenantScope(query, props.tenantKey);\n\n\t\tconst exec = await this.executeQuery(() => query.execute(), {\n\t\t\tmethod: \"selectMultipleByIds\",\n\t\t});\n\t\tif (exec.response.error) return exec.response;\n\n\t\treturn this.validateResponse(exec, {\n\t\t\t...props.validation,\n\t\t\tmode: \"multiple\",\n\t\t\tselect: [\n\t\t\t\t\"email\",\n\t\t\t\t\"first_name\",\n\t\t\t\t\"last_name\",\n\t\t\t\t\"id\",\n\t\t\t\t\"created_at\",\n\t\t\t\t\"updated_at\",\n\t\t\t\t\"username\",\n\t\t\t\t\"super_admin\",\n\t\t\t\t\"invitation_accepted\",\n\t\t\t\t\"is_locked\",\n\t\t\t\t\"profile_picture\",\n\t\t\t],\n\t\t});\n\t}\n\tasync selectSingleByEmailUsername<\n\t\tK extends keyof Select<LucidUsers>,\n\t\tV extends boolean = false,\n\t>(\n\t\tprops: QueryProps<\n\t\t\tV,\n\t\t\t{\n\t\t\t\tselect: K[];\n\t\t\t\twhere: {\n\t\t\t\t\tusername: string;\n\t\t\t\t\temail: string;\n\t\t\t\t};\n\t\t\t}\n\t\t>,\n\t) {\n\t\tconst query = this.db\n\t\t\t.selectFrom(\"lucid_users\")\n\t\t\t.select(props.select)\n\t\t\t.where((eb) =>\n\t\t\t\teb.or([\n\t\t\t\t\teb(\"username\", \"=\", props.where.username),\n\t\t\t\t\teb(\"email\", \"=\", props.where.email),\n\t\t\t\t]),\n\t\t\t);\n\n\t\tconst exec = await this.executeQuery(\n\t\t\t() =>\n\t\t\t\tquery.executeTakeFirst() as Promise<\n\t\t\t\t\tPick<Select<LucidUsers>, K> | undefined\n\t\t\t\t>,\n\t\t\t{\n\t\t\t\tmethod: \"selectSingleByEmailUsername\",\n\t\t\t},\n\t\t);\n\t\tif (exec.response.error) return exec.response;\n\n\t\treturn this.validateResponse(exec, {\n\t\t\t...props.validation,\n\t\t\tmode: \"single\",\n\t\t\tselect: props.select,\n\t\t});\n\t}\n\tasync selectMultipleFilteredFixed<V extends boolean = false>(\n\t\tprops: QueryProps<\n\t\t\tV,\n\t\t\t{\n\t\t\t\tqueryParams: GetMultipleQueryParams;\n\t\t\t\ttenantKey?: string | null;\n\t\t\t\tincludeTenants?: boolean;\n\t\t\t}\n\t\t>,\n\t) {\n\t\tconst exec = await this.executeQuery(\n\t\t\tasync () => {\n\t\t\t\tconst mainQuery = this.db\n\t\t\t\t\t.selectFrom(\"lucid_users\")\n\t\t\t\t\t.select((eb) => [\n\t\t\t\t\t\t\"lucid_users.email\",\n\t\t\t\t\t\t\"lucid_users.first_name\",\n\t\t\t\t\t\t\"lucid_users.last_name\",\n\t\t\t\t\t\t\"lucid_users.id\",\n\t\t\t\t\t\t\"lucid_users.created_at\",\n\t\t\t\t\t\t\"lucid_users.updated_at\",\n\t\t\t\t\t\t\"lucid_users.username\",\n\t\t\t\t\t\t\"lucid_users.super_admin\",\n\t\t\t\t\t\t\"lucid_users.password\",\n\t\t\t\t\t\t\"lucid_users.triggered_password_reset\",\n\t\t\t\t\t\t\"lucid_users.is_locked\",\n\t\t\t\t\t\t\"lucid_users.is_deleted\",\n\t\t\t\t\t\t\"lucid_users.is_deleted_at\",\n\t\t\t\t\t\t\"lucid_users.invitation_accepted\",\n\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\teb\n\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_user_roles\")\n\t\t\t\t\t\t\t\t\t.innerJoin(\n\t\t\t\t\t\t\t\t\t\t\"lucid_roles\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_roles.id\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_user_roles.role_id\",\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.select((eb) => [\n\t\t\t\t\t\t\t\t\t\t\"lucid_roles.id\",\n\t\t\t\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\t\t\t\teb\n\t\t\t\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_role_translations\")\n\t\t\t\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_role_translations.name\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_role_translations.locale_code\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_role_translations.role_id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_roles.id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t.as(\"translations\"),\n\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t.whereRef(\"user_id\", \"=\", \"lucid_users.id\")\n\t\t\t\t\t\t\t\t\t.$call((qb) =>\n\t\t\t\t\t\t\t\t\t\tqueryBuilder.tenantScope(qb, {\n\t\t\t\t\t\t\t\t\t\t\ttenantKey: props.tenantKey,\n\t\t\t\t\t\t\t\t\t\t\tcolumn: \"lucid_roles.tenant_key\",\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.as(\"roles\"),\n\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\teb\n\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media\")\n\t\t\t\t\t\t\t\t\t.select((mediaEb) => [\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.key\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.origin\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.folder_id\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.e_tag\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.type\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.mime_type\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.file_extension\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.file_name\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.file_size\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.width\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.height\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.focal_x\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.focal_y\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.created_at\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.updated_at\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.blur_hash\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.average_color\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.base64\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.is_dark\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.is_light\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.is_deleted\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.is_deleted_at\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.deleted_by\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.public\",\n\t\t\t\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\t\t\t\tmediaEb\n\t\t\t\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media as profile_crop\")\n\t\t\t\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.key\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.origin\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.type\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.mime_type\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_extension\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_name\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_size\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.width\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.height\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.focal_x\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.focal_y\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_x\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_y\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_width\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_height\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_rotation\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_skew_x\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_skew_y\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.blur_hash\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.average_color\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.base64\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_dark\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_light\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.parent_media_id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsql.ref<number>(\"lucid_media.id\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t\t.where(\"profile_crop.relation_type\", \"=\", \"crop\")\n\t\t\t\t\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_deleted\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.dbAdapter.getDefault(\"boolean\", \"false\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t.as(\"crop\"),\n\t\t\t\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\t\t\t\tmediaEb\n\t\t\t\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media_translations\")\n\t\t\t\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.title\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.alt\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.description\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.summary\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.locale_code\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.media_id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t.as(\"translations\"),\n\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\"lucid_users.profile_picture_media_id\",\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\"lucid_media.is_deleted\",\n\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\tthis.dbAdapter.getDefault(\"boolean\", \"false\"),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.as(\"profile_picture\"),\n\t\t\t\t\t])\n\t\t\t\t\t.$if(props.includeTenants === true, (qb) =>\n\t\t\t\t\t\tqb.select((eb) => [\n\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\teb\n\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_user_tenants\")\n\t\t\t\t\t\t\t\t\t\t.select([\"lucid_user_tenants.tenant_key\"])\n\t\t\t\t\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_user_tenants.user_id\",\n\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_users.id\",\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.as(\"tenants\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t)\n\t\t\t\t\t.leftJoin(\"lucid_user_roles\", (join) =>\n\t\t\t\t\t\tjoin.onRef(\"lucid_user_roles.user_id\", \"=\", \"lucid_users.id\"),\n\t\t\t\t\t)\n\t\t\t\t\t.groupBy(\"lucid_users.id\")\n\t\t\t\t\t.$call((qb) => this.applyUserTenantScope(qb, props.tenantKey));\n\n\t\t\t\tconst countQuery = this.db\n\t\t\t\t\t.selectFrom(\"lucid_users\")\n\t\t\t\t\t.select(sql`count(distinct lucid_users.id)`.as(\"count\"))\n\t\t\t\t\t.leftJoin(\"lucid_user_roles\", (join) =>\n\t\t\t\t\t\tjoin.onRef(\"lucid_user_roles.user_id\", \"=\", \"lucid_users.id\"),\n\t\t\t\t\t)\n\t\t\t\t\t.$call((qb) => this.applyUserTenantScope(qb, props.tenantKey));\n\n\t\t\t\tconst { main, count } = queryBuilder.main(\n\t\t\t\t\t{\n\t\t\t\t\t\tmain: mainQuery,\n\t\t\t\t\t\tcount: countQuery,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tqueryParams: props.queryParams,\n\t\t\t\t\t\tdatabase: this.dbAdapter.config,\n\t\t\t\t\t\tmeta: this.queryConfig,\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tconst [mainResult, countResult] = await Promise.all([\n\t\t\t\t\tmain.execute(),\n\t\t\t\t\tcount?.executeTakeFirst() as Promise<{ count: string } | undefined>,\n\t\t\t\t]);\n\n\t\t\t\treturn [mainResult, countResult] as const;\n\t\t\t},\n\t\t\t{\n\t\t\t\tmethod: \"selectMultipleFilteredFixed\",\n\t\t\t},\n\t\t);\n\t\tif (exec.response.error) return exec.response;\n\n\t\treturn this.validateResponse(exec, {\n\t\t\t...props.validation,\n\t\t\tmode: \"multiple-count\",\n\t\t\tselect: [\n\t\t\t\t\"email\",\n\t\t\t\t\"first_name\",\n\t\t\t\t\"last_name\",\n\t\t\t\t\"id\",\n\t\t\t\t\"created_at\",\n\t\t\t\t\"updated_at\",\n\t\t\t\t\"username\",\n\t\t\t\t\"super_admin\",\n\t\t\t\t\"password\",\n\t\t\t\t\"triggered_password_reset\",\n\t\t\t\t\"is_locked\",\n\t\t\t\t\"roles\",\n\t\t\t\t\"invitation_accepted\",\n\t\t\t\t\"profile_picture\",\n\t\t\t\t...(props.includeTenants === true ? [\"tenants\"] : []),\n\t\t\t],\n\t\t});\n\t}\n\n\tasync selectMultiplePublishReviewers<V extends boolean = false>(\n\t\tprops: QueryProps<\n\t\t\tV,\n\t\t\t{\n\t\t\t\tpermission: string;\n\t\t\t\ttenantKey?: string | null;\n\t\t\t}\n\t\t>,\n\t) {\n\t\tconst exec = await this.executeQuery(\n\t\t\t() => {\n\t\t\t\tconst superAdminValue = this.dbAdapter.getDefault(\"boolean\", \"true\");\n\t\t\t\tconst deletedValue = this.dbAdapter.getDefault(\"boolean\", \"false\");\n\t\t\t\tconst lockedValue = this.dbAdapter.getDefault(\"boolean\", \"false\");\n\n\t\t\t\treturn this.applyUserTenantScope(\n\t\t\t\t\tthis.db\n\t\t\t\t\t\t.selectFrom(\"lucid_users\")\n\t\t\t\t\t\t.select((eb) => [\n\t\t\t\t\t\t\t\"id\",\n\t\t\t\t\t\t\t\"email\",\n\t\t\t\t\t\t\t\"username\",\n\t\t\t\t\t\t\t\"first_name as firstName\",\n\t\t\t\t\t\t\t\"last_name as lastName\",\n\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\teb\n\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media\")\n\t\t\t\t\t\t\t\t\t\t.select((mediaEb) => [\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.key\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.origin\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.type\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.mime_type\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.file_extension\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.file_name\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.file_size\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.width\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.height\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.focal_x\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.focal_y\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.blur_hash\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.average_color\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.base64\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.is_dark\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.is_light\",\n\t\t\t\t\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\t\t\t\t\tmediaEb\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media as profile_crop\")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.key\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.origin\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.type\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.mime_type\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_extension\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_name\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_size\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.width\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.height\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.focal_x\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.focal_y\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_x\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_y\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_width\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_height\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_rotation\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_skew_x\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_skew_y\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.blur_hash\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.average_color\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.base64\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_dark\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_light\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.parent_media_id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsql.ref<number>(\"lucid_media.id\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.where(\"profile_crop.relation_type\", \"=\", \"crop\")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_deleted\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.dbAdapter.getDefault(\"boolean\", \"false\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t.as(\"crop\"),\n\t\t\t\t\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\t\t\t\t\tmediaEb\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media_translations\")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.title\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.alt\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.description\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.summary\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.locale_code\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.media_id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t.as(\"translations\"),\n\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_users.profile_picture_media_id\",\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.is_deleted\",\n\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\tthis.dbAdapter.getDefault(\"boolean\", \"false\"),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.as(\"profile_picture\"),\n\t\t\t\t\t\t])\n\t\t\t\t\t\t.where(\"is_deleted\", \"=\", deletedValue)\n\t\t\t\t\t\t.where(\"is_locked\", \"=\", lockedValue)\n\t\t\t\t\t\t.where(({ or, eb, exists, selectFrom }) =>\n\t\t\t\t\t\t\tor([\n\t\t\t\t\t\t\t\teb(\"super_admin\", \"=\", superAdminValue),\n\t\t\t\t\t\t\t\texists(\n\t\t\t\t\t\t\t\t\tqueryBuilder.tenantScope(\n\t\t\t\t\t\t\t\t\t\tselectFrom(\"lucid_user_roles\")\n\t\t\t\t\t\t\t\t\t\t\t.innerJoin(\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_roles\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_roles.id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_user_roles.role_id\",\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t.innerJoin(\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_role_permissions\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_role_permissions.role_id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_roles.id\",\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t.select(sql.lit(1).as(\"one\"))\n\t\t\t\t\t\t\t\t\t\t\t.whereRef(\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_user_roles.user_id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_users.id\",\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_role_permissions.permission\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\tprops.permission,\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\ttenantKey: props.tenantKey,\n\t\t\t\t\t\t\t\t\t\t\tcolumn: \"lucid_roles.tenant_key\",\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.orderBy(\"email\", \"asc\"),\n\t\t\t\t\tprops.tenantKey,\n\t\t\t\t).execute();\n\t\t\t},\n\t\t\t{\n\t\t\t\tmethod: \"selectMultiplePublishReviewers\",\n\t\t\t},\n\t\t);\n\t\tif (exec.response.error) return exec.response;\n\n\t\treturn this.validateResponse(exec, {\n\t\t\t...props.validation,\n\t\t\tmode: \"multiple\",\n\t\t});\n\t}\n\n\tasync selectMultipleWithPermission<V extends boolean = false>(\n\t\tprops: QueryProps<\n\t\t\tV,\n\t\t\t{\n\t\t\t\tpermission: string;\n\t\t\t\ttenantKey?: string | null;\n\t\t\t}\n\t\t>,\n\t) {\n\t\tconst exec = await this.executeQuery(\n\t\t\t() => {\n\t\t\t\tconst superAdminValue = this.dbAdapter.getDefault(\"boolean\", \"true\");\n\t\t\t\tconst deletedValue = this.dbAdapter.getDefault(\"boolean\", \"false\");\n\t\t\t\tconst lockedValue = this.dbAdapter.getDefault(\"boolean\", \"false\");\n\n\t\t\t\treturn this.applyUserTenantScope(\n\t\t\t\t\tthis.db\n\t\t\t\t\t\t.selectFrom(\"lucid_users\")\n\t\t\t\t\t\t.select((eb) => [\n\t\t\t\t\t\t\t\"id\",\n\t\t\t\t\t\t\t\"email\",\n\t\t\t\t\t\t\t\"username\",\n\t\t\t\t\t\t\t\"first_name as firstName\",\n\t\t\t\t\t\t\t\"last_name as lastName\",\n\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\teb\n\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media\")\n\t\t\t\t\t\t\t\t\t\t.select((mediaEb) => [\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.id\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.key\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.origin\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.type\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.mime_type\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.file_extension\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.file_name\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.file_size\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.width\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.height\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.focal_x\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.focal_y\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.blur_hash\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.average_color\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.base64\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.is_dark\",\n\t\t\t\t\t\t\t\t\t\t\t\"lucid_media.is_light\",\n\t\t\t\t\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\t\t\t\t\tmediaEb\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media as profile_crop\")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.key\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.origin\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.type\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.mime_type\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_extension\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_name\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.file_size\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.width\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.height\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.focal_x\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.focal_y\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_x\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_y\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_width\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_height\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_rotation\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_skew_x\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.crop_skew_y\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.blur_hash\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.average_color\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.base64\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_dark\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_light\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.parent_media_id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsql.ref<number>(\"lucid_media.id\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.where(\"profile_crop.relation_type\", \"=\", \"crop\")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.where(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"profile_crop.is_deleted\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"=\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.dbAdapter.getDefault(\"boolean\", \"false\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t.as(\"crop\"),\n\t\t\t\t\t\t\t\t\t\t\tthis.dbAdapter\n\t\t\t\t\t\t\t\t\t\t\t\t.jsonArrayFrom(\n\t\t\t\t\t\t\t\t\t\t\t\t\tmediaEb\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.selectFrom(\"lucid_media_translations\")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.select([\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"lucid_media_translations.title\",\n\t\