V1 for the builder processing
This commit is contained in:
117
src/shared/services/builder/wallService.ts
Normal file
117
src/shared/services/builder/wallService.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import { Request, Response } from "express";
|
||||
import wallItemModel from "../../../shared/model/builder/assets/wallitems-Model.ts";
|
||||
interface IWallSetupData {
|
||||
modelUuid: string;
|
||||
modelName: string;
|
||||
type: string;
|
||||
csgposition: [];
|
||||
csgscale: [];
|
||||
position: [];
|
||||
quaternion: [];
|
||||
scale: [];
|
||||
organization: string;
|
||||
projectId: string;
|
||||
}
|
||||
interface IWallItemResult {
|
||||
data: {};
|
||||
state: string;
|
||||
}
|
||||
export class WallItems {
|
||||
static async setWallItems(data: IWallSetupData): Promise<IWallItemResult> {
|
||||
try {
|
||||
const {
|
||||
modelUuid,
|
||||
modelName,
|
||||
position,
|
||||
type,
|
||||
csgposition,
|
||||
csgscale,
|
||||
quaternion,
|
||||
scale,
|
||||
projectId,
|
||||
organization,
|
||||
} = data;
|
||||
const findvalue = await wallItemModel(organization).findOne({
|
||||
modelUuid: modelUuid,
|
||||
});
|
||||
|
||||
if (findvalue) {
|
||||
const updatevalue = await wallItemModel(organization).findOneAndUpdate(
|
||||
{ modelUuid: modelUuid, projectId: projectId },
|
||||
{
|
||||
modelName,
|
||||
position,
|
||||
type,
|
||||
csgposition,
|
||||
csgscale,
|
||||
quaternion,
|
||||
scale,
|
||||
},
|
||||
{ new: true } // Return the updated document
|
||||
);
|
||||
return {
|
||||
state: "Updated successfully",
|
||||
data: updatevalue,
|
||||
};
|
||||
// res.status(201).json(updatevalue);
|
||||
} else {
|
||||
const newValue = await wallItemModel(organization).create({
|
||||
modelUuid,
|
||||
modelName,
|
||||
position,
|
||||
type,
|
||||
projectId,
|
||||
csgposition,
|
||||
csgscale,
|
||||
quaternion,
|
||||
scale,
|
||||
});
|
||||
return {
|
||||
state: "wall Item created successfully",
|
||||
data: newValue,
|
||||
};
|
||||
// res.status(201).json(newValue);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
const err = error as Error;
|
||||
console.error("Error creating wallitems:", error);
|
||||
return {
|
||||
state: "Failed to create wallitems",
|
||||
data: { message: err.message },
|
||||
};
|
||||
}
|
||||
}
|
||||
static async getWallItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
|
||||
const findValue = await wallItemModel(organization).find();
|
||||
if (!findValue) {
|
||||
res.status(200).json("wallitems not found");
|
||||
} else {
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error get wallitems:", error);
|
||||
res.status(500).json({ error: "Failed to get wallitems" });
|
||||
}
|
||||
}
|
||||
static async deleteWallItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { modelUuid, modelName, organization } = req.body;
|
||||
|
||||
const findValue = await wallItemModel(organization).findOneAndDelete({
|
||||
modelUuid: modelUuid,
|
||||
modelName: modelName,
|
||||
});
|
||||
if (!findValue) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error get wallitems:", error);
|
||||
res.status(500).json({ error: "Failed to get wallitems" });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user