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,15 +1,24 @@
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 }[] },
connectedUsersByOrg: {
[org: string]: { socketId: string; userId: string; role: string }[];
}
) => {
if (event !== EVENTS.setWallItems_v1 || !data?.organization) return;
const requiredFields = [
@@ -30,8 +39,14 @@ export const setWallItemsHandleEvent = async (
const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1UpdateResponse,
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.wallItems_v1UpdateResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return;
}
const result = await setWallItems(data);
@@ -42,31 +57,38 @@ export const setWallItemsHandleEvent = async (
"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
const wall_Datas = status === "Success" && result?.data ? {} : undefined;
? {
const response = FinalResponse(
status,
socket,
data.organization,
messages,
wall_Datas
);
}
: 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 }[] },
connectedUsersByOrg: {
[org: string]: { socketId: string; userId: string; role: string }[];
}
) => {
if (event !== EVENTS.setWallItems_v1 || !data?.organization) return;
if (event !== EVENTS.deleteWallItems_v1 || !data?.organization) return;
const requiredFields = [
"modelUuid",
"modelName",
@@ -78,8 +100,14 @@ export const deleteWallItemsHandleEvent = async (
const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1DeleteResponse,
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.wallItems_v1DeleteResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return;
}
const result = await deleteWallItems(data);
@@ -89,14 +117,11 @@ export const deleteWallItemsHandleEvent = async (
"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,
@@ -107,9 +132,20 @@ export const deleteWallItemsHandleEvent = async (
// zoneId: result.data.zoneId,
}
: undefined;
const response = FinalResponse(status, socket, data.organization, messages, wall_Datas);
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
);
};