V2 API for visualization gomathi part completed
This commit is contained in:
137
src/api-server/controller/assets/pointService.ts
Normal file
137
src/api-server/controller/assets/pointService.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
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: [],
|
||||
// connections: {
|
||||
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||
// targets: [],
|
||||
// },
|
||||
},
|
||||
{
|
||||
uuid: "point1UUID",
|
||||
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: [],
|
||||
// connections: {
|
||||
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||
// targets: [],
|
||||
// },
|
||||
},
|
||||
{
|
||||
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: [],
|
||||
// connections: {
|
||||
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||
// targets: [],
|
||||
// },
|
||||
},
|
||||
],
|
||||
speed: 1,
|
||||
});
|
||||
}
|
||||
// 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");
|
||||
res.send(getData);
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Server error", error });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user