181 lines
5.9 KiB
TypeScript
181 lines
5.9 KiB
TypeScript
import { Request, Response } from "express";
|
|
import pointModel from "../../../shared/model/builder/assets/assetPoint-Model.ts";
|
|
|
|
export class pointService {
|
|
static async addPoints(req: Request, res: Response): Promise<any> {
|
|
const { type, modelfileID, organization } = req.body;
|
|
|
|
if (!["Conveyor", "Vehicle"].includes(type)) {
|
|
return res.status(400).json({ message: "Invalid type requested" });
|
|
}
|
|
|
|
try {
|
|
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",
|
|
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: [],
|
|
// },
|
|
},
|
|
{
|
|
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: "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: [],
|
|
// },
|
|
},
|
|
],
|
|
});
|
|
}
|
|
// 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,
|
|
// // };
|
|
// }
|
|
|
|
res.status(200).json({ message: "point created successfully" });
|
|
} catch (error) {
|
|
res.status(500).json({ message: "Server error", error });
|
|
}
|
|
}
|
|
|
|
static async gettypePoints(req: Request, res: Response): Promise<any> {
|
|
const { modelfileID, organization } = req.params;
|
|
try {
|
|
const getData = await pointModel(organization)
|
|
.findOne({
|
|
modelfileID: modelfileID,
|
|
})
|
|
.select("-_id -__v -createdAt -updatedAt");
|
|
if (!getData) {
|
|
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 });
|
|
}
|
|
}
|
|
}
|