Services rewrite

This commit is contained in:
Emily
2024-09-18 17:43:04 +02:00
parent fa5a37ece2
commit 0be3dbecbf
40 changed files with 488146 additions and 125 deletions

View File

@@ -4,19 +4,22 @@ import { LITLYX_PROJECT_ID } from '@data/LITLYX'
import { hasAccessToProject } from "./utils/hasAccessToProject";
export async function getUserProjectFromId(project_id: string, user: AuthContext | undefined, allowGuest: boolean = true) {
if (project_id == LITLYX_PROJECT_ID) {
const project = await ProjectModel.findOne({ _id: project_id });
return project;
} else {
if (!user?.logged) return;
if (!project_id) return;
const project = await ProjectModel.findById(project_id);
if (!project) return;
const [hasAccess, role] = await hasAccessToProject(user.id, project_id, project);
if (!hasAccess) return;
if (role === 'GUEST' && !allowGuest) return false;
return project;
if (!project_id) return;
if (project_id === LITLYX_PROJECT_ID) {
return await ProjectModel.findOne({ _id: project_id });
}
if (!user || !user.logged) return;
const project = await ProjectModel.findById(project_id);
if (!project) return;
const [hasAccess, role] = await hasAccessToProject(user.id, project_id, project);
if (!hasAccess) return;
if (role === 'GUEST' && !allowGuest) return false;
return project;
}