Update environment configuration, enhance edge model, and improve logging in controllers and services

This commit is contained in:
2025-10-28 10:00:00 +05:30
parent 09c88c3396
commit e65bb2b480
10 changed files with 32 additions and 12 deletions

4
.env
View File

@@ -1,4 +1,4 @@
MONGO_URI=mongodb://192.168.0.213/
MONGO_URI=mongodb://192.168.0.210/
MONGO_USER=mydata
MONGO_PASSWORD=mongodb@hexr2002
MONGO_AUTH_DB=admin
@@ -9,7 +9,7 @@ JWT_SECRET="Schema_Studio"
REFRESH_JWT_SECRET="Schema_Studio"
REDIS_ENV= false
REDIS_LOCAL = 192.168.0.204
REDIS_LOCAL = 192.168.0.202
REDIS_PORT=6379
EMAIL_USER=nivetha@hexrfactory.com

View File

@@ -170,7 +170,7 @@ export const updateCollectionController = async (
message: "collection updated successfully",
});
break;
default:
default:
res.status(500).json({
message: "Internal server error",
});

View File

@@ -39,6 +39,7 @@ export const edgeCreationController = async (
userId: userId as string,
};
const result = await edgecreation(data);
console.log('result: ', result);
switch (result.status) {
case "User not found":
@@ -114,6 +115,7 @@ export const allEdgesController = async (
userId: userId as string,
};
const result = await Alledges(data);
console.log('result:all edge ', result);
switch (result.status) {
case "User not found":

View File

@@ -3,8 +3,8 @@ import MainModel from "../connection/connection";
import { IProject } from "./projectmodel";
export interface IEdgeModel extends Document {
projectId: IProject["_id"];
from: { collection_id: string; field: string };
to: { collection_id: string };
from: { collection_id: string; field: string; fieldId: string };
to: { collection_id: string; fieldId: string };
cardinality: "one-to-one" | "one-to-many" | "many-to-many";
isArchive: boolean;
createdAt: number;
@@ -14,9 +14,11 @@ const EdgeSchema = new Schema<IEdgeModel>({
from: {
collection_id: { type: String, required: true },
field: { type: String, required: true },
fieldId: { type: String, required: true },
},
to: {
collection_id: { type: String, required: true },
fieldId: { type: String, required: true },
},
cardinality: {
type: String,

View File

@@ -89,11 +89,13 @@ export const edgecreation = async (data: IEdge): Promise<Iresponse> => {
);
const fromFieldId = [fromField].map((attr: any) => attr?._id)[0];
const fieldType = normalizeType(fromField?.type);
const fieldExists = existingToCollection.attributes.some(
(attr: any) => attr.key === newFieldKey
);
console.log('fieldExists: ', fieldExists);
if (!fieldExists) {
const newAttribute: any = {
@@ -106,6 +108,9 @@ export const edgecreation = async (data: IEdge): Promise<Iresponse> => {
};
existingToCollection.attributes.push(newAttribute);
console.log('newAttribute: ', newAttribute);
existingToCollection.attributes = existingToCollection.attributes.map(
(attr: any) => ({
@@ -115,14 +120,20 @@ export const edgecreation = async (data: IEdge): Promise<Iresponse> => {
);
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(
// `Field ${newFieldKey} (type: ${fieldType}) added to TO collection with reference to ${existingFromCollection._id}`
// );
const newEdge = {
projectId,
from: { collection_id: existingFromCollection._id, field: from.field },
to: { collection_id: existingToCollection._id },
from: { collection_id: existingFromCollection._id, field: from.field,fieldId:fromFieldId },
to: { collection_id: existingToCollection._id ,fieldId:fieldIdTo},
cardinality,
createdAt: new Date(),
};
@@ -197,6 +208,7 @@ export const Alledges = async (data: IAllEdge): Promise<Iresponse> => {
};
export const deleteEdge = async (data: IEdgeDelete): Promise<Iresponse> => {
const { organization, projectId, edgeId, userId } = data;
console.log('data:edge ', data);
try {
const ExistingUser = await userModel(organization).findOne({

View File

@@ -405,7 +405,7 @@ export const DeleteProject = async (data: IProjectView): Promise<Iresponse> => {
{ new: true }
);
if (!deleteProject) return { status: "Project Delete unsuccessfull" };
return { status: "Success" };
return { status: "Success" ,data:deleteProject};
} catch (error: unknown) {
if (error instanceof Error) {
return {

View File

@@ -36,6 +36,7 @@ export const edgeHandleEvent = async (
return;
}
const result = await edgecreation(data);
console.log('result: ', result);
const status = typeof result?.status === "string" ? result.status : "unknown";

View File

@@ -157,6 +157,7 @@ export const projectDeleteHandleEvent = async (
return;
}
const result = await DeleteProject(data);
console.log('result: ', result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {

View File

@@ -26,9 +26,10 @@ export const SocketServer = async (io: Server) => {
const namespace = io.of(nspName);
namespace.use(async (socket: Socket, next) => {
try {
const accessToken =
socket.handshake.auth?.accessToken ||
socket.handshake.headers?.accesstoken;
socket.handshake.auth?.token ||
socket.handshake.headers?.token;
const refreshToken =
socket.handshake.auth?.refreshToken ||
socket.handshake.headers?.refreshToken;

View File

@@ -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, {
message: result.message,
data: result.data,
error: result.error,
socketId: result.socketId,
socketId: result.socketId,
organization,
});
socket.to(`${organization}_admins`).emit(event, {