isArchive and event of wall item modified

This commit is contained in:
2025-06-12 09:44:49 +05:30
parent 762f4f82af
commit dead851b1a
2 changed files with 139 additions and 102 deletions

View File

@@ -60,12 +60,12 @@ export const setWallItems = async (
);
if (!LivingProject) return { status: "Project not found" };
const findvalue = await wallItemModel(organization).findOne({
modelUuid: modelUuid,
modelUuid: modelUuid,isArchive:false
});
if (findvalue) {
const updatevalue = await wallItemModel(organization).findOneAndUpdate(
{ modelUuid: modelUuid, projectId: projectId },
{ modelUuid: modelUuid, projectId: projectId,isArchive:false },
{
modelName,
position,
@@ -96,7 +96,8 @@ export const setWallItems = async (
});
console.log("newValue: ", newValue);
return {
status: "wall Item created successfully",
// status: "wall Item created successfully",
status: "Success",
data: newValue,
};
}
@@ -124,7 +125,7 @@ export const getWallItems = async (data: IWallGet) => {
);
if (!LivingProject) return { status: "Project not found" };
const findValue = await wallItemModel(organization).find({
projectId: projectId,
projectId: projectId,isArchive:false
});
if (!findValue) {
return {
@@ -165,7 +166,7 @@ export const deleteWallItems = async (
const findValue = await wallItemModel(organization).findOneAndDelete({
modelUuid: modelUuid,
modelName: modelName,
projectId: projectId,
projectId: projectId,isArchive:false
});
if (!findValue) {
return {

View File

@@ -1,115 +1,151 @@
import { Socket, Server } from "socket.io";
import { EVENTS } from "../../socket/events.ts";
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
import { deleteWallItems, setWallItems } from "../../../shared/services/builder/wallService.ts";
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts";
import {
deleteWallItems,
setWallItems,
} from "../../../shared/services/builder/wallService.ts";
import {
ErrorResponse,
FinalResponse,
validateFields,
} from "../../utils/socketfunctionHelpers.ts";
export const setWallItemsHandleEvent = async (
event: string,
socket: Socket,
io: Server,
data: any,
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
event: string,
socket: Socket,
io: Server,
data: any,
connectedUsersByOrg: {
[org: string]: { socketId: string; userId: string; role: string }[];
}
) => {
if (event !== EVENTS.setWallItems_v1 || !data?.organization) return;
const requiredFields = [
"modelUuid",
"modelName",
"position",
"type",
"csgposition",
"csgscale",
"quaternion",
"assetId",
"scale",
"projectId",
"userId",
"organization",
];
if (event !== EVENTS.setWallItems_v1 || !data?.organization) return;
const requiredFields = [
"modelUuid",
"modelName",
"position",
"type",
"csgposition",
"csgscale",
"quaternion",
"assetId",
"scale",
"projectId",
"userId",
"organization",
];
const missingFields = validateFields(data, requiredFields);
const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1UpdateResponse,
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
return;
}
const result = await setWallItems(data);
const status = typeof result?.status === "string" ? result.status : "unknown";
if (missingFields.length > 0) {
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.wallItems_v1UpdateResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return;
}
const result = await setWallItems(data);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "wall Item created successfully" },
"User not found": { message: "User not found" },
"Project not found": { message: "Project not found" },
"Updated successfully": { message: "Updated successfully" },
const messages: Record<string, { message: string }> = {
Success: { message: "wall Item created successfully" },
"User not found": { message: "User not found" },
"Project not found": { message: "Project not found" },
"Updated successfully": { message: "Updated successfully" },
};
const msg = messages[status] || { message: "Internal server error" };
const wall_Datas = status === "Success" && result?.data ? {} : undefined;
};
const response = FinalResponse(
status,
socket,
data.organization,
messages,
wall_Datas
);
const msg = messages[status] || { message: "Internal server error" };
const wall_Datas =
status === "Success" && result?.data
? {
}
: undefined;
const response = FinalResponse(status, socket, data.organization, messages, wall_Datas);
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1UpdateResponse, response, connectedUsersByOrg)
}
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.wallItems_v1UpdateResponse,
response,
connectedUsersByOrg
);
};
export const deleteWallItemsHandleEvent = async (
event: string,
socket: Socket,
io: Server,
data: any,
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
event: string,
socket: Socket,
io: Server,
data: any,
connectedUsersByOrg: {
[org: string]: { socketId: string; userId: string; role: string }[];
}
) => {
if (event !== EVENTS.setWallItems_v1 || !data?.organization) return;
const requiredFields = [
"modelUuid",
"modelName",
"projectId",
"userId",
"organization",
];
if (event !== EVENTS.deleteWallItems_v1 || !data?.organization) return;
const requiredFields = [
"modelUuid",
"modelName",
"projectId",
"userId",
"organization",
];
const missingFields = validateFields(data, requiredFields);
const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1DeleteResponse,
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
return;
}
const result = await deleteWallItems(data);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "wall Item deleted successfully" },
"User not found": { message: "User not found" },
"Project not found": { message: "Project not found" },
"model not found": { message: "model not found" },
if (missingFields.length > 0) {
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.wallItems_v1DeleteResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return;
}
const result = await deleteWallItems(data);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "wall Item deleted successfully" },
"User not found": { message: "User not found" },
"Project not found": { message: "Project not found" },
"model not found": { message: "model not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const wall_Datas =
status === "Success" && result?.data
? {
// widget: {
// id: result.data.widgetID,
// type: result.data.projectName,
// position: result.data.position,
// },
// Data: result.data.Data,
// zoneId: result.data.zoneId,
}
: undefined;
const response = FinalResponse(
status,
socket,
data.organization,
messages,
wall_Datas
);
};
const msg = messages[status] || { message: "Internal server error" };
const wall_Datas =
status === "Success" && result?.data
? {
// widget: {
// id: result.data.widgetID,
// type: result.data.projectName,
// position: result.data.position,
// },
// Data: result.data.Data,
// zoneId: result.data.zoneId,
}
: undefined;
const response = FinalResponse(status, socket, data.organization, messages, wall_Datas);
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1DeleteResponse, response, connectedUsersByOrg)
}
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.wallItems_v1DeleteResponse,
response,
connectedUsersByOrg
);
};