diff --git a/.env b/.env index eb17487..9aea884 100644 --- a/.env +++ b/.env @@ -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 diff --git a/src/api-server/controller/collectionNodeController.ts b/src/api-server/controller/collectionNodeController.ts index 4b00cd1..e21be5c 100644 --- a/src/api-server/controller/collectionNodeController.ts +++ b/src/api-server/controller/collectionNodeController.ts @@ -170,7 +170,7 @@ export const updateCollectionController = async ( message: "collection updated successfully", }); break; - default: + default: res.status(500).json({ message: "Internal server error", }); diff --git a/src/api-server/controller/edgeController.ts b/src/api-server/controller/edgeController.ts index 9bd507b..c3ab88e 100644 --- a/src/api-server/controller/edgeController.ts +++ b/src/api-server/controller/edgeController.ts @@ -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": diff --git a/src/shared/model/edgeModel.ts b/src/shared/model/edgeModel.ts index 02ddfd2..a7fe05e 100644 --- a/src/shared/model/edgeModel.ts +++ b/src/shared/model/edgeModel.ts @@ -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({ 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, diff --git a/src/shared/services/edgeService.ts b/src/shared/services/edgeService.ts index f02576d..baa4e9b 100644 --- a/src/shared/services/edgeService.ts +++ b/src/shared/services/edgeService.ts @@ -89,11 +89,13 @@ export const edgecreation = async (data: IEdge): Promise => { ); 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 => { }; 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 => { ); 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 => { }; export const deleteEdge = async (data: IEdgeDelete): Promise => { const { organization, projectId, edgeId, userId } = data; + console.log('data:edge ', data); try { const ExistingUser = await userModel(organization).findOne({ diff --git a/src/shared/services/projectService.ts b/src/shared/services/projectService.ts index 776e146..011f28c 100644 --- a/src/shared/services/projectService.ts +++ b/src/shared/services/projectService.ts @@ -405,7 +405,7 @@ export const DeleteProject = async (data: IProjectView): Promise => { { 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 { diff --git a/src/socket-server/controllers/edgeController.ts b/src/socket-server/controllers/edgeController.ts index 48d4106..3413694 100644 --- a/src/socket-server/controllers/edgeController.ts +++ b/src/socket-server/controllers/edgeController.ts @@ -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"; diff --git a/src/socket-server/controllers/projectController.ts b/src/socket-server/controllers/projectController.ts index 9af205f..dafd0cc 100644 --- a/src/socket-server/controllers/projectController.ts +++ b/src/socket-server/controllers/projectController.ts @@ -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 = { diff --git a/src/socket-server/manager/manager.ts b/src/socket-server/manager/manager.ts index 10a2369..c28a1e2 100644 --- a/src/socket-server/manager/manager.ts +++ b/src/socket-server/manager/manager.ts @@ -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; diff --git a/src/socket-server/utils/emitEventResponse.ts b/src/socket-server/utils/emitEventResponse.ts index ae5f8c8..5e68eba 100644 --- a/src/socket-server/utils/emitEventResponse.ts +++ b/src/socket-server/utils/emitEventResponse.ts @@ -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, {