Version based API - Pushed here before the 5000 and 8000
This commit is contained in:
@@ -4,6 +4,7 @@ import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
|
||||
import {
|
||||
existingProjectById,
|
||||
existingUser,
|
||||
LivingCurrentVersion,
|
||||
} from "../helpers/v1projecthelperFns.ts";
|
||||
interface IResult {
|
||||
status: string;
|
||||
@@ -15,13 +16,16 @@ interface IAddPanel {
|
||||
panelOrder: string[];
|
||||
userId: string;
|
||||
projectId: string;
|
||||
versionId: string;
|
||||
}
|
||||
|
||||
interface IPanel {
|
||||
organization: string;
|
||||
zoneUuid: string;
|
||||
panelName: string;
|
||||
userId: string;
|
||||
projectId: string;
|
||||
versionId: string;
|
||||
}
|
||||
interface ILockedPanel {
|
||||
organization: string;
|
||||
@@ -29,10 +33,12 @@ interface ILockedPanel {
|
||||
lockedPanel: string[];
|
||||
userId: string;
|
||||
projectId: string;
|
||||
versionId: string;
|
||||
}
|
||||
export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, zoneUuid, panelOrder, userId, projectId } = data;
|
||||
const { organization, zoneUuid, panelOrder, userId, versionId, projectId } =
|
||||
data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -41,19 +47,33 @@ export const AddPanel = async (data: IAddPanel): 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 existingZone = await zoneModel(organization).findOne({
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
versionId: versionId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found" };
|
||||
await zoneModel(organization).findOneAndUpdate(
|
||||
{ zoneUuid: zoneUuid, isArchive: false },
|
||||
{
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
versionId: versionId,
|
||||
},
|
||||
{ panelOrder: panelOrder },
|
||||
{ new: true }
|
||||
);
|
||||
const existingPanels = await panelModel(organization).find({
|
||||
zoneUuid: zoneUuid,
|
||||
projectId: projectId,
|
||||
versionId: versionId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
@@ -70,6 +90,8 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
||||
const newPanel = await panelModel(organization).create({
|
||||
zoneUuid: zoneUuid,
|
||||
panelName: panelName,
|
||||
projectId: projectId,
|
||||
versionId: versionId,
|
||||
widgets: [],
|
||||
isArchive: false,
|
||||
});
|
||||
@@ -83,7 +105,8 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
||||
const zoneAndPanelData = await getZoneAndPanelData(
|
||||
organization,
|
||||
zoneUuid,
|
||||
projectId
|
||||
projectId,
|
||||
versionId
|
||||
);
|
||||
if (!zoneAndPanelData) {
|
||||
return zoneAndPanelData;
|
||||
@@ -103,7 +126,8 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
||||
};
|
||||
export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, zoneUuid, panelName, userId, projectId } = data;
|
||||
const { organization, zoneUuid, versionId, panelName, userId, projectId } =
|
||||
data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -112,25 +136,41 @@ export const DelPanel = async (data: IPanel): 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 existingZone = await zoneModel(organization).findOne({
|
||||
zoneUuid: zoneUuid,
|
||||
versionId: versionId,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found" };
|
||||
const existingPanel = await panelModel(organization).findOne({
|
||||
zoneUuid: zoneUuid,
|
||||
projectId: projectId,
|
||||
versionId: versionId,
|
||||
panelName: panelName,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingPanel) return { status: "Panel Already Deleted" };
|
||||
|
||||
await panelModel(organization).updateOne(
|
||||
{ _id: existingPanel._id, isArchive: false },
|
||||
{
|
||||
_id: existingPanel._id,
|
||||
projectId: projectId,
|
||||
versionId: versionId,
|
||||
isArchive: false,
|
||||
},
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
const existingWidgets = await widgetModel(organization).find({
|
||||
panelID: existingPanel._id,
|
||||
projectId: projectId,
|
||||
versionId: versionId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
@@ -141,14 +181,19 @@ export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
||||
|
||||
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
||||
await zoneModel(organization).updateOne(
|
||||
{ _id: existingZone._id },
|
||||
{
|
||||
_id: existingZone._id,
|
||||
projectId: projectId,
|
||||
versionId: versionId,
|
||||
},
|
||||
{ $pull: { panelOrder: existingPanel.panelName } }
|
||||
);
|
||||
}
|
||||
const zoneAndPanelData = await getZoneAndPanelData(
|
||||
organization,
|
||||
zoneUuid,
|
||||
projectId
|
||||
projectId,
|
||||
versionId
|
||||
);
|
||||
if (!zoneAndPanelData) {
|
||||
return zoneAndPanelData;
|
||||
@@ -168,7 +213,8 @@ export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
||||
};
|
||||
export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, zoneUuid, panelName, userId, projectId } = data;
|
||||
const { organization, zoneUuid, panelName, versionId, userId, projectId } =
|
||||
data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -177,8 +223,15 @@ export const ClearPanel = async (data: IPanel): 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 existingZone = await zoneModel(organization).findOne({
|
||||
zoneUuid: zoneUuid,
|
||||
versionId: versionId,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
@@ -186,18 +239,27 @@ export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
||||
const existingPanel = await panelModel(organization).findOne({
|
||||
zoneUuid: zoneUuid,
|
||||
panelName: panelName,
|
||||
versionId: versionId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingPanel) return { status: "Requested Panel not found" };
|
||||
|
||||
const existingWidgets = await widgetModel(organization).find({
|
||||
panelID: existingPanel._id,
|
||||
versionId: versionId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingWidgets.length === 0) return { status: "No widgets to clear" };
|
||||
|
||||
const clearWidgetsofPanel = await widgetModel(organization).updateMany(
|
||||
{ panelID: existingPanel._id, isArchive: false },
|
||||
{
|
||||
panelID: existingPanel._id,
|
||||
isArchive: false,
|
||||
versionId: versionId,
|
||||
projectId: projectId,
|
||||
},
|
||||
{ isArchive: true }
|
||||
);
|
||||
const removeWidgetsInPanel = await panelModel(
|
||||
@@ -213,7 +275,8 @@ export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
||||
const zoneAndPanelData = await getZoneAndPanelData(
|
||||
organization,
|
||||
zoneUuid,
|
||||
projectId
|
||||
projectId,
|
||||
versionId
|
||||
);
|
||||
if (!zoneAndPanelData) {
|
||||
return zoneAndPanelData;
|
||||
@@ -237,7 +300,14 @@ export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
||||
};
|
||||
export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, zoneUuid, lockedPanel, userId, projectId } = data;
|
||||
const {
|
||||
organization,
|
||||
zoneUuid,
|
||||
lockedPanel,
|
||||
versionId,
|
||||
userId,
|
||||
projectId,
|
||||
} = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -246,15 +316,27 @@ export const LockedPanel = async (data: ILockedPanel): 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 existingZone = await zoneModel(organization).findOne({
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
versionId: versionId,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found" };
|
||||
else {
|
||||
const updateLockedPanel = await zoneModel(organization).findOneAndUpdate(
|
||||
{ zoneUuid: zoneUuid, isArchive: false },
|
||||
{
|
||||
zoneUuid: zoneUuid,
|
||||
versionId: versionId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
lockedPanel: lockedPanel,
|
||||
},
|
||||
@@ -263,7 +345,8 @@ export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
||||
const zoneAndPanelData = await getZoneAndPanelData(
|
||||
organization,
|
||||
zoneUuid,
|
||||
projectId
|
||||
projectId,
|
||||
versionId
|
||||
);
|
||||
if (!zoneAndPanelData) {
|
||||
return zoneAndPanelData;
|
||||
@@ -291,16 +374,16 @@ export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
||||
const getZoneAndPanelData = async (
|
||||
organization: string,
|
||||
zoneUuid: string,
|
||||
projectId: string
|
||||
projectId: string,
|
||||
versionId: string
|
||||
) => {
|
||||
try {
|
||||
|
||||
|
||||
const existingZone = await zoneModel(organization)
|
||||
.findOne({
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
versionId: versionId,
|
||||
})
|
||||
.select(
|
||||
"panelOrder zoneName zonePoints lockedPanel zoneUuid viewPortCenter viewPortposition"
|
||||
@@ -311,6 +394,8 @@ const getZoneAndPanelData = async (
|
||||
const panelData = await panelModel(organization).find({
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
versionId: versionId,
|
||||
});
|
||||
const zoneName = existingZone.zoneName as string;
|
||||
|
||||
@@ -318,6 +403,8 @@ const getZoneAndPanelData = async (
|
||||
panelData.map(async (data) => {
|
||||
const widgetDataArray = await widgetModel(organization).find({
|
||||
panelID: data._id,
|
||||
projectId: projectId,
|
||||
versionId: versionId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user