Latest Project, Trash and setting API and sockets along with the Model clearance

This commit is contained in:
2025-05-17 10:12:18 +05:30
parent c64e5ea8b5
commit 0b30a8aeaa
66 changed files with 1109 additions and 2351 deletions

View File

@@ -1,182 +1,9 @@
import { Request, Response } from "express";
import assetModel from "../../../shared/model/builder/assets/asset-Model.ts";
import actionModel from "../../../shared/model/simulation/actionmodel.ts";
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
import pointModel from "../../../shared/model/builder/assets/assetPoint-Model.ts";
import EventsDataModel from "../../../shared/model/simulation/eventsDataModel.ts";
export class assetsFloorservice {
// static async setFloorassets(req: Request, res: Response): Promise<any> {
// try {
// const {
// modelUuid,
// modelName,
// position,
// modelfileID,
// rotation,
// isLocked,
// isVisible,
// organization,
// eventData,
// } = req.body;
// console.log("req.body: ", req.body);
// const findvalue = await assetModel(organization).findOne({
// modelUuid,
// // modelName,
// isArchive: false,
// });
// const checkpointType = await pointModel(organization).findOne({
// modelfileID: modelfileID,
// isArchive: false,
// });
// if (findvalue) {
// const updatevalue = await assetModel(organization).findOneAndUpdate(
// { modelUuid, isArchive: false },
// {
// modelName: modelName,
// position,
// rotation,
// isVisible,
// isLocked,
// },
// { new: true }
// );
// return res.status(201).json(updatevalue);
// } else {
// let assetData: any = {
// modelUuid,
// modelName,
// position,
// modelfileID,
// rotation,
// isLocked,
// isVisible,
// };
// console.log("eventData: ", eventData);
// if (eventData) {
// if (eventData.type === "Conveyor") {
// assetData.speed = eventData.speed;
// } else if (eventData.type === "Vehicle") {
// assetData.speed = eventData.points.speed;
// if (!eventData.points) {
// return res
// .status(400)
// .json({ message: "Vehicle points must be a single object" });
// }
// // if (eventData.points.rotation) {
// // return res.status(400).json({
// // message: "Rotation is not allowed for Vehicle points",
// // });
// // }
// if (eventData.points.triggers) {
// return res.status(400).json({
// message: "triggers is not allowed for Vehicle points",
// });
// }
// }
// // else if(eventData.type === "ArmBot"){
// // assetData.speed = eventData.position;
// // }else if(eventData.type === "StaticMachine"){
// // assetData.speed = eventData.position;
// // }
// assetData.points = eventData.points;
// assetData.type = eventData.type;
// }
// const assetDoc = await assetModel(organization).create(assetData);
// await assetDoc.save();
// return res.status(201).json({
// message: "Model stored successfully",
// modelId: assetDoc._id,
// });
// }
// } catch (error) {
// console.error("Error creating flooritems:", error);
// res.status(500).json({ message: "Failed to create flooritems" });
// }
// }
// static async getFloorItems(req: Request, res: Response): Promise<any> {
// try {
// const { organization } = req.params;
// const findValues = await assetModel(organization)
// .find({ isArchive: false })
// .select("-_id -isArchive");
// if (!findValues || findValues.length === 0) {
// return res.status(200).json({ message: "floorItems not found" });
// }
// const response = findValues.map((item) => {
// // console.log("item: ", item);
// // console.log("item: ", item.type);
// // console.log('findValues: ', findValues);
// // console.log("item.points: ", item.points);
// const responseItem: any = {
// modelUuid: item.modelUuid,
// modelName: item.modelName,
// position: item.position,
// rotation: item.rotation,
// modelfileID: item.modelfileID,
// isLocked: item.isLocked,
// isVisible: item.isVisible,
// };
// if (item.type === "Conveyor" && item.points.length > 0) {
// responseItem.eventData = {
// speed: item.speed,
// points: item.points,
// type: item.type,
// };
// }
// if (item.type === "Vehicle" && item.points) {
// responseItem.eventData = {
// type: item.type,
// points: item.points,
// };
// }
// if (item.type === "ArmBot" && item.points) {
// responseItem.eventData = {
// type: item.type,
// points: item.points,
// };
// }
// if (item.type === "StaticMachine" && item.points) {
// responseItem.eventData = {
// type: item.type,
// points: item.points,
// };
// }
// return responseItem;
// });
// return res.status(200).json(response);
// } catch (error) {
// res.status(500).json({ error: "Failed to get flooritems" });
// }
// }
// static async deleteFloorItems(req: Request, res: Response): Promise<any> {
// try {
// const { modelUuid, modelName, organization } = req.body;
// const findValue = await assetModel(organization).findOneAndDelete({
// modelUuid: modelUuid,
// modelName: modelName,
// isArchive: false,
// });
// if (!findValue) {
// res.status(200).json("user not found");
// } else {
// res.status(201).json(findValue);
// }
// } catch (error) {
// res.status(500).json({ error: "Failed to get flooritems" });
// }
// }
export class AssetsFloorService {
static async updateAssetPositionRotation(
req: Request,
res: Response
@@ -186,11 +13,11 @@ export class assetsFloorservice {
modelUuid,
modelName,
position,
modelfileID,
rotation,
isLocked,
isVisible,
organization,
// modelfileID, //optional
// eventData, // Optional
} = req.body;
@@ -244,7 +71,6 @@ export class assetsFloorservice {
return res.status(500).send(error.message);
}
}
//update setfoolrassets//getFloorItems//deleteFloorItems.........
static async setFloorassets(req: Request, res: Response): Promise<any> {
try {
const {
@@ -265,7 +91,7 @@ export class assetsFloorservice {
// modelName,
isArchive: false,
});
const checkpointType = await pointModel(organization).findOne({
await pointModel(organization).findOne({
modelfileID: modelfileID,
isArchive: false,
});
@@ -292,10 +118,9 @@ export class assetsFloorservice {
rotation,
isLocked,
isVisible,
eventData
eventData,
};
console.log("eventData: ", eventData);
if (eventData) {
if (eventData.type === "Conveyor") {
assetData.speed = eventData.speed;
@@ -306,24 +131,12 @@ export class assetsFloorservice {
.status(400)
.json({ message: "Vehicle points must be a single object" });
}
// if (eventData.points.rotation) {
// return res.status(400).json({
// message: "Rotation is not allowed for Vehicle points",
// });
// }
if (eventData.points.triggers) {
return res.status(400).json({
message: "triggers is not allowed for Vehicle points",
});
}
}
// else if(eventData.type === "ArmBot"){
// assetData.speed = eventData.position;
// }else if(eventData.type === "StaticMachine"){
// assetData.speed = eventData.position;
// }
assetData.points = eventData.points;
assetData.type = eventData.type;
}
@@ -352,10 +165,6 @@ export class assetsFloorservice {
}
const response = findValues.map((item) => {
// console.log("item: ", item);
// console.log("item: ", item.type);
// console.log('findValues: ', findValues);
// console.log("item.points: ", item.points);
const responseItem: any = {
modelUuid: item.modelUuid,
modelName: item.modelName,
@@ -366,36 +175,9 @@ export class assetsFloorservice {
isVisible: item.isVisible,
eventData: item.eventData,
};
// if (item.type === "Conveyor" && item.points.length > 0) {
// responseItem.eventData = {
// speed: item.speed,
// points: item.points,
// type: item.type,
// };
// }
// if (item.type === "Vehicle" && item.points) {
// responseItem.eventData = {
// type: item.type,
// points: item.points,
// };
// }
// if (item.type === "ArmBot" && item.points) {
// responseItem.eventData = {
// type: item.type,
// points: item.points,
// };
// }
// if (item.type === "StaticMachine" && item.points) {
// responseItem.eventData = {
// type: item.type,
// points: item.points,
// };
// }
return responseItem;
});
// console.log('response: ', response);
return res.status(200).json(response);
} catch (error) {
res.status(500).json({ error: "Failed to get flooritems" });
@@ -404,36 +186,35 @@ export class assetsFloorservice {
static async deleteFloorItems(req: Request, res: Response): Promise<any> {
try {
const { modelUuid, modelName, organization } = req.body;
console.log('req.body:', req.body);
const asset = await assetModel(organization).findOne({
modelUuid,
modelName,
isArchive: false,
});
if (!asset) {
return res.status(404).json({ message: "Model not found" });
}
const archivedAsset = await assetModel(organization).findOneAndUpdate(
{ modelUuid, modelName },
{ $set: { isArchive: true } },
{ new: true }
);
if (!archivedAsset) {
return res.status(500).json({ message: "Failed to archive asset" });
}
const updatedEvents = await EventsDataModel(organization).updateMany(
{ modelUuid },
{ $set: { isArchive: true } }
);
console.log("Archived asset:", archivedAsset);
console.log("Updated events:", updatedEvents.modifiedCount);
return res.status(200).json({ message: "delete Asset successfully" });
} catch (error) {
console.error("Error deleting floor items:", error);

View File

@@ -1,249 +0,0 @@
// import { Request, Response } from "express";
// // import assetModel from "../../../shared/model/assets/flooritems-Model.ts";
// import assetModel from "../../../shared/model/builder/assets/asset-Model.ts";
// import actionModel from "../../../shared/model/simulation/actionmodel.ts";
// import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
// import productFlowModel from "../../../shared/model/simulation/ProductFlowmodel.ts";
// export class productFlowservice {
// static async setproductFlow(req: Request, res: Response): Promise<any> {
// try {
// const {
// productName,
// modelUuid,
// modelName,
// eventData,
// organization,
// productID,
// } = req.body;
// // Validate required fields
// if (!modelUuid || !modelName || !organization) {
// return res.status(400).json({ message: "Missing required fields" });
// }
// // Check if asset exists
// const existingAsset = await assetModel(organization).findOne({
// modelUuid: modelUuid,
// isArchive: false,
// });
// if (!existingAsset) {
// return res.status(404).json({ message: "Asset not found for the ID" });
// }
// // Prepare point references
// let pointRefs: any[] = [];
// if (eventData?.points && Array.isArray(eventData.points)) {
// for (const point of eventData.points) {
// let actionRefs: any[] = [];
// let triggerRefs: any[] = [];
// // Process actions
// if (Array.isArray(point.actions)) {
// for (const action of point.actions) {
// const actionDoc = await actionModel(organization).create({
// pointsUUID: point.uuid,
// isArchive: false,
// uuid: action.uuid,
// name: action.name,
// type: action.type,
// material: action.material || null,
// delay: action.delay || null,
// spawn_Interval: action.spawn_Interval || null,
// });
// actionRefs.push({
// _id: actionDoc._id,
// ...action,
// });
// }
// }
// // Process triggers
// if (Array.isArray(point.triggers)) {
// for (const trigger of point.triggers) {
// const triggerDoc = await triggerModel(organization).create({
// pointsUUID: point.uuid,
// isArchive: false,
// uuid: trigger.uuid,
// name: trigger.name,
// type: trigger.type,
// bufferTime: trigger.bufferTime || null,
// });
// triggerRefs.push({
// _id: triggerDoc._id,
// ...trigger,
// });
// }
// }
// pointRefs.push({
// pointuuid: point.uuid,
// position: point.position || [],
// rotation: point.rotation || [],
// actions: actionRefs,
// triggers: triggerRefs,
// connections: point.connections || null,
// });
// }
// }
// // Check if product flow exists
// const existingproductData = await productFlowModel(organization).findOne({
// _id: productID,
// });
// let result;
// if (existingproductData) {
// // Update existing product flow
// result = await productFlowModel(organization).findOneAndUpdate(
// { _id: productID },
// {
// $push: {
// ProductData: {
// AssetName: modelName,
// Assetuuid: modelUuid,
// paths: {
// Points: pointRefs,
// },
// isArchive: false,
// },
// },
// },
// { new: true }
// );
// } else {
// // Create new product flow
// result = await productFlowModel(organization).create({
// _id: productID,
// productName: productName,
// ProductData: [
// {
// AssetName: modelName,
// Assetuuid: modelUuid,
// paths: {
// Points: pointRefs,
// },
// isArchive: false,
// },
// ],
// eventType: eventData?.type || null,
// speed: eventData?.speed || null,
// });
// }
// res.status(201).json({
// message: "Product flow processed successfully",
// data: result,
// });
// } catch (error) {
// console.error("Error creating flooritems:", error);
// res.status(500).json({ message: "Failed to create flooritems" });
// }
// }
// static async pointActionList(req: Request, res: Response): Promise<any> {}
// static async productpathsList(req: Request, res: Response): Promise<any> {
// try {
// const { organization } = req.params;
// const productFlowList = await productFlowModel(organization)
// .find()
// .select("ProductData productName -_id")
// .exec();
// const formattedData = await Promise.all(
// productFlowList.map(async (item) => ({
// productName: item.productName,
// paths: await Promise.all(
// item.ProductData.map(async (data: any) => ({
// Points: await Promise.all(
// data.paths.Points.map(async (point: any) => {
// const actions = await actionModel(organization)
// .find({ _id: { $in: point.actions } })
// .select(
// "-_id -pointsUUID -isArchive -createdAt -updatedAt -__v"
// )
// .lean();
// const triggers = await triggerModel(organization)
// .find({ _id: { $in: point.triggers } })
// .select(
// "-_id -pointsUUID -isArchive -createdAt -updatedAt -__v"
// )
// .lean();
// return {
// connections: point.connections || null,
// pointuuid: point.pointuuid,
// actions: actions,
// triggers: triggers,
// position: point.position,
// rotation: point.rotation,
// };
// })
// ),
// }))
// ),
// }))
// );
// return res.status(200).json(formattedData);
// } catch (error) {
// console.error("Error get flooritems:", error);
// res.status(500).json({ error: "Failed to get flooritems" });
// }
// }
// // static async deleteFloorItems(req: Request, res: Response): Promise<any> {
// // try {
// // const { modelUuid, modelName, organization } = req.body;
// // const findValue = await assetModel(organization).findOneAndDelete({
// // modelUuid: modelUuid,
// // modelName: modelName,
// // isArchive: false,
// // });
// // if (!findValue) {
// // res.status(200).json("user not found");
// // } else {
// // res.status(201).json(findValue);
// // }
// // } catch (error) {
// // console.error("Error get flooritems:", error);
// // res.status(500).json({ error: "Failed to get flooritems" });
// // }
// // }
// // static async updateAssetPositionRotation(
// // req: Request,
// // res: Response
// // ): Promise<any> {
// // try {
// // const {
// // modelUuid,
// // modelName,
// // position,
// // modelfileID,
// // rotation,
// // isLocked,
// // isVisible,
// // organization,
// // // eventData, // Optional
// // } = req.body;
// // const existingAsset = await assetModel(organization).findOne({
// // modelUuid: modelUuid,
// // isArchive: false,
// // });
// // if (!existingAsset) return res.send("Asset not found");
// // const updateAsset = await assetModel(organization).updateMany(
// // { modelUuid: modelUuid, modelName: modelName, isArchive: false },
// // {
// // position: position,
// // rotation: rotation,
// // isVisible: isVisible,
// // isLocked: isLocked,
// // }
// // );
// // if (updateAsset)
// // return res.status(200).json({ message: "Asset updated successfully" });
// // } catch (error: any) {
// // return res.send(error.message);
// // }
// // }
// // static async updateActionsDatas(req: Request, res: Response) {}
// }

View File

@@ -2,256 +2,237 @@ import { Request, Response } from "express";
import ProductModel from "../../../shared/model/simulation/productModel.ts";
import EventsDataModel from "../../../shared/model/simulation/eventsDataModel.ts";
export class productFlowservice {
static async productAdd(req: Request, res: Response): Promise<any> {
try {
const { productName, productId, eventDatas, organization } = req.body;
if (!organization) {
return res
.json({ message: "organization not found" });
export class ProductFlowservice {
static async productAdd(req: Request, res: Response): Promise<any> {
try {
const { productName, productId, eventDatas, organization } = req.body;
if (!organization) {
return res.json({ message: "organization not found" });
}
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
isArchive: false,
});
if (existingProduct) {
const existingEventData = await EventsDataModel(organization).findOne({
productId: productId,
modelUuid: eventDatas.modelUuid,
isArchive: false,
});
if (existingEventData) {
await EventsDataModel(organization).findOneAndUpdate(
{
modelUuid: eventDatas.modelUuid,
productId: productId,
isArchive: false,
},
{
modelUuid: eventDatas?.modelUuid,
modelName: eventDatas?.modelName,
position: eventDatas?.position,
rotation: eventDatas?.rotation,
type: eventDatas?.type,
speed: eventDatas?.speed,
point: eventDatas?.point,
points: eventDatas?.points,
}
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
isArchive: false,
})
if (existingProduct) {
const existingEventData = await EventsDataModel(organization).findOne(
{
productId: productId,
modelUuid: eventDatas.modelUuid,
isArchive: false,
})
if (existingEventData) {
const updateEventData = await EventsDataModel(organization).findOneAndUpdate(
{
modelUuid: eventDatas.modelUuid,
productId: productId,
isArchive: false,
}
, {
modelUuid: eventDatas?.modelUuid,
modelName: eventDatas?.modelName,
position: eventDatas?.position,
rotation: eventDatas?.rotation,
type: eventDatas?.type,
speed: eventDatas?.speed,
point: eventDatas?.point,
points: eventDatas?.points,
})
return res
.status(200)
.json({ message: "EventData updated successfully" });
} else {
const addEventData = await EventsDataModel(organization).create({
productId: productId,
modelUuid: eventDatas?.modelUuid,
modelName: eventDatas?.modelName,
position: eventDatas?.position,
rotation: eventDatas?.rotation,
type: eventDatas?.type,
speed: eventDatas?.speed,
point: eventDatas?.point,
points: eventDatas?.points
})
return res
.status(201)
.json({ message: "EventData add successfully" });
}
} else {
const newProduct = await ProductModel(organization).create({
productId: productId,
productName: productName
})
if (newProduct) {
if (eventDatas) {
const addEventData = await EventsDataModel(organization).create({
productId: productId,
modelUuid: eventDatas?.modelUuid,
modelName: eventDatas?.modelName,
position: eventDatas?.position,
rotation: eventDatas?.rotation,
type: eventDatas?.type,
speed: eventDatas?.speed,
point: eventDatas?.point,
points: eventDatas?.points,
})
}
}
return res
.status(201)
.json({ message: "Product created successfully" });
}
} catch (error) {
res.status(500).json({ message: "Failed to create product" });
);
return res
.status(200)
.json({ message: "EventData updated successfully" });
} else {
await EventsDataModel(organization).create({
productId: productId,
modelUuid: eventDatas?.modelUuid,
modelName: eventDatas?.modelName,
position: eventDatas?.position,
rotation: eventDatas?.rotation,
type: eventDatas?.type,
speed: eventDatas?.speed,
point: eventDatas?.point,
points: eventDatas?.points,
});
return res
.status(201)
.json({ message: "EventData add successfully" });
}
}
static async getProductDatas(req: Request, res: Response): Promise<any> {
try {
const { productId, organization } = req.query
if (typeof productId !== "string" || typeof organization !== "string") {
return res.status(400).json({ message: "Missing or invalid query parameters" });
}
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
isArchive: false,
})
if (!existingProduct)
return res.status(404).json({ message: "Product not found" });
const existingEventDatas = await EventsDataModel(organization).find({ productId: productId }).select("-productId")
return res
.status(200)
.json(existingEventDatas);
} catch (error) {
res.status(500).json({ message: "Failed to get product" });
} else {
const newProduct = await ProductModel(organization).create({
productId: productId,
productName: productName,
});
if (newProduct) {
if (eventDatas) {
await EventsDataModel(organization).create({
productId: productId,
modelUuid: eventDatas?.modelUuid,
modelName: eventDatas?.modelName,
position: eventDatas?.position,
rotation: eventDatas?.rotation,
type: eventDatas?.type,
speed: eventDatas?.speed,
point: eventDatas?.point,
points: eventDatas?.points,
});
}
}
return res
.status(201)
.json({ message: "Product created successfully" });
}
} catch (error) {
res.status(500).json({ message: "Failed to create product" });
}
static async productDataDelete(req: Request, res: Response): Promise<any> {
try {
const { productId, organization } = req.query
if (typeof productId !== "string" || typeof organization !== "string") {
return res.status(400).json({ message: "Missing or invalid query parameters" });
}
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
isArchive: false,
})
}
static async getProductDatas(req: Request, res: Response): Promise<any> {
try {
const { productId, organization } = req.query;
if (typeof productId !== "string" || typeof organization !== "string") {
return res
.status(400)
.json({ message: "Missing or invalid query parameters" });
}
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
isArchive: false,
});
if (!existingProduct)
return res.status(404).json({ message: "Product not found" });
if (!existingProduct)
return res.status(404).json({ message: "Product not found" });
const productDelete = await ProductModel(organization).findOneAndUpdate(
{ productId: productId },
{
isArchive: true,
}, { new: true }
)
const existingEventDatas = await EventsDataModel(organization).find({ productId: productId })
if (existingEventDatas) {
for (const event of existingEventDatas) {
await EventsDataModel(organization).updateMany(
{ productId },
{ $set: { isArchive: true } }
);
}
}
return res.status(201).json({ message: "product deleted successfully" });
} catch (error) {
res.status(500).json({ message: "Failed to delete product" });
}
const existingEventDatas = await EventsDataModel(organization)
.find({ productId: productId })
.select("-productId");
return res.status(200).json(existingEventDatas);
} catch (error) {
res.status(500).json({ message: "Failed to get product" });
}
static async EventDataDelete(req: Request, res: Response): Promise<any> {
try {
const { productId, organization, modelUuid } = req.body
}
static async productDataDelete(req: Request, res: Response): Promise<any> {
try {
const { productId, organization } = req.query;
if (typeof productId !== "string" || typeof organization !== "string") {
return res
.status(400)
.json({ message: "Missing or invalid query parameters" });
}
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
isArchive: false,
});
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
isArchive: false,
})
if (!existingProduct)
return res.status(404).json({ message: "Product not found" });
const existingEventDatas = await EventsDataModel(organization).findOneAndUpdate(
{ productId: productId, modelUuid: modelUuid }, {
isArchive: true,
}, { new: true }
)
return res.status(201).json({ message: "EventData deleted successfully" });
} catch (error) {
res.status(500).json({ message: "Failed to delete Eventdata" });
}
if (!existingProduct)
return res.status(404).json({ message: "Product not found" });
await ProductModel(organization).findOneAndUpdate(
{ productId: productId },
{
isArchive: true,
},
{ new: true }
);
const existingEventDatas = await EventsDataModel(organization).find({
productId: productId,
});
if (existingEventDatas) {
// for (const event of existingEventDatas) {
await EventsDataModel(organization).updateMany(
{ productId },
{ $set: { isArchive: true } }
);
// }
}
return res.status(201).json({ message: "product deleted successfully" });
} catch (error) {
res.status(500).json({ message: "Failed to delete product" });
}
static async AllProductDatas(req: Request, res: Response): Promise<any> {
try {
const { organization } = req.params
}
static async EventDataDelete(req: Request, res: Response): Promise<any> {
try {
const { productId, organization, modelUuid } = req.body;
if (!organization) {
return res
.json({ message: "organization not found" });
}
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
isArchive: false,
});
const existingProduct = await ProductModel(organization).find({
isArchive: false,
})
if (!existingProduct) {
return res.status(404).json({ message: 'No products found' });
}
const result = [];
if (!existingProduct)
return res.status(404).json({ message: "Product not found" });
for (const product of existingProduct) {
// Fetch events data for each product, excluding productId field
const eventDatas = await EventsDataModel(organization)
.find({ productId: product.productId, isArchive: false })
.select("-productId -isArchive -createdAt -updatedAt -__v -_id");
// Combine product and event data
result.push({
// product: {
productName: product.productName,
productId: product.productId,
eventDatas,
// },
});
}
// Return combined data
return res.status(200).json(result);
} catch (error) {
res.status(500).json({ message: "Failed to get Allproduct" });
}
await EventsDataModel(organization).findOneAndUpdate(
{ productId: productId, modelUuid: modelUuid },
{
isArchive: true,
},
{ new: true }
);
return res
.status(201)
.json({ message: "EventData deleted successfully" });
} catch (error) {
res.status(500).json({ message: "Failed to delete Eventdata" });
}
static async productRename(req: Request, res: Response): Promise<any> {
}
static async AllProductDatas(req: Request, res: Response): Promise<any> {
try {
const { organization } = req.params;
try {
const { productId, productName, organization } = req.body
if (!organization) {
return res.json({ message: "organization not found" });
}
const existingProduct = await ProductModel(organization).find({
isArchive: false,
});
if (!existingProduct) {
return res.status(404).json({ message: "No products found" });
}
const result = [];
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
isArchive: false,
})
for (const product of existingProduct) {
const eventDatas = await EventsDataModel(organization)
.find({ productId: product.productId, isArchive: false })
.select("-productId -isArchive -createdAt -updatedAt -__v -_id");
if (!existingProduct)
return res.status(404).json({ message: "Product not found" });
const productDelete = await ProductModel(organization).findOneAndUpdate(
{ productId: productId },
{
productName: productName,
}, { new: true }
)
return res.status(201).json({ message: "product Rename successfully" });
} catch (error) {
res.status(500).json({ message: "Failed to product Rename" });
}
result.push({
// product: {
productName: product.productName,
productId: product.productId,
eventDatas,
// },
});
}
return res.status(200).json(result);
} catch (error) {
res.status(500).json({ message: "Failed to get Allproduct" });
}
}
static async productRename(req: Request, res: Response): Promise<any> {
try {
const { productId, productName, organization } = req.body;
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
isArchive: false,
});
if (!existingProduct)
return res.status(404).json({ message: "Product not found" });
await ProductModel(organization).findOneAndUpdate(
{ productId: productId },
{
productName: productName,
},
{ new: true }
);
return res.status(201).json({ message: "product Rename successfully" });
} catch (error) {
res.status(500).json({ message: "Failed to product Rename" });
}
}
}