199 lines
4.8 KiB
TypeScript
199 lines
4.8 KiB
TypeScript
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, versionId } = req.body;
|
|
if (!organization || !userId || !aisleUuid || !projectId || !versionId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const data = {
|
|
points,
|
|
type,
|
|
aisleUuid,
|
|
projectId,
|
|
versionId,
|
|
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 "Version Data not found":
|
|
res.status(404).json({
|
|
message: "Version Data 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, versionId } = req.body;
|
|
if (!organization || !userId || !aisleUuid || !projectId || !versionId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const data = {
|
|
aisleUuid,
|
|
projectId,
|
|
organization,
|
|
userId,
|
|
versionId,
|
|
};
|
|
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 "Version Data not found":
|
|
res.status(404).json({
|
|
message: "Version Data 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, versionId } = req.params;
|
|
if (!organization || !userId || !projectId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const data = {
|
|
projectId,
|
|
versionId,
|
|
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 "Version Data not found":
|
|
res.status(404).json({
|
|
message: "Version Data 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",
|
|
});
|
|
}
|
|
};
|