Testing failer uncomment issue sorted API-Docker updated based on the Failed testcase
This commit is contained in:
@@ -2,256 +2,233 @@ 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) {
|
||||
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({
|
||||
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" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user