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

@@ -6,6 +6,7 @@ import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
import {
existingProjectById,
existingUser,
LivingCurrentVersion,
} from "../helpers/v1projecthelperFns.ts";
interface IResult {
status: string;
@@ -23,12 +24,14 @@ interface IAddTemplate {
Widgets3D: [];
};
projectId: string;
versionId: string;
userId: string;
}
interface ITemplateToZone {
organization: string;
templateID: string;
projectId: string;
versionId: string;
zoneUuid: string;
userId: string;
}
@@ -36,32 +39,47 @@ interface ITemplate {
organization: string;
templateID: string;
projectId: string;
versionId: string;
userId: string;
}
interface IGetTemplate {
organization: string;
projectId: string;
versionId: string;
userId: string;
}
export const AddTemplate = async (data: IAddTemplate): Promise<IResult> => {
try {
const { organization, template, projectId, userId } = data;
const { organization, template, projectId, versionId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) {return { status: "User not found" }};
if (!UserExists) {
return { status: "User not found" };
}
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) {return { status: "Project not found" }};
if (!LivingProject) {
return { status: "Project not found" };
}
const ExistingVersion = await LivingCurrentVersion(
organization,
LivingProject._id,
versionId
);
if (!ExistingVersion) return { status: "Version Data not found" };
const existingTemplate = await templateModel(organization).findOne({
templateID: template.id,
isArchive: false,
versionId: versionId,
projectId: projectId,
});
if (existingTemplate) return { status: "TemplateID alreay exists" };
const newTemplate = await templateModel(organization).create({
templateID: template.id,
versionId: versionId,
projectId: projectId,
templateName: template.name,
panelOrder: template.panelOrder,
widgets: template.widgets,
@@ -71,7 +89,11 @@ export const AddTemplate = async (data: IAddTemplate): Promise<IResult> => {
});
if (newTemplate) {
const allTemplateDatas = await templateModel(organization)
.find({ isArchive: false })
.find({
isArchive: false,
versionId: versionId,
projectId: projectId,
})
.select("-_id -__v -isArchive -createdAt -updatedAt");
const formattedTemplates = allTemplateDatas.map(async (data) => ({
@@ -102,7 +124,8 @@ export const AddTemplateToZone = async (
data: ITemplateToZone
): Promise<IResult> => {
try {
const { organization, templateID, projectId, zoneUuid, userId } = data;
const { organization, templateID, versionId, projectId, zoneUuid, userId } =
data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
@@ -111,9 +134,16 @@ export const AddTemplateToZone = 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 existingZone = await zoneModel(organization).findOne({
zoneUuid: zoneUuid,
isArchive: false,
versionId: versionId,
projectId: projectId,
});
if (!existingZone)
@@ -124,6 +154,7 @@ export const AddTemplateToZone = async (
const existingTemplate = await templateModel(organization).findOne({
templateID: templateID,
isArchive: false,
versionId: versionId,
projectId: projectId,
});
if (!existingTemplate)
@@ -136,20 +167,28 @@ export const AddTemplateToZone = async (
await existingZone.save();
const archivePanelDatas = await panelModel(organization).find({
zoneUuid,
versionId: versionId,
projectId: projectId,
isArchive: false,
});
for (const panelData of archivePanelDatas) {
await widgetModel(organization).deleteMany({
panelID: panelData._id,
versionId: versionId,
projectId: projectId,
isArchive: false,
});
}
await panelModel(organization).deleteMany({
zoneUuid,
versionId: versionId,
projectId: projectId,
isArchive: false,
});
await floatWidgetModel(organization).deleteMany({
zoneUuid,
versionId: versionId,
projectId: projectId,
isArchive: false,
});
}
@@ -157,6 +196,8 @@ export const AddTemplateToZone = async (
await existingZone.save();
const existingPanels = await panelModel(organization).find({
zoneUuid,
versionId: versionId,
projectId: projectId,
isArchive: false,
});
const existingPanelNames = existingPanels.map(
@@ -170,6 +211,8 @@ export const AddTemplateToZone = async (
missingPanels.map((panelName: any) =>
panelModel(organization).create({
zoneUuid,
versionId: versionId,
projectId: projectId,
panelName,
widgets: [],
isArchive: false,
@@ -180,6 +223,8 @@ export const AddTemplateToZone = async (
for (const widgetData of existingTemplate.widgets) {
const addedExistingPanel = await panelModel(organization).findOne({
panelName: widgetData.panel,
versionId: versionId,
projectId: projectId,
zoneUuid,
isArchive: false,
});
@@ -187,6 +232,8 @@ export const AddTemplateToZone = async (
const existingWidget = await widgetModel(organization).findOne({
panelID: addedExistingPanel._id,
versionId: versionId,
projectId: projectId,
widgetID: widgetData.id,
isArchive: false,
});
@@ -194,6 +241,8 @@ export const AddTemplateToZone = async (
const newWidget = await widgetModel(organization).create({
widgetID: widgetData.id,
versionId: versionId,
projectId: projectId,
elementType: widgetData.type,
zoneUuid: zoneUuid,
widgetName: widgetData.widgetName || "Widget",
@@ -207,6 +256,8 @@ export const AddTemplateToZone = async (
for (const floatData of existingTemplate.floatWidgets) {
const existingFloatWidget = await floatWidgetModel(organization).findOne({
floatWidgetID: floatData.id,
versionId: versionId,
projectId: projectId,
isArchive: false,
zoneUuid,
});
@@ -214,6 +265,8 @@ export const AddTemplateToZone = async (
await floatWidgetModel(organization).create({
className: floatData.className,
versionId: versionId,
projectId: projectId,
header: floatData.header,
floatWidgetID: floatData.id,
position: floatData.position,
@@ -250,7 +303,7 @@ export const AddTemplateToZone = async (
};
export const TemplateDelete = async (data: ITemplate): Promise<IResult> => {
try {
const { templateID, projectId, userId, organization } = data;
const { templateID, projectId, userId, organization, versionId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
@@ -259,14 +312,26 @@ export const TemplateDelete = async (data: ITemplate): 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 existingTemplate = await templateModel(organization).findOne({
templateID: templateID,
isArchive: false,
versionId: versionId,
projectId: projectId,
});
if (existingTemplate) {
const newTemplate = await templateModel(organization).updateOne(
{ templateID: templateID, isArchive: false, projectId: projectId },
{
templateID: templateID,
isArchive: false,
versionId: versionId,
projectId: projectId,
},
{ $set: { isArchive: true } }
);
if (newTemplate) {
@@ -293,7 +358,7 @@ export const TemplateDelete = async (data: ITemplate): Promise<IResult> => {
};
export const GetAllTemplates = async (data: IGetTemplate): Promise<IResult> => {
try {
const { organization, userId, projectId } = data;
const { organization, userId, projectId,versionId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
@@ -302,8 +367,19 @@ export const GetAllTemplates = async (data: IGetTemplate): Promise<IResult> => {
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 templateDatas = await templateModel(organization)
.find({ projectId: projectId, isArchive: false })
.find({
versionId: ExistingVersion._id,
projectId: projectId,
isArchive: false,
})
.select("-_id -__v -isArchive -createdAt -updatedAt");
if (!templateDatas) return { status: "All Datas" };