refactor: update validation

This commit is contained in:
Mauricio Siu
2025-02-15 13:14:48 -06:00
parent 55abac3f2f
commit 6ec60b6bab
2 changed files with 213 additions and 211 deletions

View File

@@ -59,6 +59,14 @@ export const validateRequest = async (request: IncomingMessage) => {
}), }),
}); });
if (!session?.session || !session.user) {
return {
session: null,
user: null,
};
}
if (session?.user) {
if (session?.user.role === "user") { if (session?.user.role === "user") {
const owner = await db.query.member.findFirst({ const owner = await db.query.member.findFirst({
where: eq(schema.member.userId, session.user.id), where: eq(schema.member.userId, session.user.id),
@@ -71,14 +79,8 @@ export const validateRequest = async (request: IncomingMessage) => {
session.user.ownerId = owner.organization.ownerId; session.user.ownerId = owner.organization.ownerId;
} }
} else { } else {
session.user.ownerId = session?.user.id; session.user.ownerId = session?.user?.id || "";
} }
if (!session?.session || !session.user) {
return {
session: null,
user: null,
};
} }
return session; return session;

View File

@@ -14,7 +14,7 @@ import { IS_CLOUD } from "../constants";
export type Admin = typeof users_temp.$inferSelect; export type Admin = typeof users_temp.$inferSelect;
export const createInvitation = async ( export const createInvitation = async (
input: typeof apiCreateUserInvitation._type, input: typeof apiCreateUserInvitation._type,
adminId: string, adminId: string
) => { ) => {
await db.transaction(async (tx) => { await db.transaction(async (tx) => {
const result = await tx const result = await tx
@@ -79,7 +79,7 @@ export const updateUser = async (userId: string, userData: Partial<Admin>) => {
export const updateAdminById = async ( export const updateAdminById = async (
adminId: string, adminId: string,
adminData: Partial<Admin>, adminData: Partial<Admin>
) => { ) => {
const admin = await db const admin = await db
.update(admins) .update(admins)
@@ -101,8 +101,8 @@ export const findAdminById = async (userId: string) => {
}; };
export const isAdminPresent = async () => { export const isAdminPresent = async () => {
const admin = await db.query.user.findFirst({ const admin = await db.query.users_temp.findFirst({
where: eq(user.role, "admin"), where: eq(users_temp.role, "admin"),
}); });
if (!admin) { if (!admin) {
return false; return false;