2025-05-27 12:19:15 +05:30
|
|
|
import wallItemModel from "../../../shared/model/builder/assets/wallitems-Model.ts";
|
2025-05-28 13:01:55 +05:30
|
|
|
import { existingUser } from "../helpers/v1projecthelperFns.ts";
|
2025-05-27 12:19:15 +05:30
|
|
|
interface IWallSetupData {
|
|
|
|
|
modelUuid: string;
|
|
|
|
|
modelName: string;
|
|
|
|
|
type: string;
|
|
|
|
|
csgposition: [];
|
|
|
|
|
csgscale: [];
|
|
|
|
|
position: [];
|
|
|
|
|
quaternion: [];
|
|
|
|
|
scale: [];
|
|
|
|
|
organization: string;
|
|
|
|
|
projectId: string;
|
2025-05-28 13:01:55 +05:30
|
|
|
userId: string;
|
2025-05-27 12:19:15 +05:30
|
|
|
}
|
2025-05-27 16:46:48 +05:30
|
|
|
interface IWallGet {
|
|
|
|
|
userId: string;
|
|
|
|
|
organization: string;
|
|
|
|
|
projectId: string;
|
|
|
|
|
}
|
|
|
|
|
interface IWallDelete {
|
|
|
|
|
userId: string;
|
|
|
|
|
modelUuid: string;
|
|
|
|
|
modelName: string;
|
|
|
|
|
organization: string;
|
|
|
|
|
projectId: string;
|
|
|
|
|
}
|
2025-05-27 12:19:15 +05:30
|
|
|
interface IWallItemResult {
|
2025-05-27 16:46:48 +05:30
|
|
|
data?: Object;
|
|
|
|
|
status: string;
|
2025-05-27 12:19:15 +05:30
|
|
|
}
|
|
|
|
|
export class WallItems {
|
|
|
|
|
static async setWallItems(data: IWallSetupData): Promise<IWallItemResult> {
|
|
|
|
|
try {
|
|
|
|
|
const {
|
2025-05-28 13:01:55 +05:30
|
|
|
userId,
|
2025-05-27 12:19:15 +05:30
|
|
|
modelUuid,
|
|
|
|
|
modelName,
|
|
|
|
|
position,
|
|
|
|
|
type,
|
|
|
|
|
csgposition,
|
|
|
|
|
csgscale,
|
|
|
|
|
quaternion,
|
|
|
|
|
scale,
|
|
|
|
|
projectId,
|
|
|
|
|
organization,
|
|
|
|
|
} = data;
|
2025-05-28 13:01:55 +05:30
|
|
|
const UserExists = await existingUser(userId, organization);
|
|
|
|
|
if (!UserExists) return { status: "User not found" };
|
2025-05-27 12:19:15 +05:30
|
|
|
const findvalue = await wallItemModel(organization).findOne({
|
|
|
|
|
modelUuid: modelUuid,
|
2025-05-29 15:34:12 +05:30
|
|
|
isArchive: false,
|
2025-05-27 12:19:15 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (findvalue) {
|
|
|
|
|
const updatevalue = await wallItemModel(organization).findOneAndUpdate(
|
2025-05-29 15:34:12 +05:30
|
|
|
{ modelUuid: modelUuid, projectId: projectId, isArchive: false },
|
2025-05-27 12:19:15 +05:30
|
|
|
{
|
|
|
|
|
modelName,
|
|
|
|
|
position,
|
|
|
|
|
type,
|
|
|
|
|
csgposition,
|
|
|
|
|
csgscale,
|
|
|
|
|
quaternion,
|
|
|
|
|
scale,
|
|
|
|
|
},
|
2025-05-29 15:34:12 +05:30
|
|
|
{ new: true }
|
2025-05-27 12:19:15 +05:30
|
|
|
);
|
|
|
|
|
return {
|
2025-05-27 16:46:48 +05:30
|
|
|
status: "Updated successfully",
|
2025-05-27 12:19:15 +05:30
|
|
|
data: updatevalue,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
const newValue = await wallItemModel(organization).create({
|
|
|
|
|
modelUuid,
|
|
|
|
|
modelName,
|
|
|
|
|
position,
|
|
|
|
|
type,
|
|
|
|
|
projectId,
|
|
|
|
|
csgposition,
|
|
|
|
|
csgscale,
|
|
|
|
|
quaternion,
|
|
|
|
|
scale,
|
|
|
|
|
});
|
|
|
|
|
return {
|
2025-05-27 16:46:48 +05:30
|
|
|
status: "wall Item created successfully",
|
2025-05-27 12:19:15 +05:30
|
|
|
data: newValue,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
} catch (error: unknown) {
|
2025-05-27 16:46:48 +05:30
|
|
|
if (error instanceof Error) {
|
|
|
|
|
return {
|
|
|
|
|
status: error.message,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
status: "An unexpected error occurred",
|
|
|
|
|
};
|
|
|
|
|
}
|
2025-05-27 12:19:15 +05:30
|
|
|
}
|
|
|
|
|
}
|
2025-05-27 16:46:48 +05:30
|
|
|
static async getWallItems(data: IWallGet) {
|
2025-05-27 12:19:15 +05:30
|
|
|
try {
|
2025-05-28 13:01:55 +05:30
|
|
|
const { organization, userId, projectId } = data;
|
|
|
|
|
const UserExists = await existingUser(userId, organization);
|
|
|
|
|
if (!UserExists) return { status: "User not found" };
|
|
|
|
|
const findValue = await wallItemModel(organization).find({
|
|
|
|
|
projectId: projectId,
|
2025-05-29 15:34:12 +05:30
|
|
|
isArchive: false,
|
2025-05-28 13:01:55 +05:30
|
|
|
});
|
2025-05-27 12:19:15 +05:30
|
|
|
if (!findValue) {
|
2025-05-27 16:46:48 +05:30
|
|
|
return {
|
|
|
|
|
status: "wallitems not found",
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
status: "Success",
|
|
|
|
|
data: findValue,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
} catch (error: unknown) {
|
|
|
|
|
if (error instanceof Error) {
|
|
|
|
|
return {
|
|
|
|
|
status: error.message,
|
|
|
|
|
};
|
2025-05-27 12:19:15 +05:30
|
|
|
} else {
|
2025-05-27 16:46:48 +05:30
|
|
|
return {
|
|
|
|
|
status: "An unexpected error occurred",
|
|
|
|
|
};
|
2025-05-27 12:19:15 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-27 16:46:48 +05:30
|
|
|
static async deleteWallItems(data: IWallDelete): Promise<IWallItemResult> {
|
2025-05-27 12:19:15 +05:30
|
|
|
try {
|
2025-05-28 13:01:55 +05:30
|
|
|
const { modelUuid, modelName, organization, userId, projectId } = data;
|
|
|
|
|
const UserExists = await existingUser(userId, organization);
|
|
|
|
|
if (!UserExists) return { status: "User not found" };
|
2025-05-27 12:19:15 +05:30
|
|
|
const findValue = await wallItemModel(organization).findOneAndDelete({
|
|
|
|
|
modelUuid: modelUuid,
|
|
|
|
|
modelName: modelName,
|
2025-05-27 16:46:48 +05:30
|
|
|
projectId: projectId,
|
2025-05-29 15:34:12 +05:30
|
|
|
isArchive: false,
|
2025-05-27 12:19:15 +05:30
|
|
|
});
|
|
|
|
|
if (!findValue) {
|
2025-05-27 16:46:48 +05:30
|
|
|
return {
|
|
|
|
|
status: "model not found",
|
|
|
|
|
};
|
2025-05-27 12:19:15 +05:30
|
|
|
} else {
|
2025-05-27 16:46:48 +05:30
|
|
|
return {
|
|
|
|
|
status: "Success",
|
|
|
|
|
data: findValue,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
} catch (error: unknown) {
|
|
|
|
|
if (error instanceof Error) {
|
|
|
|
|
return {
|
|
|
|
|
status: error.message,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
status: "An unexpected error occurred",
|
|
|
|
|
};
|
2025-05-27 12:19:15 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|