AssetPoints based on type fixed, Asset Get,Create, 3d widget type updated in socket

This commit is contained in:
2025-04-03 19:51:51 +05:30
parent bc97dfa1ed
commit 7b8636c43b
14 changed files with 1648 additions and 460 deletions

View File

@@ -1,180 +1,303 @@
import { Request, Response } from "express";
import pointModel from "../../../shared/model/builder/assets/assetPoint-Model.ts";
interface ITriggerConveyor {
uuid: string;
name: string;
type: string;
isUsed: boolean;
bufferTime: number;
}
interface ITriggerVehicle {
uuid: string;
name: string;
type: string;
isUsed: boolean;
}
interface IConnection {
source: { pathUUID: string; pointUUID: string };
targets: { pathUUID: string; pointUUID: string }[];
}
interface IPointBase {
uuid: string;
position: number[];
connections: IConnection;
}
interface IPointConveyor extends IPointBase {
rotation: number[];
actions: Array<{
uuid: string;
name: string;
type: string;
material: string;
delay: number | string;
spawnInterval: number | string;
isUsed: boolean;
}>;
triggers: Array<{
uuid: string;
name: string;
type: string;
isUsed: boolean;
bufferTime: number;
}>;
}
interface IPointVehicle extends IPointBase {
actions: Array<{
uuid: string;
name: string;
type: string;
isUsed: boolean;
hitCount: number;
start: string;
end: string;
buffer: number;
}>;
triggers: Array<{
uuid: string;
name: string;
type: string;
isUsed: boolean;
}>;
}
export class pointService {
static async addPoints(req: Request, res: Response): Promise<any> {
const { type, modelfileID, organization } = req.body;
// Validate type
if (!["Conveyor", "Vehicle"].includes(type)) {
return res.status(400).json({ message: "Invalid type requested" });
}
try {
const existingdata = await pointModel(organization).findOne({
modelfileID: modelfileID,
isArchive: false,
});
if (existingdata) return res.send("Data already exists");
if (type === "Conveyor") {
const pointsData = await pointModel(organization).findOne({
modelfileID: modelfileID,
type: type,
});
if (pointsData) return res.send("Data already exists");
const createData = await pointModel(organization).create({
type: "Conveyor",
const baseData = {
modelfileID: "672a090f80d91ac979f4d0bd",
points: [
{
uuid: "point1UUID",
position: [0, 0.85, 2.2],
rotation: [0, 0, 0],
actions: [
{
uuid: "randomUUID",
name: "Action 1",
type: "Inherit",
material: "Inherit",
delay: "Inherit",
spawnInterval: "Inherit",
isUsed: false,
},
],
triggers: [
{
uuid: "randomUUID",
name: "trigger 1",
type: "Inherit",
bufferTime: 0,
// delay: "Inherit",
// spawnInterval: "Inherit",
isUsed: false,
},
],
// connections: {
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
// targets: [],
// },
type: "Conveyor",
};
const conveyorPoints: IPointConveyor[] = [
{
uuid: "point1UUID",
position: [0, 0.85, 2.2],
rotation: [0, 0, 0],
actions: [
{
uuid: "randomUUID",
name: "Action 1",
type: "actionType",
material: "actionMaterial",
delay: "Inherit",
spawnInterval: "Inherit",
isUsed: false,
},
],
triggers: [
{
uuid: "randomUUID",
name: "trigger 1",
type: "triggerType",
bufferTime: 0,
// delay: "Inherit",
// spawnInterval: "Inherit",
isUsed: false,
},
],
connections: {
source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
targets: [{ pathUUID: "modelUUID", pointUUID: "point1UUID" }],
},
{
uuid: "point2UUID",
position: [0, 0.85, 0],
rotation: [0, 0, 0],
actions: [
{
uuid: "randomUUID",
name: "Action 1",
type: "Inherit",
material: "Inherit",
delay: "Inherit",
spawnInterval: "Inherit",
isUsed: false,
},
],
triggers: [
{
uuid: "randomUUID",
name: "trigger 1",
type: "Inherit",
bufferTime: 0,
// delay: "Inherit",
// spawnInterval: "Inherit",
isUsed: false,
},
],
// connections: {
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
// targets: [],
// },
},
{
uuid: "point2UUID",
position: [0, 0.85, 0],
rotation: [0, 0, 0],
actions: [
{
uuid: "randomUUID",
name: "Action 1",
type: "actionType",
material: "actionMaterial",
delay: "Inherit",
spawnInterval: "Inherit",
isUsed: false,
},
],
triggers: [
{
uuid: "randomUUID",
name: "trigger 1",
type: "triggerType",
bufferTime: 0,
isUsed: false,
},
],
connections: {
source: { pathUUID: "modelUUID", pointUUID: "point2UUID" },
targets: [{ pathUUID: "modelUUID", pointUUID: "point2UUID" }],
},
{
uuid: "point3UUID",
position: [0, 0.85, -2.2],
rotation: [0, 0, 0],
actions: [
{
uuid: "randomUUID",
name: "Action 1",
type: "Inherit",
material: "Inherit",
delay: "Inherit",
spawnInterval: "Inherit",
isUsed: false,
},
],
triggers: [
{
uuid: "randomUUID",
name: "trigger 1",
type: "Inherit",
bufferTime: 0,
// delay: "Inherit",
// spawnInterval: "Inherit",
isUsed: false,
},
],
// connections: {
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
// targets: [],
// },
},
{
uuid: "point3UUID",
position: [0, 0.85, -2.2],
rotation: [0, 0, 0],
actions: [
{
uuid: "randomUUID",
name: "Action 1",
type: "actionType",
material: "actionMaterial",
delay: "Inherit",
spawnInterval: "Inherit",
isUsed: false,
},
],
triggers: [
{
uuid: "randomUUID",
name: "trigger 1",
type: "triggerType",
bufferTime: 0,
isUsed: false,
},
],
connections: {
source: { pathUUID: "modelUUID", pointUUID: "point3UUID" },
targets: [{ pathUUID: "modelUUID", pointUUID: "point3UUID" }],
},
],
},
];
await pointModel(organization).create({
...baseData,
points: conveyorPoints,
});
}
// else if (type === "Vehicle") {
// // responseData = {
// // type: "Vehicle",
// // points: {
// // uuid: "point1UUID",
// // position: [10, 20, 30],
// // rotation: [0, 0, 0],
// // actions: [
// // {
// // uuid: "randomUUID",
// // name: "Action 1",
// // type: "Inherit",
// // material: "Inherit",
// // delay: "Inherit",
// // spawnInterval: "Inherit",
// // isUsed: false,
// // },
// // ],
// // triggers: [],
// // connections: {
// // source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
// // targets: [],
// // },
// // },
// // speed: 1,
// // };
// }
if (type === "Vehicle") {
console.log("vehcile data");
const baseData = {
modelfileID: "67e3da19c2e8f37134526e6a",
type: "Vehicle",
};
const vehiclePoint: IPointVehicle = {
uuid: "point1UUID",
position: [0, 1.3, 0],
actions: [
{
uuid: "randomUUID",
name: "Action 1",
type: "string",
hitCount: 1,
isUsed: false,
start: "start",
end: "end",
buffer: 0,
},
],
triggers: [
{ uuid: "string", name: "string", type: "string", isUsed: false },
],
connections: {
source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
targets: [{ pathUUID: "modelUUID", pointUUID: "point1UUID" }],
},
};
if ("rotation" in vehiclePoint) {
return res
.status(400)
.json({ error: "Rotation not allowed for Vehicle points" });
}
res.status(200).json({ message: "point created successfully" });
await pointModel(organization).create({
...baseData,
points: vehiclePoint,
});
}
return res.status(201).json({ message: "Points created successfully" });
} catch (error) {
res.status(500).json({ message: "Server error", error });
return res.status(500).json({
message: "Server error",
error: error instanceof Error ? error.message : "Unknown error",
});
}
}
static async gettypePoints(req: Request, res: Response): Promise<any> {
const { modelfileID, organization } = req.params;
console.log("req.params: ", req.params);
try {
const getData = await pointModel(organization)
const pointData = await pointModel(organization)
.findOne({
modelfileID: modelfileID,
isArchive: false,
})
.select("-_id -__v -createdAt -updatedAt");
if (!getData) {
.select("type points -_id");
if (!pointData) {
return res.json({ message: "Data not found" });
}
const formattedData = {
modelfileID: getData?.modelfileID,
type: getData?.type,
points: Array.isArray(getData?.points)
? getData.points.map((point: any) => ({
position: point.position,
rotation: point.rotation,
}))
: [],
};
return res.status(200).json(formattedData);
} catch (error) {
res.status(500).json({ message: "Server error", error });
res.status(200).json(pointData);
} catch (error: any) {
res.status(500).json({ message: "Server error", error: error.message });
}
}
}
// Function to remove `_id` recursively
// const removeIdRecursively = (obj: any): any => {
// if (Array.isArray(obj)) {
// return obj.map(removeIdRecursively);
// } else if (obj !== null && typeof obj === "object") {
// const { _id, ...rest } = obj; // Remove `_id`
// return Object.keys(rest).reduce((acc, key) => {
// acc[key] = removeIdRecursively(rest[key]); // Recursively clean nested objects
// return acc;
// }, {} as any);
// }
// return obj;
// };
// static async gettypePoints(req: Request, res: Response): Promise<any> {
// const { modelfileID, organization } = req.params;
// try {
// const { ConveyorModel, VehicleModel } = pointModel(organization);
// const conveyorData = await ConveyorModel.findOne({ modelfileID })
// .select("-_id -createdAt -updatedAt")
// .lean();
// const vehicleData = await VehicleModel.findOne({ modelfileID })
// .select("-_id -createdAt -updatedAt")
// .lean();
// if (!conveyorData && !vehicleData) {
// return res.status(404).json({ message: "Data not found" });
// }
// const combinedData = [conveyorData, vehicleData].filter(Boolean);
// const formattedData = combinedData.map((data) => {
// const typedData = data as any;
// return {
// modelfileID: typedData.modelfileID,
// type: typedData.type,
// points: Array.isArray(typedData.points)
// ? typedData.points.map((point: any) => ({
// position: point.position,
// rotation: point.rotation,
// }))
// : [],
// };
// });
// return res.status(200).json(formattedData);
// } catch (error) {
// res.status(500).json({ message: "Server error", error });
// }
// }