New version API collaboration and tested for Project

This commit is contained in:
2025-05-29 19:11:26 +05:30
parent 72faf6782e
commit 2bb3814d75
25 changed files with 526 additions and 88 deletions

View File

@@ -22,6 +22,7 @@ export const existingUser = async (userId: string, organization: string) => {
}
const userData = await AuthModel(organization).findOne({
_id: userId,
isArchive: false,
});
return userData;
};
@@ -90,11 +91,11 @@ export const existingProjectById = async (
};
export const existingProjectByIdWithoutUser = async (
projectId: string,
organization: string,
organization: string
) => {
const projectData = await projectModel(organization).findOne({
_id: projectId,
isArchive: false,
});
return projectData;
};
};

View File

@@ -2,18 +2,14 @@ import projectModel from "../../model/project/project-model.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
interface IOrg {
organization: string;
userId: string;
}
interface IRestore {
projectId: string;
organization: string;
userId: string;
}
export const TrashDatas = async (data: IOrg) => {
try {
const { organization, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const { organization } = data;
const TrashLists = await projectModel(organization).find({
isArchive: true,
isDeleted: false,
@@ -51,9 +47,7 @@ export const TrashDatas = async (data: IOrg) => {
};
export const RestoreTrashData = async (data: IRestore) => {
try {
const { projectId, organization, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const { projectId, organization } = data;
const findProject = await projectModel(organization).findOne({
_id: projectId,
isArchive: true,
@@ -70,25 +64,4 @@ export const RestoreTrashData = async (data: IRestore) => {
return { status: error };
}
};
export const TrashDelete = async (data: IRestore) => {
try {
const { projectId, organization, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findProject = await projectModel(organization).findOne({
_id: projectId,
isArchive: true,
});
if (!findProject) return { status: "Project not found" };
const DeleteTrashData = await projectModel(organization).findOneAndUpdate(
{ _id: projectId, isArchive: true },
{ isDelete: true },
{ new: true }
);
if (!DeleteTrashData)
return { status: "Project Trash Delete unsuccessfull" };
return { status: "Trash Project Restored successfully" };
} catch (error) {
return { status: error };
}
};

View File

@@ -16,6 +16,14 @@ interface CreateProjectInput {
sharedUsers?: string[];
organization: string;
}
interface IProjectDuplicate {
projectName: string;
projectUuid: string;
userId: string; // user ID
thumbnail?: string;
sharedUsers?: string[];
organization: string;
}
interface updateProjectInput {
projectName: string;
projectId: string;
@@ -30,6 +38,11 @@ interface GetProjectsInterface {
organization: string;
role: string;
}
interface ProjectDelInterface {
projectId: string;
userId: string;
organization: string;
}
interface ProjectInterface {
projectId: string;
userId: string;
@@ -44,6 +57,7 @@ export const createProject = async (data: CreateProjectInput) => {
try {
const { thumbnail, sharedUsers, projectUuid, userId, organization } = data;
const userExisting = await existingUser(userId, organization);
console.log("userExisting: ", userExisting);
if (!userExisting) {
return {
status: "user_not_found",
@@ -115,16 +129,18 @@ export const GetAllProjects = async (data: GetProjectsInterface) => {
}
};
export const DeleteProject = async (data: ProjectInterface) => {
export const DeleteProject = async (data: ProjectDelInterface) => {
try {
const { projectId, organization, userId, role } = data;
const { projectId, organization, userId } = data;
const ExistingUser = await existingUser(userId, organization);
if (!ExistingUser) return { status: "User not found" };
let filter = { _id: projectId, isArchive: false } as RoleFilter;
// if (role === "User") {
// filter.createdBy = userId;
// }
const existingProject = await projectModel(organization).findOne(filter);
console.log("existingProject: ", existingProject);
if (!existingProject) return { status: "Project not found" };
const updateProject = await projectModel(organization).findOneAndUpdate(
filter,
@@ -162,6 +178,63 @@ export const updateProject = async (data: updateProjectInput) => {
return { status: error };
}
};
export const DuplicateProject = async (data: IProjectDuplicate) => {
try {
const {
thumbnail,
sharedUsers,
projectUuid,
userId,
organization,
projectName,
} = data;
const userExisting = await existingUser(userId, organization);
if (!userExisting) {
return {
status: "user_not_found",
};
}
const projectExisting = await existingProject(
projectUuid,
organization,
userId
);
if (projectExisting) {
return {
status: "project_exists",
project: projectExisting,
};
}
const project = await projectModel(organization).create({
projectName: projectName,
projectUuid: projectUuid,
createdBy: userId,
thumbnail: thumbnail,
sharedUsers: sharedUsers || [],
isArchive: false,
});
const versionData = await previousVersion(project._id, organization);
if (!versionData || versionData.length === 0) {
const newVersion = await versionModel(organization).create({
projectId: project._id,
createdBy: userId,
version: 0.0,
});
await projectModel(organization).findByIdAndUpdate(
{ _id: project._id, isArchive: false },
{ total_versions: `v-${newVersion.version.toFixed(2)}` }
);
}
return {
status: "Success",
project: project,
};
} catch (error: unknown) {
return { status: error };
}
};
const maxLength: number = 6;
export const viewProject = async (data: ProjectInterface) => {
try {
@@ -193,8 +266,8 @@ export const viewProject = async (data: ProjectInterface) => {
newArr.pop();
}
}
await UsersDataModel(organization).updateOne(
{ _id: userId },
const datas = await UsersDataModel(organization).findOneAndUpdate(
{ userId: userId, isArchive: false },
{ recentlyViewed: newArr },
{ new: true }
);

View File

@@ -1,7 +1,6 @@
import projectModel from "../../V1Models/Project/project-model.ts";
import userModel from "../../model/user-Model.ts";
import UsersDataModel from "../../V1Models/Auth/user.ts";
import { existingUser } from "../helpers/ProjecthelperFn.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
interface IRecentData {
organization: string;
@@ -29,7 +28,6 @@ export const RecentlyAdded = async (data: IRecentData) => {
try {
const { userId, organization, role } = data;
const userExisting = await existingUser(userId, organization);
console.log('userExisting: ', userExisting);
if (!userExisting) return { status: "User not found" };
const userRecentData = await UsersDataModel(organization)
.findOne({ userId: userId, isArchive: false })
@@ -43,16 +41,19 @@ export const RecentlyAdded = async (data: IRecentData) => {
// filter.createdBy = userId;
// }
const populatedProjects = userRecentData.recentlyViewed as IProject[];
console.log("populatedProjects: ", populatedProjects);
const RecentDatas = await Promise.all(
populatedProjects.map(async (project) => {
const projectExisting = await projectModel(organization)
.findOne(filter)
.findOne({ _id: project._id, isArchive: false })
.select("_id projectName createdBy thumbnail createdAt isViewed");
return projectExisting;
})
);
console.log("RecentDatas: ", RecentDatas);
const filteredProjects = RecentDatas.filter(Boolean);
console.log("filteredProjects: ", filteredProjects);
return { status: "Success", data: filteredProjects };
} catch (error) {
return { status: error };

View File

@@ -1,4 +1,5 @@
import projectModel from "../../V1Models/Project/project-model.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
interface IOrg {
organization: string;
role: string;
@@ -21,6 +22,8 @@ export const TrashDatas = async (data: IOrg) => {
// if (role === "User") {
// filter.createdBy = userId;
// }
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const TrashLists = await projectModel(organization).find(filter);
if (!TrashLists) return { staus: "Trash is Empty" };
const TrashDocs: any[] = [];
@@ -56,6 +59,8 @@ export const TrashDatas = async (data: IOrg) => {
export const RestoreTrashData = async (data: IRestore) => {
try {
const { projectId, organization, role, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
let filter = { isArchive: true, _id: projectId } as RoleFilter;
// if (role === "User") {
// filter.createdBy = userId;
@@ -73,3 +78,24 @@ export const RestoreTrashData = async (data: IRestore) => {
return { status: error };
}
};
export const TrashDelete = async (data: IRestore) => {
try {
const { projectId, organization, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findProject = await projectModel(organization).findOne({
_id: projectId,
isArchive: true,
});
if (!findProject) return { status: "Project not found" };
const DeleteTrashData = await projectModel(organization).findOneAndUpdate(
{ _id: projectId, isArchive: true, isDeleted: false },
{ isDeleted: true },
{ new: true }
);
if (!DeleteTrashData) return { status: "Project Already Deleted" };
return { status: "Trash Project Delete successfully" };
} catch (error) {
return { status: error };
}
};

View File

@@ -1,6 +1,9 @@
import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
import {
existingProjectById,
existingUser,
} from "../helpers/v1projecthelperFns.ts";
interface IResult {
status: string;
@@ -75,6 +78,12 @@ export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
const { organization, widget, zoneId, index, projectId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -163,6 +172,12 @@ export const DelFloat = async (data: IDelFloat): Promise<IResult> => {
const { organization, floatWidgetID, zoneId, projectId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -210,6 +225,12 @@ export const DuplicateFloat = async (
const { organization, widget, zoneId, index, projectId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -312,6 +333,12 @@ export const GetFloatWidget = async (data: IGetZoneFloat): Promise<IResult> => {
const { organization, zoneId, projectId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -361,6 +388,7 @@ export const SingleFloatWidget = async (
const { organization, floatWidgetID, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const widgetData = await floatWidgetModel(organization)
.findOne({
floatWidgetID: floatWidgetID,

View File

@@ -1,7 +1,10 @@
import panelModel from "../../V1Models/Vizualization/panelmodel.ts";
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
import {
existingProjectById,
existingUser,
} from "../helpers/v1projecthelperFns.ts";
interface IResult {
status: string;
data?: object;
@@ -32,6 +35,12 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
const { organization, zoneId, panelOrder, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -97,6 +106,12 @@ export const DelPanel = async (data: IPanel): Promise<IResult> => {
const { organization, zoneId, panelName, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -156,6 +171,12 @@ export const ClearPanel = async (data: IPanel): Promise<IResult> => {
const { organization, zoneId, panelName, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -219,6 +240,12 @@ export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
const { organization, zoneId, lockedPanel, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -267,6 +294,8 @@ const getZoneAndPanelData = async (
projectId: string
) => {
try {
const existingZone = await zoneModel(organization)
.findOne({
zoneId: zoneId,

View File

@@ -3,7 +3,10 @@ import panelModel from "../../V1Models/Vizualization/panelmodel.ts";
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
import {
existingProjectById,
existingUser,
} from "../helpers/v1projecthelperFns.ts";
interface IResult {
status: string;
data?: object;
@@ -45,6 +48,12 @@ export const AddTemplate = async (data: IAddTemplate): Promise<IResult> => {
const { organization, template, projectId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingTemplate = await templateModel(organization).findOne({
templateID: template.id,
isArchive: false,
@@ -96,6 +105,12 @@ export const AddTemplateToZone = async (
const { organization, templateID, projectId, zoneId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -238,6 +253,12 @@ export const TemplateDelete = async (data: ITemplate): Promise<IResult> => {
const { templateID, projectId, userId, organization } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingTemplate = await templateModel(organization).findOne({
templateID: templateID,
isArchive: false,
@@ -275,6 +296,12 @@ export const GetAllTemplates = async (data: IGetTemplate): Promise<IResult> => {
const { organization, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const templateDatas = await templateModel(organization)
.find({ projectId: projectId, isArchive: false })
.select("-_id -__v -isArchive -createdAt -updatedAt");

View File

@@ -1,6 +1,9 @@
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
import widget3dModel from "../../V1Models/Vizualization/3dwidget.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
import {
existingProjectById,
existingUser,
} from "../helpers/v1projecthelperFns.ts";
interface IResult {
status: string;
data?: object;
@@ -47,6 +50,12 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
const { organization, widget, userId, zoneId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -120,6 +129,13 @@ export const Update3Dwidget = async (data: IWidgetUpdate): Promise<IResult> => {
data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -183,6 +199,12 @@ export const Delete3Dwidget = async (
const { organization, id, userId, zoneId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -238,6 +260,12 @@ export const Get3Dwidget = async (data: I3dWidgetGet): Promise<IResult> => {
const { organization, userId, zoneId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,