Project based wall,service Functionality processing

This commit is contained in:
2025-05-27 16:46:48 +05:30
parent fdfc7a983c
commit 2c28ffe9aa
6 changed files with 526 additions and 123 deletions

View File

@@ -52,18 +52,116 @@ export const WallSetup = async (
scale,
organization,
});
switch (result.state) {
switch (result.status) {
case "Updated successfully":
res.status(201).json(result.data);
res.status(200).json(result.data);
break;
case "wall Item created successfully":
res.status(201).json(result.data);
res.status(200).json(result.data);
break;
default:
res.status(500).json(error);
break;
}
} catch (error: unknown) {
res.status(500).json({ message: "Unknown error" });
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};
export const WallGet = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { organization, role, userId } = req.user || {};
const { projectId } = req.params;
if (!organization || !role || !userId || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await WallItems.getWallItems({
organization,
role,
userId,
projectId,
});
switch (result.status) {
case "wallitems not found":
res.status(404).json({
message: "wallitems not found",
});
break;
case "Success":
res.status(200).json({
WallItems: result.data,
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
}
};
export const WallDelete = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { organization, role, userId } = req.user || {};
const { projectId, modelName, modelUuid } = req.body;
if (
!organization ||
!role ||
!userId ||
!projectId ||
!modelName ||
!modelUuid
) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await WallItems.deleteWallItems({
organization,
role,
userId,
projectId,
modelName,
modelUuid,
});
switch (result.status) {
case "model not found":
res.status(404).json({
message: "model not found",
});
break;
case "Success":
res.status(200).json({
message: "WallItem deleted",
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
}
};

View File

@@ -0,0 +1,213 @@
import lineModel from "../../V1Models/Builder/linesModel.ts";
interface ILineItems {
organization: string;
layer: number;
line: [];
type: string;
projectId: string;
userId: string;
}
interface ILineUpdate {
organization: string;
uuid: number;
position: {};
projectId: string;
userId: string;
}
interface ILineDelete {
organization: string;
line: [];
projectId: string;
userId: string;
}
interface ILinePointsDelete {
organization: string;
uuid: string;
projectId: string;
userId: string;
}
interface ILayerDelete {
organization: string;
layer: number;
projectId: string;
userId: string;
}
export const CreateLineItems = async (
data: ILineItems
): Promise<{ status: string; data?: Object }> => {
try {
const { organization, line, type, layer, projectId, userId } = data;
const newLine = await lineModel(organization).create({
layer,
line,
type,
projectId,
});
return { status: "Success", data: newLine };
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const UpdateLineItems = async (
data: ILineUpdate
): Promise<{ status: string; data?: Object }> => {
try {
const { organization, projectId, uuid, position, userId } = data;
const updateResult = await lineModel(organization).updateMany(
{ "line.uuid": uuid, projectId: projectId }, // Filter: Find the line with the given uuid
{ $set: { "line.$.position": position } } // Update the position and type
);
// return {
// success: true,
// status: "line updated",
// data: { uuid: uuid, position: position },
// organization: organization,
// };
return {
status: "Success",
data: { uuid: uuid, position: position },
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const DeleteLineItems = async (
data: ILineDelete
): Promise<{ status: string; data?: object }> => {
try {
const { organization, projectId, line, userId } = data;
const inputUuids = line.map((item: any) => item.uuid);
const findValue = await lineModel(organization).findOneAndDelete({
"line.uuid": { $all: inputUuids }, // Ensure all UUIDs are present in the `line` key
});
if (!findValue) {
return {
status: "line not found",
};
// return {
// success: false,
// message: "line not found",
// organization: organization,
// };
} else {
return {
status: "Success",
data: findValue,
};
// return {
// success: true,
// message: "line deleted",
// data: findValue,
// organization: organization,
// };
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const DeleteLayer = async (
data: ILayerDelete
): Promise<{ status: string; data?: object }> => {
try {
const { organization, projectId, layer, userId } = data;
const findValue = await lineModel(organization).find({
layer: layer,
projectId: projectId,
});
if (!findValue) {
return { status: "layer not found" };
// return { success: false, message: "layer not found" };
} else {
await lineModel(organization).deleteMany({ layer: layer });
const updateResult = await lineModel(organization).updateMany(
{ layer: { $gt: layer } },
{ $inc: { layer: -1 } }
);
return {
status: "Success",
data: updateResult,
};
// return {
// success: true,
// message: "layer deleted",
// data: layer,
// organization: organization,
// };
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const DeleteLinePoints = async (
data: ILinePointsDelete
): Promise<{ status: string; data?: object }> => {
try {
const { organization, projectId, uuid, userId } = data;
const findValue = await lineModel(organization).deleteMany({
"line.uuid": uuid,
});
if (!findValue) {
return {
success: false,
message: "line not found",
organization: organization,
};
} else {
return {
success: true,
message: "point deleted",
data: uuid,
organization: organization,
};
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};

View File

@@ -12,9 +12,23 @@ interface IWallSetupData {
organization: string;
projectId: string;
}
interface IWallGet {
userId: string;
role: string;
organization: string;
projectId: string;
}
interface IWallDelete {
userId: string;
modelUuid: string;
modelName: string;
role: string;
organization: string;
projectId: string;
}
interface IWallItemResult {
data: {};
state: string;
data?: Object;
status: string;
}
export class WallItems {
static async setWallItems(data: IWallSetupData): Promise<IWallItemResult> {
@@ -50,7 +64,7 @@ export class WallItems {
{ new: true } // Return the updated document
);
return {
state: "Updated successfully",
status: "Updated successfully",
data: updatevalue,
};
// res.status(201).json(updatevalue);
@@ -67,51 +81,80 @@ export class WallItems {
scale,
});
return {
state: "wall Item created successfully",
status: "wall Item created successfully",
data: newValue,
};
// res.status(201).json(newValue);
}
} catch (error: unknown) {
const err = error as Error;
console.error("Error creating wallitems:", error);
return {
state: "Failed to create wallitems",
data: { message: err.message },
};
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
}
static async getWallItems(req: Request, res: Response) {
static async getWallItems(data: IWallGet) {
try {
const { organization } = req.params;
const { organization, role, userId, projectId } = data;
const findValue = await wallItemModel(organization).find();
if (!findValue) {
res.status(200).json("wallitems not found");
return {
status: "wallitems not found",
};
} else {
res.status(201).json(findValue);
return {
status: "Success",
data: findValue,
};
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
} catch (error) {
console.error("Error get wallitems:", error);
res.status(500).json({ error: "Failed to get wallitems" });
}
}
static async deleteWallItems(req: Request, res: Response) {
static async deleteWallItems(data: IWallDelete): Promise<IWallItemResult> {
try {
const { modelUuid, modelName, organization } = req.body;
const { modelUuid, modelName, organization, userId, projectId, role } =
data;
const findValue = await wallItemModel(organization).findOneAndDelete({
modelUuid: modelUuid,
modelName: modelName,
projectId: projectId,
});
if (!findValue) {
res.status(200).json("user not found");
return {
status: "model not found",
};
} else {
res.status(201).json(findValue);
return {
status: "Success",
data: findValue,
};
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
} catch (error) {
console.error("Error get wallitems:", error);
res.status(500).json({ error: "Failed to get wallitems" });
}
}
}

View File

@@ -85,7 +85,6 @@ export const createProject = async (data: CreateProjectInput) => {
project: project,
};
} catch (error) {
console.log("error: ", error);
return {
status: error,
};

View File

@@ -1,100 +1,152 @@
import { Request, Response } from "express";
import lineModel from "../../../shared/model/lines/lines-Model.ts";
export const createLineItems = async (data: any) => {
const { organization, layer, line, type } = data;
try {
const newLine = await lineModel(organization).create({ layer, line, type });
return {
success: true,
message: "line create",
data: newLine,
organization: organization,
};
export const createLineItems = async (data: any)=>{
const {organization,layer,line,type}=data
try {
const newLine = await lineModel(organization).create({ layer,line,type });
return { success: true, message: 'line create', data: newLine,organization:organization }
// Send response with the created document
} catch (error) {
return { success: false, message: 'Error create line', error,organization:organization }
}
}
export const updateLineItems = async (data: any)=>{
const {organization,uuid,position,}=data
try {
// const findLine = await lineModel(organization).find({ 'line.uuid': uuid });
// Update the position of the line matching the uuid
const updateResult = await lineModel(organization).updateMany(
{ 'line.uuid': uuid }, // Filter: Find the line with the given uuid
{ $set: { 'line.$.position': position } } // Update the position and type
);
return { success: true, message: 'line updated', data: {uuid:uuid,position:position},organization:organization }
// Send response with the created document
} catch (error) {
console.error('Error creating Lines:', error);
return { success: false, message: 'Error updating line', error,organization:organization }
}
}
// Send response with the created document
} catch (error) {
return {
success: false,
message: "Error create line",
error,
organization: organization,
};
}
};
export const updateLineItems = async (data: any) => {
const { organization, uuid, position } = data;
try {
// const findLine = await lineModel(organization).find({ 'line.uuid': uuid });
// Update the position of the line matching the uuid
const updateResult = await lineModel(organization).updateMany(
{ "line.uuid": uuid }, // Filter: Find the line with the given uuid
{ $set: { "line.$.position": position } } // Update the position and type
);
return {
success: true,
message: "line updated",
data: { uuid: uuid, position: position },
organization: organization,
};
export const deleteLineItems = async (data: any)=>{
const {organization,line}=data
try {
// Send response with the created document
} catch (error) {
console.error("Error creating Lines:", error);
return {
success: false,
message: "Error updating line",
error,
organization: organization,
};
}
};
const inputUuids = line.map((item: any) => item.uuid);
// const findValue = await lineModel(organization).findOneAndDelete({
// line: { $elemMatch: { uuid: { $in: inputUuids } } },
// });
const findValue = await lineModel(organization).findOneAndDelete({
"line.uuid": { $all: inputUuids } // Ensure all UUIDs are present in the `line` key
});
if (!findValue) {
return { success: false, message: 'line not found',organization:organization }
} else {
return { success: true, message: 'line deleted', data: findValue,organization:organization }
}
} catch (error) {
console.error('Error delete Lines:', error);
return { success: false, message: 'Failed to delete line', error ,organization:organization}
}
}
export const deleteLayer = async (data: any)=>{
const {organization,layer}=data
try {
export const deleteLineItems = async (data: any) => {
const { organization, line } = data;
try {
const inputUuids = line.map((item: any) => item.uuid);
const findValue = await lineModel(organization).find({ layer: layer });
if (!findValue) {
return { success: false, message: 'layer not found' }
} else {
await lineModel(organization).deleteMany({ layer: layer });
// Update documents with layer greater than -1
const updateResult = await lineModel(organization).updateMany(
{ layer: { $gt:layer} },
{ $inc: { layer: -1 } } // Example operation: decrementing layer by 1
);
return { success: true, message: 'layer deleted', data: layer,organization:organization }
}
} catch (error) {
console.error('Error delete layer:', error);
return { success: false, message: 'Failed to delete layer', error ,organization:organization}
}
}
export const deleteLinPoiteItems = async (data: any)=>{
const {organization,uuid}=data
try {
const findValue = await lineModel(organization).deleteMany({ 'line.uuid': uuid })
if (!findValue) {
return { success: false, message: 'line not found',organization:organization }
} else {
// const findValue = await lineModel(organization).findOneAndDelete({
return { success: true, message: 'point deleted', data: uuid ,organization:organization}
}
} catch (error) {
console.error('Error delete Lines:', error);
return { success: false, message: 'Failed to delete point', error ,organization:organization}
}
// line: { $elemMatch: { uuid: { $in: inputUuids } } },
// });
const findValue = await lineModel(organization).findOneAndDelete({
"line.uuid": { $all: inputUuids }, // Ensure all UUIDs are present in the `line` key
});
if (!findValue) {
return {
success: false,
message: "line not found",
organization: organization,
};
} else {
return {
success: true,
message: "line deleted",
data: findValue,
organization: organization,
};
}
} catch (error) {
console.error("Error delete Lines:", error);
return {
success: false,
message: "Failed to delete line",
error,
organization: organization,
};
}
};
export const deleteLayer = async (data: any) => {
const { organization, layer } = data;
try {
const findValue = await lineModel(organization).find({ layer: layer });
if (!findValue) {
return { success: false, message: "layer not found" };
} else {
await lineModel(organization).deleteMany({ layer: layer });
// Update documents with layer greater than -1
const updateResult = await lineModel(organization).updateMany(
{ layer: { $gt: layer } },
{ $inc: { layer: -1 } } // Example operation: decrementing layer by 1
);
return {
success: true,
message: "layer deleted",
data: layer,
organization: organization,
};
}
} catch (error) {
console.error("Error delete layer:", error);
return {
success: false,
message: "Failed to delete layer",
error,
organization: organization,
};
}
};
export const deleteLinPoiteItems = async (data: any) => {
const { organization, uuid } = data;
try {
const findValue = await lineModel(organization).deleteMany({
"line.uuid": uuid,
});
if (!findValue) {
return {
success: false,
message: "line not found",
organization: organization,
};
} else {
return {
success: true,
message: "point deleted",
data: uuid,
organization: organization,
};
}
} catch (error) {
console.error("Error delete Lines:", error);
return {
success: false,
message: "Failed to delete point",
error,
organization: organization,
};
}
};

View File

@@ -66,7 +66,6 @@ const cameraHandleEvent = async (
namespace: any,
notifySender: boolean = false
) => {
console.log("data?.organization: ", data?.organization);
if (!data?.organization) {
console.warn(`Missing organization for event: ${event}`);
return;
@@ -323,7 +322,6 @@ const lineHandleEvent = async (
data: any,
io: any
) => {
console.log("data?.organization: ", data?.organization);
if (!data?.organization) {
console.warn(`Missing organization for event: ${event}`);
return;