Version based API - Pushed here before the 5000 and 8000

This commit is contained in:
2025-06-21 15:16:52 +05:30
parent dead851b1a
commit 3ec45276f4
114 changed files with 7547 additions and 1436 deletions

View File

@@ -4,7 +4,9 @@ import ProductModel from "../../V1Models/Simulation/productModel.ts";
import {
existingProjectById,
existingUser,
LivingCurrentVersion,
} from "../helpers/v1projecthelperFns.ts";
import versionModel from "../../V1Models/Version/versionModel.ts";
interface IEventDatainterface {
modelUuid: string;
modelName: string;
@@ -31,12 +33,21 @@ interface Iproduct {
userId: string;
organization: string;
projectId: string;
versionId: string;
}
interface IProductEvent {
productUuid: string;
userId: string;
organization: string;
projectId: string;
versionId: string;
}
interface IProductEventDel {
productUuid: string;
userId: string;
organization: string;
projectId: string;
versionId: string;
}
interface IDelEvent {
productUuid: string;
@@ -44,16 +55,19 @@ interface IDelEvent {
userId: string;
organization: string;
projectId: string;
versionId: string;
}
interface IProjectProducts {
userId: string;
organization: string;
projectId: string;
versionId: string;
}
interface IProductRename {
userId: string;
organization: string;
projectId: string;
versionId: string;
productUuid: string;
productName: string;
}
@@ -69,6 +83,7 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
productUuid,
eventDatas,
projectId,
versionId,
userId,
organization,
} = data;
@@ -80,15 +95,23 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
userId
);
if (!LivingProject) return { status: "Project not found" };
const ExistingVersion = await LivingCurrentVersion(
organization,
LivingProject._id,
versionId
);
if (!ExistingVersion) return { status: "Version Data not found" };
const existingProduct = await ProductAFind(
productUuid,
projectId,
versionId,
organization
);
if (existingProduct) {
const existingEventData = await EventsDataModel(organization).findOne({
productUuid: productUuid,
projectId: projectId,
versionId: versionId,
modelUuid: eventDatas.modelUuid,
isArchive: false,
});
@@ -97,7 +120,8 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
organization,
eventDatas,
productUuid,
projectId
projectId,
versionId
);
return {
status: "EventData updated successfully",
@@ -107,7 +131,8 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
organization,
eventDatas,
productUuid,
projectId
projectId,
versionId
);
return {
status: "EventData add successfully",
@@ -118,6 +143,7 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
productUuid: productUuid,
projectId: projectId,
productName: productName,
versionId: versionId,
});
if (newProduct) {
if (eventDatas) {
@@ -125,7 +151,8 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
organization,
eventDatas,
productUuid,
projectId
projectId,
versionId
);
}
}
@@ -150,9 +177,11 @@ async function EventCreateFunction(
organization: string,
eventDatas: IEventDatainterface,
productUuid: string,
projectId: string
projectId: string,
versionId: string
) {
await EventsDataModel(organization).create({
versionId: versionId,
projectId: projectId,
productUuid: productUuid,
modelUuid: eventDatas?.modelUuid as string,
@@ -169,11 +198,13 @@ async function EventUpdateFunction(
organization: string,
eventDatas: IEventDatainterface,
productUuid: string,
projectId: string
projectId: string,
versionId: string
) {
await EventsDataModel(organization).findOneAndUpdate(
{
projectId: projectId,
versionId: versionId,
modelUuid: eventDatas.modelUuid,
productUuid: productUuid,
isArchive: false,
@@ -193,11 +224,13 @@ async function EventUpdateFunction(
async function ProductAFind(
productUuid: string,
projectId: string,
versionId: string,
organization: string
) {
const existingProduct = await ProductModel(organization).findOne({
productUuid: productUuid,
projectId: projectId,
versionId: versionId,
isArchive: false,
});
@@ -207,7 +240,7 @@ export const getProductDatas = async (
data: IProductEvent
): Promise<IResult> => {
try {
const { productUuid, projectId, userId, organization } = data;
const { productUuid, projectId,versionId, userId, organization } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
@@ -216,9 +249,17 @@ export const getProductDatas = async (
userId
);
if (!LivingProject) return { status: "Project not found" };
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
const ExistingVersion = await LivingCurrentVersion(
organization,
LivingProject._id,
VersionGetId
);
if (!ExistingVersion) return { status: "Version Data not found" };
const ExistingProduct = await ProductAFind(
productUuid,
projectId,
ExistingVersion._id,
organization
);
if (!ExistingProduct) return { status: "Product not found" };
@@ -227,6 +268,7 @@ export const getProductDatas = async (
.find({
productUuid: productUuid,
projectId: projectId,
versionId: ExistingVersion._id,
isArchive: false,
})
.select("-productUuid");
@@ -247,10 +289,10 @@ export const getProductDatas = async (
}
};
export const productDataDelete = async (
data: IProductEvent
data: IProductEventDel
): Promise<IResult> => {
try {
const { productUuid, projectId, userId, organization } = data;
const { productUuid, projectId, versionId, userId, organization } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
@@ -259,15 +301,27 @@ export const productDataDelete = async (
userId
);
if (!LivingProject) return { status: "Project not found" };
const ExistingVersion = await LivingCurrentVersion(
organization,
LivingProject._id,
versionId
);
if (!ExistingVersion) return { status: "Version Data not found" };
const ExistingProduct = await ProductAFind(
productUuid,
projectId,
versionId,
organization
);
if (!ExistingProduct) return { status: "Product not found" };
await ProductModel(organization).findOneAndUpdate(
{ productUuid: productUuid, projectId: projectId, isArchive: false },
{
productUuid: productUuid,
projectId: projectId,
versionId: versionId,
isArchive: false,
},
{
isArchive: true,
},
@@ -276,11 +330,17 @@ export const productDataDelete = async (
const existingEventDatas = await EventsDataModel(organization).find({
productUuid: productUuid,
projectId: projectId,
versionId: versionId,
isArchive: false,
});
if (existingEventDatas) {
await EventsDataModel(organization).updateMany(
{ productUuid, projectId, isArchive: false },
{
productUuid,
projectId,
versionId: versionId,
isArchive: false,
},
{ $set: { isArchive: true } }
);
}
@@ -301,7 +361,14 @@ export const productDataDelete = async (
};
export const EventDataDelete = async (data: IDelEvent): Promise<IResult> => {
try {
const { modelUuid, productUuid, projectId, userId, organization } = data;
const {
modelUuid,
productUuid,
projectId,
versionId,
userId,
organization,
} = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
@@ -310,9 +377,16 @@ export const EventDataDelete = async (data: IDelEvent): Promise<IResult> => {
userId
);
if (!LivingProject) return { status: "Project not found" };
const ExistingVersion = await LivingCurrentVersion(
organization,
LivingProject._id,
versionId
);
if (!ExistingVersion) return { status: "Version Data not found" };
const ExistingProduct = await ProductAFind(
productUuid,
projectId,
versionId,
organization
);
if (!ExistingProduct) return { status: "Product not found" };
@@ -320,6 +394,7 @@ export const EventDataDelete = async (data: IDelEvent): Promise<IResult> => {
{
productUuid: productUuid,
projectId: projectId,
versionId: versionId,
isArchive: false,
modelUuid: modelUuid,
},
@@ -351,7 +426,7 @@ export const AllProductDatas = async (
data: IProjectProducts
): Promise<IResult> => {
try {
const { projectId, userId, organization } = data;
const { projectId, versionId ,userId, organization } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
@@ -360,8 +435,16 @@ export const AllProductDatas = async (
userId
);
if (!LivingProject) return { status: "Project not found" };
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
const ExistingVersion = await LivingCurrentVersion(
organization,
LivingProject._id,
VersionGetId
);
if (!ExistingVersion) return { status: "Version Data not found" };
const existingProduct = await ProductModel(organization).find({
isArchive: false,
versionId: ExistingVersion._id,
projectId: projectId,
});
if (!existingProduct) {
@@ -375,6 +458,7 @@ export const AllProductDatas = async (
for (const product of existingProduct) {
const eventDatas = await EventsDataModel(organization)
.find({
versionId: ExistingVersion._id,
projectId: product.projectId,
productUuid: product.productUuid,
isArchive: false,
@@ -383,6 +467,7 @@ export const AllProductDatas = async (
result.push({
projectId: product.projectId,
versionId: product.versionId,
productName: product.productName,
productUuid: product.productUuid,
eventDatas,
@@ -407,7 +492,14 @@ export const AllProductDatas = async (
};
export const productRename = async (data: IProductRename): Promise<IResult> => {
try {
const { productName, productUuid, projectId, userId, organization } = data;
const {
productName,
productUuid,
projectId,
versionId,
userId,
organization,
} = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
@@ -416,15 +508,27 @@ export const productRename = async (data: IProductRename): Promise<IResult> => {
userId
);
if (!LivingProject) return { status: "Project not found" };
const ExistingVersion = await LivingCurrentVersion(
organization,
LivingProject._id,
versionId
);
if (!ExistingVersion) return { status: "Version Data not found" };
const ExistingProduct = await ProductAFind(
productUuid,
projectId,
versionId,
organization
);
if (!ExistingProduct) return { status: "Product not found" };
const UpdateName = await ProductModel(organization).findOneAndUpdate(
{ productUuid: productUuid, projectId: projectId, isArchive: false },
{
productUuid: productUuid,
projectId: projectId,
versionId: versionId,
isArchive: false,
},
{
productName: productName,
},