From 2117d2bfa4481e5f217b84971fb4e29d5b467c1e Mon Sep 17 00:00:00 2001 From: vishnu Date: Mon, 19 Feb 2024 12:57:38 +0530 Subject: [PATCH 1/4] initial commit --- docker-compose-mentoring-local.yml | 231 +++++++++++++++++++++++++++++ src/database/queries/sessions.js | 38 ++++- src/services/mentors.js | 12 +- 3 files changed, 279 insertions(+), 2 deletions(-) create mode 100644 docker-compose-mentoring-local.yml diff --git a/docker-compose-mentoring-local.yml b/docker-compose-mentoring-local.yml new file mode 100644 index 000000000..c53719850 --- /dev/null +++ b/docker-compose-mentoring-local.yml @@ -0,0 +1,231 @@ +version: '3' +services: + zookeeper: + image: 'bitnami/zookeeper:3.8.0' + ports: + - '2181:2181' + environment: + - ALLOW_ANONYMOUS_LOGIN=yes + networks: + - elevate_net + volumes: + - zookeeper-data:/bitnami/zookeeper + logging: + driver: none + kafka: + image: 'bitnami/kafka:3.1.0' + ports: + - '9092:9092' + environment: + - KAFKA_BROKER_ID=1 + - KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://:9093 + - KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka:9092,EXTERNAL://localhost:9093 + - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181 + - ALLOW_PLAINTEXT_LISTENER=yes + - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT + - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=CLIENT + depends_on: + - zookeeper + networks: + - elevate_net + volumes: + - kafka-data:/bitnami/kafka + logging: + driver: none + mongo: + image: 'mongo:4.4.14' + restart: 'always' + ports: + - '27017:27017' + networks: + - elevate_net + volumes: + - mongo-data:/data/db + logging: + driver: none + redis: + image: 'redis:7.0.0' + restart: 'always' + ports: + - '6379:6379' + networks: + - elevate_net + logging: + driver: none + # redis_bullmq: + # image: 'redis:7.0.0' + # container_name: redis_bullmq + # restart: 'always' + # command: redis-server --appendonly yes --maxmemory-policy noeviction + # ports: + # - '6380:6379' + # networks: + # - elevate_net + # volumes: + # - redis_data:/data + + elevate_mentoring: + build: './' + image: elevate/elevate_mentoring:1.0 + volumes: + - ./src/:/var/src + ports: + - '3000:3000' + command: ['nodemon', 'app.js'] + environment: + - MONGODB_URL=mongodb://mongo:27017/elevate-mentoring-local + - KAFKA_URL=kafka:9092 + - USER_SERVICE_HOST=http://elevate_user:3001 + # - DEV_DATABASE_URL=postgres://postgres:postgres@citus_master:5432/mentoring_Nov_27 + - DEV_DATABASE_URL=postgres://shikshalokam:slpassword123@10.148.0.36:9700/qa_elevate_mentoring + - REDIS_HOST=redis://redis:6379 + - SCHEDULER_SERVICE_HOST=http://elevate_scheduler:4000 + + depends_on: + - kafka + - mongo + - citus + networks: + - elevate_net + elevate_user: + build: '../user/' + image: elevate/elevate_user:1.0 + volumes: + - ../user/src/:/var/src + ports: + - '3001:3001' + command: ['nodemon', 'app.js'] + environment: + - MONGODB_URL=mongodb://mongo:27017/elevate-mentoring + - KAFKA_URL=kafka:9092 + - REDIS_HOST=redis://redis:6379 + - DEV_DATABASE_URL=postgres://shikshalokam:slpassword123@10.148.0.36:9700/qa_elevate_user + # - DEV_DATABASE_URL=postgres://postgres:postgres@citus_master:5432/user_Nov_27 + depends_on: + - kafka + - mongo + - redis + networks: + - elevate_net + elevate_notification: + build: '../notification/' + image: elevate/elevate_notification:1.0 + volumes: + - ../notification/src/:/var/src + ports: + - '3002:3002' + command: ['nodemon', 'app.js'] + environment: + - KAFKA_HOST=kafka:9092 + - DEV_DATABASE_URL=postgres://postgres:postgres@citus_master:5432/notification-local + + depends_on: + - kafka + - mongo + - citus + networks: + - elevate_net + elevate_scheduler: + build: '../scheduler/' + image: elevate/elevate_scheduler:1.0 + volumes: + - ../scheduler/src/:/var/src + ports: + - '4000:4000' + command: ['nodemon', 'app.js'] + environment: + - KAFKA_URL=kafka:9092 + - MONGODB_URL=mongodb://mongo:27017/elevate-scheduler + depends_on: + - kafka + - mongo + - redis + networks: + - elevate_net + # interface: + # build: '../interface-service/' + # image: elevate/interface:1.0 + # volumes: + # - ../interface-service/src/:/var/src + # ports: + # - '3569:3569' + # command: ['node', 'app.js'] + # networks: + # - elevate_net + # master: + # container_name: 'citus_master' + # image: 'citusdata/citus:11.2.0' + # ports: ['${COORDINATOR_EXTERNAL_PORT:-5432}:5432'] + # labels: ['com.citusdata.role=Master'] + # environment: &AUTH + # POSTGRES_USER: '${POSTGRES_USER:-postgres}' + # POSTGRES_PASSWORD: '${POSTGRES_PASSWORD:-postgres}' + # PGUSER: '${POSTGRES_USER:-postgres}' + # PGPASSWORD: '${POSTGRES_PASSWORD:-postgres}' + # POSTGRES_HOST_AUTH_METHOD: '${POSTGRES_HOST_AUTH_METHOD:-trust}' + # networks: + # - elevate_net + # worker: + # image: 'citusdata/citus:11.2.0' + # labels: ['com.citusdata.role=Worker'] + # depends_on: [manager] + # environment: *AUTH + # command: '/wait-for-manager.sh' + # volumes: + # - healthcheck-volume:/healthcheck + # networks: + # - elevate_net + # manager: + # container_name: '${COMPOSE_PROJECT_NAME:-citus}_manager' + # image: 'citusdata/membership-manager:0.3.0' + # volumes: + # - '${DOCKER_SOCK:-/var/run/docker.sock}:/var/run/docker.sock' + # - healthcheck-volume:/healthcheck + # depends_on: [master] + # environment: *AUTH + # networks: + # - elevate_net + + citus: + image: citusdata/citus:11.2.0 + container_name: 'citus_master' + ports: + - 5432:5432 + # expose: + # - 5432 + # command: > + # bash -c "while ! pg_isready -h localhost -U postgres -q; do sleep 1; done && + # psql -h localhost -U postgres -d -c 'CREATE EXTENSION citus; SELECT create_distributed_table(\"notification_templates\", \"id\");'" + environment: &AUTH + POSTGRES_USER: '${POSTGRES_USER:-postgres}' + POSTGRES_PASSWORD: '${POSTGRES_PASSWORD:-postgres}' + PGUSER: '${POSTGRES_USER:-postgres}' + PGPASSWORD: '${POSTGRES_PASSWORD:-postgres}' + POSTGRES_DB: 'user_Nov_27' + POSTGRES_HOST_AUTH_METHOD: '${POSTGRES_HOST_AUTH_METHOD:-trust}' + POSTGRES_LOG_STATEMENT: 'all' # Enable query logging (set to 'all' for all queries) + + networks: + - elevate_net + pgadmin: + image: dpage/pgadmin4 + container_name: elevate-pgadmin + restart: always + ports: + - '5500:80' + environment: + - PGADMIN_DEFAULT_EMAIL=user@shikshalokam.org + - PGADMIN_DEFAULT_PASSWORD=password + networks: + - elevate_net + logging: + driver: none +networks: + elevate_net: + external: false +volumes: + zookeeper-data: + kafka-data: + mongo-data: + redis_data: + healthcheck-volume: diff --git a/src/database/queries/sessions.js b/src/database/queries/sessions.js index dbc2db95d..69962bf68 100644 --- a/src/database/queries/sessions.js +++ b/src/database/queries/sessions.js @@ -385,6 +385,42 @@ exports.getCreatedSessionsCountInDateRange = async (mentorId, startDate, endDate } } +/** + * Get the count of mentoring sessions within a date range for a specific mentor. + * @param {number} mentorId - The ID of the mentor. + * @param {Date} startDate - The start date of the date range. + * @param {Date} endDate - The end date of the date range. + * @returns {Promise} - The count of mentoring sessions. + * @throws {Error} - If an error occurs during the process. + */ + +exports.getMentoringSessionsCountInDateRange = async (mentorId, startDate, endDate) => { + try { + const filter = { + user_id: mentorId, + type: common.SESSION_OWNERSHIP_TYPE.MENTOR, + } + + const option = { + attributes: ['session_id'], + } + const sessionIds = await sessionOwnership.findAll(filter, option, true) + + const count = await Session.count({ + where: { + id: { [Op.in]: sessionIds }, + created_at: { + [Op.between]: [startDate, endDate], + }, + mentor_id: mentorId, + }, + }) + return count + } catch (error) { + throw error + } +} + exports.getHostedSessionsCountInDateRange = async (mentorId, startDate, endDate) => { try { const filter = { @@ -728,7 +764,7 @@ exports.getMentorsUpcomingSessionsFromView = async (page, limit, search, mentorI ${saasFilterClause} ORDER BY start_date ASC - OFFSET + OFFSETp :offset LIMIT :limit; diff --git a/src/services/mentors.js b/src/services/mentors.js index 1cad1b6cc..103376894 100644 --- a/src/services/mentors.js +++ b/src/services/mentors.js @@ -179,13 +179,23 @@ module.exports = class MentorsHelper { filterEndDate.toISOString() ) + const totalSessionsMentoring = await sessionQueries.getMentoringSessionsCountInDateRange( + userId, + filterStartDate.toISOString(), + filterEndDate.toISOString() + ) + const totalSessionsHosted = await sessionQueries.getHostedSessionsCountInDateRange( userId, Date.parse(filterStartDate) / 1000, // Converts milliseconds to seconds Date.parse(filterEndDate) / 1000 ) - const result = { total_session_created: totalSessionsCreated, total_session_hosted: totalSessionsHosted } + const result = { + total_session_created: totalSessionsCreated, + total_session_hosted: totalSessionsHosted, + total_session_mentoring: totalSessionsMentoring, + } return responses.successResponse({ statusCode: httpStatusCode.ok, message: 'MENTORS_REPORT_FETCHED_SUCCESSFULLY', From 98c5ade0a1c8c686aca43c5e47667db77321fcbb Mon Sep 17 00:00:00 2001 From: vishnu Date: Mon, 19 Feb 2024 18:27:25 +0530 Subject: [PATCH 2/4] dashboard data change --- src/database/queries/sessions.js | 5 ++++- src/services/mentors.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/database/queries/sessions.js b/src/database/queries/sessions.js index 69962bf68..b0521d6d5 100644 --- a/src/database/queries/sessions.js +++ b/src/database/queries/sessions.js @@ -377,6 +377,8 @@ exports.getCreatedSessionsCountInDateRange = async (mentorId, startDate, endDate created_at: { [Op.between]: [startDate, endDate], }, + mentor_id: mentorId, // Check mentor_id + created_by: mentorId, // Check created_by }, }) return count @@ -394,7 +396,7 @@ exports.getCreatedSessionsCountInDateRange = async (mentorId, startDate, endDate * @throws {Error} - If an error occurs during the process. */ -exports.getMentoringSessionsCountInDateRange = async (mentorId, startDate, endDate) => { +exports.getAssignedSessionsCountInDateRange = async (mentorId, startDate, endDate) => { try { const filter = { user_id: mentorId, @@ -413,6 +415,7 @@ exports.getMentoringSessionsCountInDateRange = async (mentorId, startDate, endDa [Op.between]: [startDate, endDate], }, mentor_id: mentorId, + created_by: { [Op.ne]: mentorId }, }, }) return count diff --git a/src/services/mentors.js b/src/services/mentors.js index 103376894..0dcf166d4 100644 --- a/src/services/mentors.js +++ b/src/services/mentors.js @@ -179,7 +179,7 @@ module.exports = class MentorsHelper { filterEndDate.toISOString() ) - const totalSessionsMentoring = await sessionQueries.getMentoringSessionsCountInDateRange( + const totalSessionsAssigned = await sessionQueries.getAssignedSessionsCountInDateRange( userId, filterStartDate.toISOString(), filterEndDate.toISOString() @@ -194,7 +194,7 @@ module.exports = class MentorsHelper { const result = { total_session_created: totalSessionsCreated, total_session_hosted: totalSessionsHosted, - total_session_mentoring: totalSessionsMentoring, + total_session_assigned: totalSessionsAssigned, } return responses.successResponse({ statusCode: httpStatusCode.ok, From 458b061e960a3a474a65c5403ebf63de256a5f1e Mon Sep 17 00:00:00 2001 From: vishnu Date: Mon, 19 Feb 2024 18:40:36 +0530 Subject: [PATCH 3/4] removed unwanted changes --- docker-compose-mentoring-local.yml | 231 ----------------------------- 1 file changed, 231 deletions(-) delete mode 100644 docker-compose-mentoring-local.yml diff --git a/docker-compose-mentoring-local.yml b/docker-compose-mentoring-local.yml deleted file mode 100644 index c53719850..000000000 --- a/docker-compose-mentoring-local.yml +++ /dev/null @@ -1,231 +0,0 @@ -version: '3' -services: - zookeeper: - image: 'bitnami/zookeeper:3.8.0' - ports: - - '2181:2181' - environment: - - ALLOW_ANONYMOUS_LOGIN=yes - networks: - - elevate_net - volumes: - - zookeeper-data:/bitnami/zookeeper - logging: - driver: none - kafka: - image: 'bitnami/kafka:3.1.0' - ports: - - '9092:9092' - environment: - - KAFKA_BROKER_ID=1 - - KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://:9093 - - KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka:9092,EXTERNAL://localhost:9093 - - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181 - - ALLOW_PLAINTEXT_LISTENER=yes - - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT - - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=CLIENT - depends_on: - - zookeeper - networks: - - elevate_net - volumes: - - kafka-data:/bitnami/kafka - logging: - driver: none - mongo: - image: 'mongo:4.4.14' - restart: 'always' - ports: - - '27017:27017' - networks: - - elevate_net - volumes: - - mongo-data:/data/db - logging: - driver: none - redis: - image: 'redis:7.0.0' - restart: 'always' - ports: - - '6379:6379' - networks: - - elevate_net - logging: - driver: none - # redis_bullmq: - # image: 'redis:7.0.0' - # container_name: redis_bullmq - # restart: 'always' - # command: redis-server --appendonly yes --maxmemory-policy noeviction - # ports: - # - '6380:6379' - # networks: - # - elevate_net - # volumes: - # - redis_data:/data - - elevate_mentoring: - build: './' - image: elevate/elevate_mentoring:1.0 - volumes: - - ./src/:/var/src - ports: - - '3000:3000' - command: ['nodemon', 'app.js'] - environment: - - MONGODB_URL=mongodb://mongo:27017/elevate-mentoring-local - - KAFKA_URL=kafka:9092 - - USER_SERVICE_HOST=http://elevate_user:3001 - # - DEV_DATABASE_URL=postgres://postgres:postgres@citus_master:5432/mentoring_Nov_27 - - DEV_DATABASE_URL=postgres://shikshalokam:slpassword123@10.148.0.36:9700/qa_elevate_mentoring - - REDIS_HOST=redis://redis:6379 - - SCHEDULER_SERVICE_HOST=http://elevate_scheduler:4000 - - depends_on: - - kafka - - mongo - - citus - networks: - - elevate_net - elevate_user: - build: '../user/' - image: elevate/elevate_user:1.0 - volumes: - - ../user/src/:/var/src - ports: - - '3001:3001' - command: ['nodemon', 'app.js'] - environment: - - MONGODB_URL=mongodb://mongo:27017/elevate-mentoring - - KAFKA_URL=kafka:9092 - - REDIS_HOST=redis://redis:6379 - - DEV_DATABASE_URL=postgres://shikshalokam:slpassword123@10.148.0.36:9700/qa_elevate_user - # - DEV_DATABASE_URL=postgres://postgres:postgres@citus_master:5432/user_Nov_27 - depends_on: - - kafka - - mongo - - redis - networks: - - elevate_net - elevate_notification: - build: '../notification/' - image: elevate/elevate_notification:1.0 - volumes: - - ../notification/src/:/var/src - ports: - - '3002:3002' - command: ['nodemon', 'app.js'] - environment: - - KAFKA_HOST=kafka:9092 - - DEV_DATABASE_URL=postgres://postgres:postgres@citus_master:5432/notification-local - - depends_on: - - kafka - - mongo - - citus - networks: - - elevate_net - elevate_scheduler: - build: '../scheduler/' - image: elevate/elevate_scheduler:1.0 - volumes: - - ../scheduler/src/:/var/src - ports: - - '4000:4000' - command: ['nodemon', 'app.js'] - environment: - - KAFKA_URL=kafka:9092 - - MONGODB_URL=mongodb://mongo:27017/elevate-scheduler - depends_on: - - kafka - - mongo - - redis - networks: - - elevate_net - # interface: - # build: '../interface-service/' - # image: elevate/interface:1.0 - # volumes: - # - ../interface-service/src/:/var/src - # ports: - # - '3569:3569' - # command: ['node', 'app.js'] - # networks: - # - elevate_net - # master: - # container_name: 'citus_master' - # image: 'citusdata/citus:11.2.0' - # ports: ['${COORDINATOR_EXTERNAL_PORT:-5432}:5432'] - # labels: ['com.citusdata.role=Master'] - # environment: &AUTH - # POSTGRES_USER: '${POSTGRES_USER:-postgres}' - # POSTGRES_PASSWORD: '${POSTGRES_PASSWORD:-postgres}' - # PGUSER: '${POSTGRES_USER:-postgres}' - # PGPASSWORD: '${POSTGRES_PASSWORD:-postgres}' - # POSTGRES_HOST_AUTH_METHOD: '${POSTGRES_HOST_AUTH_METHOD:-trust}' - # networks: - # - elevate_net - # worker: - # image: 'citusdata/citus:11.2.0' - # labels: ['com.citusdata.role=Worker'] - # depends_on: [manager] - # environment: *AUTH - # command: '/wait-for-manager.sh' - # volumes: - # - healthcheck-volume:/healthcheck - # networks: - # - elevate_net - # manager: - # container_name: '${COMPOSE_PROJECT_NAME:-citus}_manager' - # image: 'citusdata/membership-manager:0.3.0' - # volumes: - # - '${DOCKER_SOCK:-/var/run/docker.sock}:/var/run/docker.sock' - # - healthcheck-volume:/healthcheck - # depends_on: [master] - # environment: *AUTH - # networks: - # - elevate_net - - citus: - image: citusdata/citus:11.2.0 - container_name: 'citus_master' - ports: - - 5432:5432 - # expose: - # - 5432 - # command: > - # bash -c "while ! pg_isready -h localhost -U postgres -q; do sleep 1; done && - # psql -h localhost -U postgres -d -c 'CREATE EXTENSION citus; SELECT create_distributed_table(\"notification_templates\", \"id\");'" - environment: &AUTH - POSTGRES_USER: '${POSTGRES_USER:-postgres}' - POSTGRES_PASSWORD: '${POSTGRES_PASSWORD:-postgres}' - PGUSER: '${POSTGRES_USER:-postgres}' - PGPASSWORD: '${POSTGRES_PASSWORD:-postgres}' - POSTGRES_DB: 'user_Nov_27' - POSTGRES_HOST_AUTH_METHOD: '${POSTGRES_HOST_AUTH_METHOD:-trust}' - POSTGRES_LOG_STATEMENT: 'all' # Enable query logging (set to 'all' for all queries) - - networks: - - elevate_net - pgadmin: - image: dpage/pgadmin4 - container_name: elevate-pgadmin - restart: always - ports: - - '5500:80' - environment: - - PGADMIN_DEFAULT_EMAIL=user@shikshalokam.org - - PGADMIN_DEFAULT_PASSWORD=password - networks: - - elevate_net - logging: - driver: none -networks: - elevate_net: - external: false -volumes: - zookeeper-data: - kafka-data: - mongo-data: - redis_data: - healthcheck-volume: From 5e8a4d80b081e1ccca0f73fb1a6c378a4dcb3b38 Mon Sep 17 00:00:00 2001 From: vishnu Date: Mon, 19 Feb 2024 18:42:31 +0530 Subject: [PATCH 4/4] removed unwanted changes --- src/database/queries/sessions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/queries/sessions.js b/src/database/queries/sessions.js index b0521d6d5..83d7783ae 100644 --- a/src/database/queries/sessions.js +++ b/src/database/queries/sessions.js @@ -767,7 +767,7 @@ exports.getMentorsUpcomingSessionsFromView = async (page, limit, search, mentorI ${saasFilterClause} ORDER BY start_date ASC - OFFSETp + OFFSET :offset LIMIT :limit;