merged with main branch to clear the testing commits
This commit is contained in:
@@ -194,7 +194,6 @@ export const AuthLogin = async (
|
||||
name: existingMail.userName,
|
||||
userId: existingMail._id,
|
||||
isShare: UserData.isShare,
|
||||
// updatedUser: updatedUser as IUser,
|
||||
token: tokenValidation,
|
||||
refreshToken: refreshTokenvalidation,
|
||||
};
|
||||
|
||||
@@ -11,7 +11,6 @@ type MulterFile = {
|
||||
|
||||
const bucketName = "assets-public-bucket";
|
||||
|
||||
// Define public read policy
|
||||
const publicReadPolicy = {
|
||||
Version: "2012-10-17",
|
||||
Statement: [
|
||||
@@ -35,7 +34,7 @@ async function ensureBucketExists() {
|
||||
async function ensureFolderExists(folderName: string) {
|
||||
const folderPrefix = folderName.endsWith("/") ? folderName : `${folderName}/`;
|
||||
const objects = minioClient.listObjects(bucketName, folderPrefix, true);
|
||||
for await (const _ of objects) return; // Folder exists
|
||||
for await (const _ of objects) return;
|
||||
await minioClient.putObject(bucketName, folderPrefix, Buffer.from(""));
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
interface setAssetInput {
|
||||
modelUuid: string;
|
||||
modelName: string;
|
||||
position: []; // user ID
|
||||
position: [];
|
||||
rotation: object;
|
||||
eventData: Mixed;
|
||||
modelfileID: string;
|
||||
@@ -22,7 +22,7 @@ interface setAssetInput {
|
||||
interface AssetUpdate {
|
||||
modelUuid: string;
|
||||
modelName: string;
|
||||
position: []; // user ID
|
||||
position: [];
|
||||
rotation: object;
|
||||
isLocked: boolean;
|
||||
isVisible: boolean;
|
||||
@@ -98,12 +98,7 @@ export const setAssetModel = async (
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
// return {
|
||||
// success: true,
|
||||
// message: "Model updated successfully",
|
||||
// data: updatevalue,
|
||||
// organization: organization,
|
||||
// };
|
||||
|
||||
return {
|
||||
status: "Updated successfully",
|
||||
data: updatevalue,
|
||||
@@ -121,21 +116,6 @@ export const setAssetModel = async (
|
||||
isVisible,
|
||||
};
|
||||
|
||||
// if (eventData) {
|
||||
// if (eventData?.type === "Conveyor") {
|
||||
// assetData.eventData = {
|
||||
// type: eventData.type,
|
||||
// // point:undefined,
|
||||
// points: eventData.points,
|
||||
// };
|
||||
// } else {
|
||||
// assetData.eventData = {
|
||||
// type: eventData.type,
|
||||
// point: eventData.point,
|
||||
// // points: undefined
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
if (eventData) {
|
||||
const typedEventData = eventData as unknown as {
|
||||
type: string;
|
||||
@@ -254,12 +234,7 @@ export const setAssetModel = async (
|
||||
isVisible: assetDoc.isVisible,
|
||||
};
|
||||
}
|
||||
// return {
|
||||
// success: true,
|
||||
// message: "Model created successfully",
|
||||
// data: assetDatas,
|
||||
// organization: organization,
|
||||
// };
|
||||
|
||||
return {
|
||||
status: "Success",
|
||||
data: assetDatas,
|
||||
@@ -307,11 +282,6 @@ export const deleteAssetModel = async (
|
||||
{ new: true }
|
||||
);
|
||||
if (!archivedAsset) {
|
||||
// return {
|
||||
// success: false,
|
||||
// status: "Failed to archive asset",
|
||||
// organization: organization,
|
||||
// };
|
||||
return {
|
||||
status: "Failed to archive asset",
|
||||
};
|
||||
@@ -321,13 +291,6 @@ export const deleteAssetModel = async (
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
|
||||
// return {
|
||||
// success: true,
|
||||
// message: "Model deleted successfully",
|
||||
// data: archivedAsset,
|
||||
// organization: organization,
|
||||
// };
|
||||
|
||||
return {
|
||||
status: "Success",
|
||||
data: archivedAsset,
|
||||
@@ -364,11 +327,6 @@ export const replaceEventDatas = async (
|
||||
});
|
||||
if (!existingModel) {
|
||||
return { status: "Model not for this UUID" };
|
||||
// return {
|
||||
// success: false,
|
||||
// message: "Model not for this UUID",
|
||||
// organization: organization,
|
||||
// };
|
||||
} else {
|
||||
const typedEventData = eventData as unknown as {
|
||||
speed: number;
|
||||
@@ -384,23 +342,11 @@ export const replaceEventDatas = async (
|
||||
{ modelUuid, projectId, isArchive: false },
|
||||
{
|
||||
points: typedEventData?.points,
|
||||
// speed: speed,
|
||||
type: typedEventData?.type || existingModel?.type,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
// if (updatedModel)
|
||||
// // return {
|
||||
// // success: true,
|
||||
// // message: "Data updated successfully",
|
||||
// // data: updatedModel,
|
||||
// // organization: organization,
|
||||
// // };
|
||||
// return {
|
||||
// status: "Success",
|
||||
// data: updatedModel,
|
||||
// };
|
||||
return {
|
||||
status: "Success",
|
||||
data: updatedModel,
|
||||
@@ -448,7 +394,6 @@ export const updateAssetPositionRotation = async (
|
||||
});
|
||||
if (!existingAsset) {
|
||||
return { status: "Asset not found" };
|
||||
// return res.send("Asset not found");
|
||||
}
|
||||
const updateAsset = await assetModel(organization).updateMany(
|
||||
{
|
||||
@@ -464,12 +409,10 @@ export const updateAssetPositionRotation = async (
|
||||
isLocked: isLocked,
|
||||
}
|
||||
);
|
||||
// if (updateAsset)
|
||||
return {
|
||||
status: "Success",
|
||||
data: updateAsset,
|
||||
};
|
||||
// return res.status(200).json({ message: "Asset updated successfully" });
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
@@ -501,7 +444,6 @@ export const getFloorItems = async (
|
||||
|
||||
if (!findValues || findValues.length === 0) {
|
||||
return { status: "floorItems not found" };
|
||||
// return res.status(200).json({ message: "floorItems not found" });
|
||||
}
|
||||
|
||||
const response = findValues.map((item) => {
|
||||
@@ -519,8 +461,6 @@ export const getFloorItems = async (
|
||||
return responseItem;
|
||||
});
|
||||
|
||||
// return res.status(200).json(response);
|
||||
|
||||
return {
|
||||
status: "Success",
|
||||
data: response,
|
||||
|
||||
@@ -68,13 +68,12 @@ export const setWallItems = async (data: IWallSetupData): Promise<IWallItemResul
|
||||
quaternion,
|
||||
scale,
|
||||
},
|
||||
{ new: true } // Return the updated document
|
||||
{ new: true }
|
||||
);
|
||||
return {
|
||||
status: "Updated successfully",
|
||||
data: updatevalue,
|
||||
};
|
||||
// res.status(201).json(updatevalue);
|
||||
} else {
|
||||
const newValue = await wallItemModel(organization).create({
|
||||
modelUuid,
|
||||
@@ -91,7 +90,6 @@ export const setWallItems = async (data: IWallSetupData): Promise<IWallItemResul
|
||||
status: "wall Item created successfully",
|
||||
data: newValue,
|
||||
};
|
||||
// res.status(201).json(newValue);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
|
||||
@@ -42,7 +42,7 @@ export const previousVersion = async (
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
// .sort({ version: -1 });
|
||||
|
||||
return result;
|
||||
};
|
||||
export const generateUntitledProjectName = async (
|
||||
|
||||
@@ -45,7 +45,7 @@ export const previousVersion = async (
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
// .sort({ version: -1 });
|
||||
|
||||
return result;
|
||||
};
|
||||
export const generateUntitledProjectName = async (
|
||||
|
||||
@@ -56,7 +56,7 @@ export const searchProject = async (data: searchProjectInterface) => {
|
||||
const userExisting = await existingUser(userId, organization);
|
||||
if (!userExisting) return { status: "User not found" };
|
||||
const findprojectName = await projectModel(organization).find({
|
||||
projectName: { $regex: `${searchName}`, $options: "i" }, // 'i' makes it case-insensitive
|
||||
projectName: { $regex: `${searchName}`, $options: "i" },
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findprojectName || findprojectName.length === 0)
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
interface CreateProjectInput {
|
||||
projectName: string;
|
||||
projectUuid: string;
|
||||
userId: string; // user ID
|
||||
userId: string;
|
||||
thumbnail?: string;
|
||||
sharedUsers?: string[];
|
||||
organization: string;
|
||||
@@ -19,7 +19,7 @@ interface CreateProjectInput {
|
||||
interface updateProjectInput {
|
||||
projectName: string;
|
||||
projectId: string;
|
||||
userId: string; // user ID
|
||||
userId: string;
|
||||
thumbnail?: string;
|
||||
sharedUsers?: string[];
|
||||
organization: string;
|
||||
|
||||
@@ -1,375 +1,364 @@
|
||||
import { Mixed } from "mongoose";
|
||||
import EventsDataModel from "../../V1Models/Simulation/eventsDataModel.ts";
|
||||
import ProductModel from "../../V1Models/Simulation/productModel.ts";
|
||||
import { existingProjectById, existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||
import {
|
||||
existingProjectById,
|
||||
existingUser,
|
||||
} from "../helpers/v1projecthelperFns.ts";
|
||||
|
||||
interface Iproduct {
|
||||
productName: string;
|
||||
productId: string;
|
||||
eventDatas: {
|
||||
modelUuid: string
|
||||
modelName: string
|
||||
position: [Number]
|
||||
rotation: [Number]
|
||||
type: string
|
||||
speed: string
|
||||
point: Mixed
|
||||
points: Mixed
|
||||
};
|
||||
userId: string;
|
||||
organization: string;
|
||||
projectId: string;
|
||||
productName: string;
|
||||
productId: string;
|
||||
eventDatas: {
|
||||
modelUuid: string;
|
||||
modelName: string;
|
||||
position: [Number];
|
||||
rotation: [Number];
|
||||
type: string;
|
||||
speed: string;
|
||||
point: Mixed;
|
||||
points: Mixed;
|
||||
};
|
||||
userId: string;
|
||||
organization: string;
|
||||
projectId: string;
|
||||
}
|
||||
interface IResult {
|
||||
status: string;
|
||||
data?: object;
|
||||
status: string;
|
||||
data?: object;
|
||||
}
|
||||
interface IEventDataDelete {
|
||||
productId: string;
|
||||
modelUuid: string
|
||||
userId: string;
|
||||
organization: string;
|
||||
projectId: string;
|
||||
productId: string;
|
||||
modelUuid: string;
|
||||
userId: string;
|
||||
organization: string;
|
||||
projectId: string;
|
||||
}
|
||||
export const productAdd = async (data: Iproduct): Promise<IResult> => {
|
||||
try {
|
||||
const { productName, productId, eventDatas, projectId, userId, organization } = data
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId, projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingProduct) {
|
||||
const existingEventData = await EventsDataModel(organization).findOne({
|
||||
productId: productId,
|
||||
projectId: projectId,
|
||||
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,
|
||||
}
|
||||
);
|
||||
return {
|
||||
status: "EventData updated successfully"
|
||||
}
|
||||
// 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 {
|
||||
status: "EventData add successfully"
|
||||
}
|
||||
// return res
|
||||
// .status(201)
|
||||
// .json({ message: "EventData add successfully" });
|
||||
}
|
||||
} 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 {
|
||||
status: "Success"
|
||||
}
|
||||
// return res
|
||||
// .status(201)
|
||||
// .json({ message: "Product created successfully" });
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
export const getProductDatas = async (data: Iproduct): Promise<IResult> => {
|
||||
try {
|
||||
const { productId, projectId, userId, organization } = data
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId, projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProduct)
|
||||
return { status: "Product not found" };
|
||||
// return res.status(404).json({ message: "Product not found" });
|
||||
|
||||
const existingEventDatas = await EventsDataModel(organization)
|
||||
.find({ productId: productId, projectId: projectId })
|
||||
.select("-productId");
|
||||
return { status: "Success", data: existingEventDatas };
|
||||
// return res.status(200).json(existingEventDatas);
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
export const productDataDelete = async (data: Iproduct): Promise<IResult> => {
|
||||
try {
|
||||
const { productId, projectId, userId, organization } = data
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProduct)
|
||||
return { status: "Product not found" };
|
||||
// return res.status(404).json({ message: "Product not found" });
|
||||
|
||||
await ProductModel(organization).findOneAndUpdate(
|
||||
{ productId: productId, projectId: projectId },
|
||||
{
|
||||
isArchive: true,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
const existingEventDatas = await EventsDataModel(organization).find({
|
||||
productId: productId,
|
||||
});
|
||||
if (existingEventDatas) {
|
||||
await EventsDataModel(organization).updateMany(
|
||||
{ productId, projectId },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
}
|
||||
return {
|
||||
status: "Success",
|
||||
// data: assetDatas,
|
||||
};
|
||||
// return res.status(201).json({ message: "product deleted successfully" });
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
export const EventDataDelete = async (data: IEventDataDelete): Promise<IResult> => {
|
||||
try {
|
||||
const { modelUuid, productId, projectId, userId, organization } = data
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId, projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProduct)
|
||||
return { status: "Product not found" };
|
||||
// return res.status(404).json({ message: "Product not found" });
|
||||
try {
|
||||
const {
|
||||
productName,
|
||||
productId,
|
||||
eventDatas,
|
||||
projectId,
|
||||
userId,
|
||||
organization,
|
||||
} = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingProduct) {
|
||||
const existingEventData = await EventsDataModel(organization).findOne({
|
||||
productId: productId,
|
||||
projectId: projectId,
|
||||
modelUuid: eventDatas.modelUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingEventData) {
|
||||
await EventsDataModel(organization).findOneAndUpdate(
|
||||
{ productId: productId, projectId: projectId, modelUuid: modelUuid },
|
||||
{
|
||||
isArchive: true,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
// return res
|
||||
// .status(201)
|
||||
// .json({ message: "EventData deleted successfully" });
|
||||
return {
|
||||
status: "Success",
|
||||
// data: assetDatas,
|
||||
};
|
||||
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
export const AllProductDatas = async (data: IEventDataDelete): Promise<IResult> => {
|
||||
try {
|
||||
const { projectId, userId, organization } = data
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingProduct = await ProductModel(organization).find({
|
||||
{
|
||||
modelUuid: eventDatas.modelUuid,
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingProduct) {
|
||||
// return res.status(404).json({ message: "No products found" });
|
||||
return {
|
||||
status: "No products found",
|
||||
// data: result,
|
||||
};
|
||||
}
|
||||
const result = [];
|
||||
|
||||
for (const product of existingProduct) {
|
||||
const eventDatas = await EventsDataModel(organization)
|
||||
.find({ projectId: product.projectId, productId: product.productId, isArchive: false })
|
||||
.select("-productId -isArchive -createdAt -updatedAt -__v -_id");
|
||||
|
||||
result.push({
|
||||
// product: {
|
||||
projectId: product.projectId,
|
||||
productName: product.productName,
|
||||
productId: product.productId,
|
||||
eventDatas,
|
||||
// },
|
||||
});
|
||||
}
|
||||
|
||||
// return res.status(200).json(result);
|
||||
},
|
||||
{
|
||||
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 {
|
||||
status: "Success",
|
||||
data: result,
|
||||
status: "EventData updated successfully",
|
||||
};
|
||||
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
} 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 {
|
||||
status: "EventData add successfully",
|
||||
};
|
||||
}
|
||||
} 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 {
|
||||
status: "Success",
|
||||
};
|
||||
}
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
export const getProductDatas = async (data: Iproduct): Promise<IResult> => {
|
||||
try {
|
||||
const { productId, projectId, userId, organization } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProduct) return { status: "Product not found" };
|
||||
|
||||
const existingEventDatas = await EventsDataModel(organization)
|
||||
.find({ productId: productId, projectId: projectId })
|
||||
.select("-productId");
|
||||
return { status: "Success", data: existingEventDatas };
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
export const productDataDelete = async (data: Iproduct): Promise<IResult> => {
|
||||
try {
|
||||
const { productId, projectId, userId, organization } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProduct) return { status: "Product not found" };
|
||||
|
||||
await ProductModel(organization).findOneAndUpdate(
|
||||
{ productId: productId, projectId: projectId },
|
||||
{
|
||||
isArchive: true,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
const existingEventDatas = await EventsDataModel(organization).find({
|
||||
productId: productId,
|
||||
});
|
||||
if (existingEventDatas) {
|
||||
await EventsDataModel(organization).updateMany(
|
||||
{ productId, projectId },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
}
|
||||
return {
|
||||
status: "Success",
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
export const EventDataDelete = async (
|
||||
data: IEventDataDelete
|
||||
): Promise<IResult> => {
|
||||
try {
|
||||
const { modelUuid, productId, projectId, userId, organization } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProduct) return { status: "Product not found" };
|
||||
await EventsDataModel(organization).findOneAndUpdate(
|
||||
{ productId: productId, projectId: projectId, modelUuid: modelUuid },
|
||||
{
|
||||
isArchive: true,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
return {
|
||||
status: "Success",
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
export const AllProductDatas = async (
|
||||
data: IEventDataDelete
|
||||
): Promise<IResult> => {
|
||||
try {
|
||||
const { projectId, userId, organization } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingProduct = await ProductModel(organization).find({
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingProduct) {
|
||||
return {
|
||||
status: "No products found",
|
||||
};
|
||||
}
|
||||
const result = [];
|
||||
|
||||
for (const product of existingProduct) {
|
||||
const eventDatas = await EventsDataModel(organization)
|
||||
.find({
|
||||
projectId: product.projectId,
|
||||
productId: product.productId,
|
||||
isArchive: false,
|
||||
})
|
||||
.select("-productId -isArchive -createdAt -updatedAt -__v -_id");
|
||||
|
||||
result.push({
|
||||
projectId: product.projectId,
|
||||
productName: product.productName,
|
||||
productId: product.productId,
|
||||
eventDatas,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
status: "Success",
|
||||
data: result,
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
export const productRename = async (data: Iproduct): Promise<IResult> => {
|
||||
try {
|
||||
const { productName, productId, projectId, userId, organization } = data
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId, projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
try {
|
||||
const { productName, productId, projectId, userId, organization } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProduct)
|
||||
return { status: "Product not found" };
|
||||
if (!existingProduct) return { status: "Product not found" };
|
||||
|
||||
await ProductModel(organization).findOneAndUpdate(
|
||||
{ productId: productId },
|
||||
{
|
||||
productName: productName,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
await ProductModel(organization).findOneAndUpdate(
|
||||
{ productId: productId },
|
||||
{
|
||||
productName: productName,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
// return res.status(201).json({ message: "product Rename successfully" });
|
||||
return {
|
||||
status: "Success",
|
||||
// data: assetDatas,
|
||||
};
|
||||
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: "Success",
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ import UsersDataModel from "../../V1Models/Auth/user.ts";
|
||||
interface CreateProjectInput {
|
||||
projectName: string;
|
||||
projectUuid: string;
|
||||
userId: string; // user ID
|
||||
userId: string;
|
||||
thumbnail?: string;
|
||||
sharedUsers?: string[];
|
||||
organization: string;
|
||||
@@ -19,7 +19,7 @@ interface CreateProjectInput {
|
||||
interface IProjectDuplicate {
|
||||
projectName: string;
|
||||
projectUuid: string;
|
||||
userId: string; // user ID
|
||||
userId: string;
|
||||
thumbnail?: string;
|
||||
sharedUsers?: string[];
|
||||
organization: string;
|
||||
@@ -27,7 +27,7 @@ interface IProjectDuplicate {
|
||||
interface updateProjectInput {
|
||||
projectName: string;
|
||||
projectId: string;
|
||||
userId: string; // user ID
|
||||
userId: string;
|
||||
thumbnail?: string;
|
||||
sharedUsers?: string[];
|
||||
organization: string;
|
||||
@@ -116,9 +116,7 @@ export const GetAllProjects = async (data: GetProjectsInterface) => {
|
||||
await existingUser(userId, organization);
|
||||
if (!existingUser) return { status: "User not found" };
|
||||
let filter = { isArchive: false } as RoleFilter;
|
||||
// if (role === "User") {
|
||||
// filter.createdBy = userId;
|
||||
// }
|
||||
|
||||
const projectDatas = await projectModel(organization)
|
||||
.find(filter)
|
||||
.select("_id projectName createdBy thumbnail createdAt projectUuid");
|
||||
@@ -135,9 +133,7 @@ export const DeleteProject = async (data: ProjectDelInterface) => {
|
||||
if (!ExistingUser) return { status: "User not found" };
|
||||
|
||||
let filter = { _id: projectId, isArchive: false } as RoleFilter;
|
||||
// if (role === "User") {
|
||||
// filter.createdBy = userId;
|
||||
// }
|
||||
|
||||
const existingProject = await projectModel(organization).findOne(filter);
|
||||
console.log("existingProject: ", existingProject);
|
||||
if (!existingProject) return { status: "Project not found" };
|
||||
@@ -158,9 +154,7 @@ export const updateProject = async (data: updateProjectInput) => {
|
||||
const ExistingUser = await existingUser(userId, organization);
|
||||
if (!ExistingUser) return { status: "User not found" };
|
||||
let filter = { _id: projectId, isArchive: false } as RoleFilter;
|
||||
// if (role === "User") {
|
||||
// filter.createdBy = userId;
|
||||
// }
|
||||
|
||||
const existingProject = await projectModel(organization).findOne(filter);
|
||||
if (!existingProject) return { status: "Project not found" };
|
||||
if (projectName !== undefined) projectName;
|
||||
@@ -245,9 +239,7 @@ export const viewProject = async (data: ProjectInterface) => {
|
||||
isArchive: false,
|
||||
});
|
||||
let filter = { _id: projectId, isArchive: false } as RoleFilter;
|
||||
// if (role === "User") {
|
||||
// filter.createdBy = userId;
|
||||
// }
|
||||
|
||||
const existingProject = await projectModel(organization).findOne(filter);
|
||||
if (!existingProject) return { status: "Project not found" };
|
||||
const newArr = RecentUserDoc?.recentlyViewed || [];
|
||||
|
||||
@@ -36,12 +36,8 @@ export const RecentlyAdded = async (data: IRecentData) => {
|
||||
model: projectModel(organization),
|
||||
select: "_id",
|
||||
});
|
||||
let filter = { isArchive: false } as RoleFilter;
|
||||
// if (role === "User") {
|
||||
// filter.createdBy = userId;
|
||||
// }
|
||||
|
||||
const populatedProjects = userRecentData.recentlyViewed as IProject[];
|
||||
console.log("populatedProjects: ", populatedProjects);
|
||||
const RecentDatas = await Promise.all(
|
||||
populatedProjects.map(async (project) => {
|
||||
const projectExisting = await projectModel(organization)
|
||||
@@ -50,7 +46,6 @@ export const RecentlyAdded = async (data: IRecentData) => {
|
||||
return projectExisting;
|
||||
})
|
||||
);
|
||||
console.log("RecentDatas: ", RecentDatas);
|
||||
|
||||
const filteredProjects = RecentDatas.filter(Boolean);
|
||||
console.log("filteredProjects: ", filteredProjects);
|
||||
@@ -65,7 +60,7 @@ export const searchProject = async (data: searchProjectInterface) => {
|
||||
const userExisting = await existingUser(userId, organization);
|
||||
if (!userExisting) return { status: "User not found" };
|
||||
const findprojectName = await projectModel(organization).find({
|
||||
projectName: { $regex: `${searchName}`, $options: "i" }, // 'i' makes it case-insensitive
|
||||
projectName: { $regex: `${searchName}`, $options: "i" },
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findprojectName || findprojectName.length === 0)
|
||||
|
||||
@@ -19,9 +19,7 @@ export const TrashDatas = async (data: IOrg) => {
|
||||
try {
|
||||
const { organization, role, userId } = data;
|
||||
let filter = { isArchive: true, isDeleted: false } as RoleFilter;
|
||||
// if (role === "User") {
|
||||
// filter.createdBy = userId;
|
||||
// }
|
||||
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const TrashLists = await projectModel(organization).find(filter);
|
||||
@@ -62,9 +60,7 @@ export const RestoreTrashData = async (data: IRestore) => {
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
let filter = { isArchive: true, _id: projectId } as RoleFilter;
|
||||
// if (role === "User") {
|
||||
// filter.createdBy = userId;
|
||||
// }
|
||||
|
||||
const findProject = await projectModel(organization).findOne(filter);
|
||||
if (!findProject) return { status: "Project not found" };
|
||||
const restoreData = await projectModel(organization).findOneAndUpdate(
|
||||
|
||||
@@ -48,7 +48,6 @@ class VersionService {
|
||||
userId: string,
|
||||
description?: string
|
||||
) {
|
||||
// Create new version
|
||||
const newVersion = await this.createNewVersion(
|
||||
db,
|
||||
projectId,
|
||||
@@ -56,7 +55,6 @@ class VersionService {
|
||||
description
|
||||
);
|
||||
|
||||
// Get all assets from previous version
|
||||
const previousVersion = parseFloat((newVersion.version - 0.1).toFixed(1));
|
||||
const previousVersionDoc = await versionModel(db).findOne({
|
||||
projectId,
|
||||
@@ -73,7 +71,6 @@ class VersionService {
|
||||
});
|
||||
}
|
||||
|
||||
// Copy assets to new version
|
||||
const newAssets = await Promise.all(
|
||||
previousAssets.map(async (asset) => {
|
||||
console.log("previousAssets: ", previousAssets);
|
||||
|
||||
@@ -45,13 +45,12 @@ export class WallItems {
|
||||
quaternion,
|
||||
scale,
|
||||
},
|
||||
{ new: true } // Return the updated document
|
||||
{ new: true }
|
||||
);
|
||||
return {
|
||||
state: "Updated successfully",
|
||||
data: updatevalue,
|
||||
};
|
||||
// res.status(201).json(updatevalue);
|
||||
} else {
|
||||
const newValue = await wallItemModel(organization).create({
|
||||
modelUuid,
|
||||
@@ -67,16 +66,12 @@ export class WallItems {
|
||||
state: "wall Item created successfully",
|
||||
data: newValue,
|
||||
};
|
||||
// res.status(201).json(newValue);
|
||||
}
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error:unknown) {
|
||||
const err = error as Error;
|
||||
console.error("Error creating wallitems:", error);
|
||||
return { state: "Failed to create wallitems", data: { message: err.message } };
|
||||
// return { state: "Failed to create wallitems", data: error } };
|
||||
// res.status(500).json({ message: "Failed to create wallitems" });
|
||||
}
|
||||
}
|
||||
static async getWallItems(req: Request, res: Response) {
|
||||
|
||||
Reference in New Issue
Block a user