zone duplication and Deleted Time updated

This commit is contained in:
2025-06-02 18:08:32 +05:30
parent 245959ef88
commit e6f3e26353
5 changed files with 76 additions and 18 deletions

11
.env
View File

@@ -1,11 +1,14 @@
MONGO_URI=mongodb://mongo/
MONGO_USER=admin
MONGO_PASSWORD=admin321
# MONGO_URI=mongodb://mongo/
# MONGO_USER=admin
# MONGO_PASSWORD=admin321
# MONGO_AUTH_DB=admin
MONGO_URI=mongodb://192.168.0.110/
MONGO_USER=mydata
MONGO_PASSWORD=mongodb@hexr2002
MONGO_AUTH_DB=admin
API_PORT=5000
SOCKET_PORT=8000
NODE_ENV=development

View File

@@ -1,13 +1,12 @@
import express from 'express';
import { Lines } from '../controller/lines/line-Services.ts';
import express from "express";
import { Lines } from "../controller/lines/line-Services.ts";
const router = express.Router();
router.post('/setLine',Lines.setLines)
router.post('/updatePoint',Lines.updateLines)
router.get('/findLines/:organization',Lines.getLines)
router.delete('/deleteLine',Lines.deleteLineItems)
router.delete('/deletePoint',Lines.deleteLinPoiteItems)
router.post('/deleteLayer',Lines.deleteLayer)
router.post("/setLine", Lines.setLines);
router.post("/updatePoint", Lines.updateLines);
router.get("/findLines/:organization", Lines.getLines);
router.delete("/deleteLine", Lines.deleteLineItems);
router.delete("/deletePoint", Lines.deleteLinPoiteItems);
router.post("/deleteLayer", Lines.deleteLayer);
export default router;

View File

@@ -134,7 +134,6 @@ export const DeleteProject = async (data: ProjectDelInterface) => {
let filter = { _id: projectId, isArchive: false } as RoleFilter;
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,
@@ -148,8 +147,7 @@ export const DeleteProject = async (data: ProjectDelInterface) => {
};
export const updateProject = async (data: UpdateProjectInput) => {
try {
const { projectId, organization, userId, projectName, thumbnail } =
data;
const { projectId, organization, userId, projectName, thumbnail } = data;
const ExistingUser = await existingUser(userId, organization);
if (!ExistingUser) return { status: "User not found" };
let filter = { _id: projectId, isArchive: false } as RoleFilter;
@@ -199,14 +197,43 @@ export const DuplicateProject = async (data: IProjectDuplicate) => {
project: projectExisting,
};
}
const uniqeName = await generateUniqueProjectName(
projectName,
organization,
userId
);
const project = await projectModel(organization).create({
projectName: projectName,
projectName: uniqeName,
projectUuid: projectUuid,
createdBy: userId,
thumbnail: thumbnail,
sharedUsers: sharedUsers || [],
isArchive: false,
});
const RecentUserDoc = await UsersDataModel(organization).findOne({
userId: userId,
isArchive: false,
});
const newArr = RecentUserDoc?.recentlyViewed || [];
if (RecentUserDoc?.recentlyViewed.length === 0) {
newArr.push(project._id);
await RecentUserDoc.save();
} else {
const index = newArr.indexOf(project._id);
if (index !== -1) {
newArr.splice(index, 1);
}
newArr.unshift(project._id);
if (newArr.length > maxLength) {
newArr.pop();
}
}
await UsersDataModel(organization).findOneAndUpdate(
{ userId: userId, isArchive: false },
{ recentlyViewed: newArr },
{ new: true }
);
const versionData = await previousVersion(project._id, organization);
if (!versionData || versionData.length === 0) {
const newVersion = await versionModel(organization).create({
@@ -227,6 +254,33 @@ export const DuplicateProject = async (data: IProjectDuplicate) => {
return { status: error };
}
};
const generateUniqueProjectName = async (
baseName: string,
organization: string,
userId: string
): Promise<string> => {
let nameToTry = baseName;
let suffix = "";
let attempt = 0;
while (true) {
const existing = await projectModel(organization).findOne({
projectName: nameToTry.trim(),
createdBy: userId,
isArchive: false,
});
if (!existing) return nameToTry;
suffix += " (copy)";
nameToTry = `${baseName}${suffix}`;
attempt++;
if (attempt > 10)
throw new Error("Too many duplicate project name attempts");
}
};
const maxLength: number = 6;
export const viewProject = async (data: ProjectInterface) => {
try {

View File

@@ -45,6 +45,7 @@ export const TrashDatas = async (data: IOrg) => {
projectName: data.projectName,
thumbnail: data.thumbnail,
createdBy: data.createdBy,
DeletedAt: data.DeletedAt,
_id: data._id,
};
});
@@ -90,7 +91,7 @@ export const TrashDelete = async (data: IRestore) => {
{ new: true }
);
if (!DeleteTrashData) return { status: "Project Already Deleted" };
return { status: "Success",data:DeleteTrashData };
return { status: "Success", data: DeleteTrashData };
} catch (error) {
return { status: error };
}

View File

@@ -6,6 +6,7 @@ import templateModel from "../../../shared/model/vizualization/templatemodel.ts"
import widgetModel from "../../../shared/model/vizualization/widgemodel.ts";
export const setZone = async (data: any) => {
const { organization, userId, zoneData } = data;
console.log('data:zone ', data);
try {
const zoneId = zoneData.zoneId;
const points = zoneData.points;