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

View File

@@ -1,15 +1,24 @@
import { Socket, Server } from "socket.io"; import { Socket, Server } from "socket.io";
import { EVENTS } from "../../socket/events.ts"; import { EVENTS } from "../../socket/events.ts";
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts"; import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
import { deleteWallItems, setWallItems } from "../../../shared/services/builder/wallService.ts"; import {
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts"; deleteWallItems,
setWallItems,
} from "../../../shared/services/builder/wallService.ts";
import {
ErrorResponse,
FinalResponse,
validateFields,
} from "../../utils/socketfunctionHelpers.ts";
export const setWallItemsHandleEvent = async ( export const setWallItemsHandleEvent = async (
event: string, event: string,
socket: Socket, socket: Socket,
io: Server, io: Server,
data: any, 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.setWallItems_v1 || !data?.organization) return;
const requiredFields = [ const requiredFields = [
@@ -30,8 +39,14 @@ export const setWallItemsHandleEvent = async (
const missingFields = validateFields(data, requiredFields); const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) { if (missingFields.length > 0) {
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1UpdateResponse, emitToSenderAndAdmins(
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg); io,
socket,
data.organization,
EVENTS.wallItems_v1UpdateResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return; return;
} }
const result = await setWallItems(data); const result = await setWallItems(data);
@@ -42,31 +57,38 @@ export const setWallItemsHandleEvent = async (
"User not found": { message: "User not found" }, "User not found": { message: "User not found" },
"Project not found": { message: "Project not found" }, "Project not found": { message: "Project not found" },
"Updated successfully": { message: "Updated successfully" }, "Updated successfully": { message: "Updated successfully" },
}; };
const msg = messages[status] || { message: "Internal server error" }; const msg = messages[status] || { message: "Internal server error" };
const wall_Datas = const wall_Datas = status === "Success" && result?.data ? {} : undefined;
status === "Success" && result?.data
? { const response = FinalResponse(
status,
socket,
data.organization,
messages,
wall_Datas
);
} emitToSenderAndAdmins(
: undefined; io,
socket,
const response = FinalResponse(status, socket, data.organization, messages, wall_Datas); data.organization,
EVENTS.wallItems_v1UpdateResponse,
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1UpdateResponse, response, connectedUsersByOrg) response,
} connectedUsersByOrg
);
};
export const deleteWallItemsHandleEvent = async ( export const deleteWallItemsHandleEvent = async (
event: string, event: string,
socket: Socket, socket: Socket,
io: Server, io: Server,
data: any, 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 = [ const requiredFields = [
"modelUuid", "modelUuid",
"modelName", "modelName",
@@ -78,8 +100,14 @@ export const deleteWallItemsHandleEvent = async (
const missingFields = validateFields(data, requiredFields); const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) { if (missingFields.length > 0) {
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1DeleteResponse, emitToSenderAndAdmins(
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg); io,
socket,
data.organization,
EVENTS.wallItems_v1DeleteResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return; return;
} }
const result = await deleteWallItems(data); const result = await deleteWallItems(data);
@@ -89,14 +117,11 @@ export const deleteWallItemsHandleEvent = async (
"User not found": { message: "User not found" }, "User not found": { message: "User not found" },
"Project not found": { message: "Project not found" }, "Project not found": { message: "Project not found" },
"model not found": { message: "model not found" }, "model not found": { message: "model not found" },
}; };
const msg = messages[status] || { message: "Internal server error" }; const msg = messages[status] || { message: "Internal server error" };
const wall_Datas = const wall_Datas =
status === "Success" && result?.data status === "Success" && result?.data
? { ? {
// widget: { // widget: {
// id: result.data.widgetID, // id: result.data.widgetID,
@@ -107,9 +132,20 @@ export const deleteWallItemsHandleEvent = async (
// zoneId: result.data.zoneId, // zoneId: result.data.zoneId,
} }
: undefined; : undefined;
const response = FinalResponse(status, socket, data.organization, messages, wall_Datas); const response = FinalResponse(
status,
socket,
data.organization,
messages,
wall_Datas
);
emitToSenderAndAdmins(
io,
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1DeleteResponse, response, connectedUsersByOrg) socket,
} data.organization,
EVENTS.wallItems_v1DeleteResponse,
response,
connectedUsersByOrg
);
};