mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: update validation
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user