Files
Dwinzo-Backend-V0.0/src/shared/services/builder/wallService.ts

167 lines
4.0 KiB
TypeScript
Raw Normal View History

2025-05-27 12:19:15 +05:30
import wallItemModel from "../../../shared/model/builder/assets/wallitems-Model.ts";
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;
userId: string;
2025-05-27 12:19:15 +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 {
data?: Object;
status: string;
2025-05-27 12:19:15 +05:30
}
export class WallItems {
static async setWallItems(data: IWallSetupData): Promise<IWallItemResult> {
try {
const {
userId,
2025-05-27 12:19:15 +05:30
modelUuid,
modelName,
position,
type,
csgposition,
csgscale,
quaternion,
scale,
projectId,
organization,
} = 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).findOne({
modelUuid: modelUuid,
isArchive: false,
2025-05-27 12:19:15 +05:30
});
if (findvalue) {
const updatevalue = await wallItemModel(organization).findOneAndUpdate(
{ modelUuid: modelUuid, projectId: projectId, isArchive: false },
2025-05-27 12:19:15 +05:30
{
modelName,
position,
type,
csgposition,
csgscale,
quaternion,
scale,
},
{ new: true }
2025-05-27 12:19:15 +05:30
);
return {
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 {
status: "wall Item created successfully",
2025-05-27 12:19:15 +05:30
data: newValue,
};
}
} 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
}
}
static async getWallItems(data: IWallGet) {
2025-05-27 12:19:15 +05:30
try {
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,
isArchive: false,
});
2025-05-27 12:19:15 +05:30
if (!findValue) {
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 {
return {
status: "An unexpected error occurred",
};
2025-05-27 12:19:15 +05:30
}
}
}
static async deleteWallItems(data: IWallDelete): Promise<IWallItemResult> {
2025-05-27 12:19:15 +05:30
try {
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,
projectId: projectId,
isArchive: false,
2025-05-27 12:19:15 +05:30
});
if (!findValue) {
return {
status: "model not found",
};
2025-05-27 12:19:15 +05:30
} else {
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
}
}
}
}