Aisle and Simulation Product API and socket Completed
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
import { Response } from "express";
|
||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||
import {
|
||||
DeleteAisle,
|
||||
GetProjectAisles,
|
||||
SetAisle,
|
||||
} from "../../../../shared/services/builder/AisleService.ts";
|
||||
|
||||
export const UpsertAisleController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId } = req.user || {};
|
||||
const { aisleUuid, points, type, projectId } = req.body;
|
||||
if (!organization || !userId || !aisleUuid || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
points,
|
||||
type,
|
||||
aisleUuid,
|
||||
projectId,
|
||||
organization,
|
||||
userId,
|
||||
};
|
||||
const result = await SetAisle(data);
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Aisle Not Updated":
|
||||
res.status(200).json({
|
||||
message: "Aisle Not Updated",
|
||||
});
|
||||
break;
|
||||
case "Aisle Updated Successfully":
|
||||
res.status(200).json({
|
||||
message: "Aisle Updated Successfully",
|
||||
});
|
||||
break;
|
||||
case "Aisle Not Created":
|
||||
res.status(200).json({
|
||||
message: "Aisle Not Created",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message: "Aisle Created Successfully",
|
||||
});
|
||||
break;
|
||||
case "Aisle validation failed":
|
||||
res.status(200).json({
|
||||
message: "Aisle validation failed",
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
export const DeleteAisleController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId } = req.user || {};
|
||||
const { aisleUuid, projectId } = req.body;
|
||||
if (!organization || !userId || !aisleUuid || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
aisleUuid,
|
||||
projectId,
|
||||
organization,
|
||||
userId,
|
||||
};
|
||||
const result = await DeleteAisle(data);
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Aisle not found":
|
||||
res.status(200).json({
|
||||
message: "Aisle not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message: "Aisle Deleted Successfully",
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
export const AllAisleController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId } = req.user || {};
|
||||
const { projectId } = req.params;
|
||||
if (!organization || !userId || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
projectId,
|
||||
organization,
|
||||
userId,
|
||||
};
|
||||
const result = await GetProjectAisles(data);
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Aisle not found":
|
||||
res.status(200).json(result.data);
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json(result.data);
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user