Update environment configuration, enhance edge model, and improve logging in controllers and services
This commit is contained in:
4
.env
4
.env
@@ -1,4 +1,4 @@
|
|||||||
MONGO_URI=mongodb://192.168.0.213/
|
MONGO_URI=mongodb://192.168.0.210/
|
||||||
MONGO_USER=mydata
|
MONGO_USER=mydata
|
||||||
MONGO_PASSWORD=mongodb@hexr2002
|
MONGO_PASSWORD=mongodb@hexr2002
|
||||||
MONGO_AUTH_DB=admin
|
MONGO_AUTH_DB=admin
|
||||||
@@ -9,7 +9,7 @@ JWT_SECRET="Schema_Studio"
|
|||||||
REFRESH_JWT_SECRET="Schema_Studio"
|
REFRESH_JWT_SECRET="Schema_Studio"
|
||||||
|
|
||||||
REDIS_ENV= false
|
REDIS_ENV= false
|
||||||
REDIS_LOCAL = 192.168.0.204
|
REDIS_LOCAL = 192.168.0.202
|
||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
|
|
||||||
EMAIL_USER=nivetha@hexrfactory.com
|
EMAIL_USER=nivetha@hexrfactory.com
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ export const updateCollectionController = async (
|
|||||||
message: "collection updated successfully",
|
message: "collection updated successfully",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
message: "Internal server error",
|
message: "Internal server error",
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export const edgeCreationController = async (
|
|||||||
userId: userId as string,
|
userId: userId as string,
|
||||||
};
|
};
|
||||||
const result = await edgecreation(data);
|
const result = await edgecreation(data);
|
||||||
|
console.log('result: ', result);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found":
|
case "User not found":
|
||||||
@@ -114,6 +115,7 @@ export const allEdgesController = async (
|
|||||||
userId: userId as string,
|
userId: userId as string,
|
||||||
};
|
};
|
||||||
const result = await Alledges(data);
|
const result = await Alledges(data);
|
||||||
|
console.log('result:all edge ', result);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found":
|
case "User not found":
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import MainModel from "../connection/connection";
|
|||||||
import { IProject } from "./projectmodel";
|
import { IProject } from "./projectmodel";
|
||||||
export interface IEdgeModel extends Document {
|
export interface IEdgeModel extends Document {
|
||||||
projectId: IProject["_id"];
|
projectId: IProject["_id"];
|
||||||
from: { collection_id: string; field: string };
|
from: { collection_id: string; field: string; fieldId: string };
|
||||||
to: { collection_id: string };
|
to: { collection_id: string; fieldId: string };
|
||||||
cardinality: "one-to-one" | "one-to-many" | "many-to-many";
|
cardinality: "one-to-one" | "one-to-many" | "many-to-many";
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
@@ -14,9 +14,11 @@ const EdgeSchema = new Schema<IEdgeModel>({
|
|||||||
from: {
|
from: {
|
||||||
collection_id: { type: String, required: true },
|
collection_id: { type: String, required: true },
|
||||||
field: { type: String, required: true },
|
field: { type: String, required: true },
|
||||||
|
fieldId: { type: String, required: true },
|
||||||
},
|
},
|
||||||
to: {
|
to: {
|
||||||
collection_id: { type: String, required: true },
|
collection_id: { type: String, required: true },
|
||||||
|
fieldId: { type: String, required: true },
|
||||||
},
|
},
|
||||||
cardinality: {
|
cardinality: {
|
||||||
type: String,
|
type: String,
|
||||||
|
|||||||
@@ -89,11 +89,13 @@ export const edgecreation = async (data: IEdge): Promise<Iresponse> => {
|
|||||||
);
|
);
|
||||||
const fromFieldId = [fromField].map((attr: any) => attr?._id)[0];
|
const fromFieldId = [fromField].map((attr: any) => attr?._id)[0];
|
||||||
|
|
||||||
|
|
||||||
const fieldType = normalizeType(fromField?.type);
|
const fieldType = normalizeType(fromField?.type);
|
||||||
|
|
||||||
const fieldExists = existingToCollection.attributes.some(
|
const fieldExists = existingToCollection.attributes.some(
|
||||||
(attr: any) => attr.key === newFieldKey
|
(attr: any) => attr.key === newFieldKey
|
||||||
);
|
);
|
||||||
|
console.log('fieldExists: ', fieldExists);
|
||||||
|
|
||||||
if (!fieldExists) {
|
if (!fieldExists) {
|
||||||
const newAttribute: any = {
|
const newAttribute: any = {
|
||||||
@@ -106,6 +108,9 @@ export const edgecreation = async (data: IEdge): Promise<Iresponse> => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
existingToCollection.attributes.push(newAttribute);
|
existingToCollection.attributes.push(newAttribute);
|
||||||
|
console.log('newAttribute: ', newAttribute);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
existingToCollection.attributes = existingToCollection.attributes.map(
|
existingToCollection.attributes = existingToCollection.attributes.map(
|
||||||
(attr: any) => ({
|
(attr: any) => ({
|
||||||
@@ -115,14 +120,20 @@ export const edgecreation = async (data: IEdge): Promise<Iresponse> => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await existingToCollection.save();
|
await existingToCollection.save();
|
||||||
|
const savedToCollection = await collectionsModel(organization).findById(existingToCollection._id);
|
||||||
|
const lastAttr = savedToCollection?.attributes?.at(-1);
|
||||||
|
|
||||||
|
const fieldIdTo = (lastAttr as any)?._id;
|
||||||
|
console.log('fieldIdTo: ', fieldIdTo);
|
||||||
|
|
||||||
// console.log(
|
// console.log(
|
||||||
// `Field ${newFieldKey} (type: ${fieldType}) added to TO collection with reference to ${existingFromCollection._id}`
|
// `Field ${newFieldKey} (type: ${fieldType}) added to TO collection with reference to ${existingFromCollection._id}`
|
||||||
// );
|
// );
|
||||||
|
|
||||||
const newEdge = {
|
const newEdge = {
|
||||||
projectId,
|
projectId,
|
||||||
from: { collection_id: existingFromCollection._id, field: from.field },
|
from: { collection_id: existingFromCollection._id, field: from.field,fieldId:fromFieldId },
|
||||||
to: { collection_id: existingToCollection._id },
|
to: { collection_id: existingToCollection._id ,fieldId:fieldIdTo},
|
||||||
cardinality,
|
cardinality,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
};
|
};
|
||||||
@@ -197,6 +208,7 @@ export const Alledges = async (data: IAllEdge): Promise<Iresponse> => {
|
|||||||
};
|
};
|
||||||
export const deleteEdge = async (data: IEdgeDelete): Promise<Iresponse> => {
|
export const deleteEdge = async (data: IEdgeDelete): Promise<Iresponse> => {
|
||||||
const { organization, projectId, edgeId, userId } = data;
|
const { organization, projectId, edgeId, userId } = data;
|
||||||
|
console.log('data:edge ', data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ExistingUser = await userModel(organization).findOne({
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
|||||||
@@ -405,7 +405,7 @@ export const DeleteProject = async (data: IProjectView): Promise<Iresponse> => {
|
|||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
if (!deleteProject) return { status: "Project Delete unsuccessfull" };
|
if (!deleteProject) return { status: "Project Delete unsuccessfull" };
|
||||||
return { status: "Success" };
|
return { status: "Success" ,data:deleteProject};
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export const edgeHandleEvent = async (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const result = await edgecreation(data);
|
const result = await edgecreation(data);
|
||||||
|
|
||||||
console.log('result: ', result);
|
console.log('result: ', result);
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ export const projectDeleteHandleEvent = async (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const result = await DeleteProject(data);
|
const result = await DeleteProject(data);
|
||||||
|
console.log('result: ', result);
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
const messages: Record<string, { message: string }> = {
|
||||||
|
|||||||
@@ -26,9 +26,10 @@ export const SocketServer = async (io: Server) => {
|
|||||||
const namespace = io.of(nspName);
|
const namespace = io.of(nspName);
|
||||||
namespace.use(async (socket: Socket, next) => {
|
namespace.use(async (socket: Socket, next) => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const accessToken =
|
const accessToken =
|
||||||
socket.handshake.auth?.accessToken ||
|
socket.handshake.auth?.token ||
|
||||||
socket.handshake.headers?.accesstoken;
|
socket.handshake.headers?.token;
|
||||||
const refreshToken =
|
const refreshToken =
|
||||||
socket.handshake.auth?.refreshToken ||
|
socket.handshake.auth?.refreshToken ||
|
||||||
socket.handshake.headers?.refreshToken;
|
socket.handshake.headers?.refreshToken;
|
||||||
|
|||||||
@@ -42,12 +42,13 @@ export const emitToSenderAndAdmins = (
|
|||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
|
|
||||||
console.log('result.data: ', result.data);
|
console.log('result.data:emitevent ', result.data);
|
||||||
|
console.log('event:emit ', event);
|
||||||
socket.emit(event, {
|
socket.emit(event, {
|
||||||
message: result.message,
|
message: result.message,
|
||||||
data: result.data,
|
data: result.data,
|
||||||
error: result.error,
|
error: result.error,
|
||||||
socketId: result.socketId,
|
socketId: result.socketId,
|
||||||
organization,
|
organization,
|
||||||
});
|
});
|
||||||
socket.to(`${organization}_admins`).emit(event, {
|
socket.to(`${organization}_admins`).emit(event, {
|
||||||
|
|||||||
Reference in New Issue
Block a user