Redone
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
tenants
|
||||
} from "../../db/schema"
|
||||
|
||||
import { eq } from "drizzle-orm"
|
||||
import {and, eq, inArray} from "drizzle-orm"
|
||||
|
||||
|
||||
export default async function tenantRoutes(server: FastifyInstance) {
|
||||
@@ -48,12 +48,10 @@ export default async function tenantRoutes(server: FastifyInstance) {
|
||||
const membership = await server.db
|
||||
.select()
|
||||
.from(authTenantUsers)
|
||||
.where(
|
||||
eq(authTenantUsers.user_id, req.user.user_id)
|
||||
)
|
||||
.where(
|
||||
eq(authTenantUsers.tenant_id, Number(tenant_id))
|
||||
)
|
||||
.where(and(
|
||||
eq(authTenantUsers.user_id, req.user.user_id),
|
||||
eq(authTenantUsers.tenant_id, Number(tenant_id))
|
||||
))
|
||||
|
||||
if (!membership.length) {
|
||||
return reply.code(403).send({ error: "Not a member of this tenant" })
|
||||
@@ -120,8 +118,11 @@ export default async function tenantRoutes(server: FastifyInstance) {
|
||||
const profiles = await server.db
|
||||
.select()
|
||||
.from(authProfiles)
|
||||
.where(eq(authProfiles.tenant_id, tenantId))
|
||||
.where(inArray(authProfiles.user_id, userIds))
|
||||
.where(
|
||||
and(
|
||||
eq(authProfiles.tenant_id, tenantId),
|
||||
inArray(authProfiles.user_id, userIds)
|
||||
))
|
||||
|
||||
const combined = users.map(u => {
|
||||
const profile = profiles.find(p => p.user_id === u.id)
|
||||
@@ -192,6 +193,7 @@ export default async function tenantRoutes(server: FastifyInstance) {
|
||||
if (!current) return reply.code(404).send({ error: "Tenant not found" })
|
||||
|
||||
const updatedRanges = {
|
||||
//@ts-ignore
|
||||
...current.numberRanges,
|
||||
[numberrange]: numberRange
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user