Merge branch 'branch-v2' into branch-1

This commit is contained in:
2025-05-17 10:13:58 +05:30
12 changed files with 353 additions and 133 deletions

View File

@@ -63,7 +63,6 @@ export const generateUntitledProjectName = async (
for (const proj of projects) {
const match = proj.projectName.match(/^Untitled(?:\s?(\d+))?$/);
console.log("match: ", match);
if (match) {
const num = match[1] ? parseInt(match[1], 10) : 0;
usedNumbers.add(num);

View File

@@ -0,0 +1,82 @@
import projectModel from "../../model/project/project-model.ts";
import userModel from "../../model/user-Model.ts";
import { existingUser } from "../helpers/ProjecthelperFn.ts";
interface IRecentData {
organization: string;
userId: string;
}
interface IProject {
_id: string;
projectName: string;
createdBy: string;
thumbnail?: string;
createdAt: Date;
isViewed?: number;
}
interface searchProjectInterface {
searchName: string;
userId: string;
organization: string;
}
export const RecentlyAdded = async (data: IRecentData) => {
try {
const { userId, organization } = data;
const userExisting = await existingUser(userId, organization);
if (!userExisting) return { status: "User not found" };
const userRecentData = await userModel(organization)
.findOne({ _id: userId })
.populate({
path: "recentlyViewed",
model: projectModel(organization),
select: "_id",
});
const populatedProjects = userRecentData.recentlyViewed as IProject[];
const RecentDatas = await Promise.all(
populatedProjects.map(async (project) => {
const projectExisting = await projectModel(organization)
.findOne({
_id: project._id,
isArchive: false,
})
.select("_id projectName createdBy thumbnail createdAt isViewed");
return projectExisting;
})
);
const filteredProjects = RecentDatas.filter(Boolean);
return { status: "Success", data: filteredProjects };
} catch (error) {
return { status: error };
}
};
export const searchProject = async (data: searchProjectInterface) => {
try {
const { userId, organization, searchName } = data;
const userExisting = await existingUser(userId, organization);
if (!userExisting) return { status: "User not found" };
const findprojectName = await projectModel(organization).find({
projectName: { $regex: `${searchName}`, $options: "i" }, // 'i' makes it case-insensitive
isArchive: false,
})
if (!findprojectName||findprojectName.length===0) return { status: "Project not found" }
return { status: "Success", data: findprojectName };
} catch (error: unknown) {
return { status: error };
}
}
export const searchTrashProject = async (data: searchProjectInterface) => {
try {
const { userId, organization, searchName } = data;
const userExisting = await existingUser(userId, organization);
if (!userExisting) return { status: "User not found" };
const findprojectName = await projectModel(organization).find({
projectName: { $regex: `${searchName}`, $options: "i" },
isArchive: true,isDeleted:false
})
if (!findprojectName||findprojectName.length===0) return { status: "Project not found" }
return { status: "Success", data: findprojectName };
} catch (error: unknown) {
return { status: error };
}
}

View File

@@ -1,34 +0,0 @@
import projectModel from "../../model/project/project-model.ts";
import userModel from "../../model/user-Model.ts";
import { existingUser } from "../helpers/ProjecthelperFn.ts";
interface IRecentData {
organization: string;
userId: string;
}
export const RecentlyAdded = async (data: IRecentData) => {
try {
const { userId, organization } = data;
const userExisting = await existingUser(userId, organization);
if (!userExisting) return { status: "User not found" };
const userRecentData = await userModel(organization)
.findOne({ _id: userId })
.populate({
path: "recentlyViewed",
model: projectModel(organization),
select: "_id projectName createdBy thumbnail createdAt isViewed",
});
let RecentDatas = [];
userRecentData.recentlyViewed.map(async (project: object) => {
console.log("project: ", typeof project);
const projectExisting = await projectModel(organization).findOne({
_id: project,
isArchive: false,
});
});
if (!userRecentData) return { status: "Datas were empty" };
return { status: "Success", data: userRecentData.recentlyViewed };
} catch (error) {
return { status: error };
}
};

View File

@@ -33,6 +33,7 @@ interface ProjectInterface {
userId: string;
organization: string;
}
export const createProject = async (data: CreateProjectInput) => {
try {
const { userId, thumbnail, sharedUsers, organization, projectUuid } = data;
@@ -41,7 +42,7 @@ export const createProject = async (data: CreateProjectInput) => {
return {
status: "user_not_found",
};
}
}
const projectExisting = await existingProject(
projectUuid,
organization,
@@ -122,7 +123,7 @@ export const DeleteProject = async (data: ProjectInterface) => {
{ isArchive: true, DeletedAt: new Date() },
{ new: true }
);
if (updateProject) return { status: "Success" };
if (updateProject) return { status: "Success",project: updateProject };
} catch (error: unknown) {
return { status: error };
}