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

@@ -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,
};