Skip to content

Commit

Permalink
Updates for web socket update
Browse files Browse the repository at this point in the history
  • Loading branch information
arcshiftsolutions committed Oct 27, 2023
1 parent a439a6d commit a579d63
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/src/messaging/handlers/edx-event-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const NATS = require('../message-pub-sub');
const {StringCodec} = require('nats');
const cacheService = require('../../components/cache-service');
const sc = StringCodec();
const TOPICS = [CONSTANTS.WS_MOVE_SCHOOL_TOPIC, CONSTANTS.WS_NEW_SECURE_MESSAGE_TOPIC];
const TOPICS = [CONSTANTS.WS_MOVE_SCHOOL_TOPIC, CONSTANTS.WS_NEW_SECURE_MESSAGE_TOPIC, CONSTANTS.WS_CREATE_SCHOOL_TOPIC];


function broadCastMessageToWebSocketClients(msg) {
Expand Down
14 changes: 8 additions & 6 deletions backend/src/messaging/handlers/institute-jetstream-subscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ const handleJetStreamMessage = async (err, msg) => {
const data = JSON.parse(StringCodec().decode(msg.data)); // it would always be a JSON string. ii will always be choreographed event.
logger.info(`Received message, on ${msg.subject} , Sequence :: [${msg.seq}], sid :: [${msg.sid}], redelivered :: [${msg.redelivered}] :: Data ::`, data);
try {
if (data.eventType === CONSTANTS.EVENT_TYPE.UPDATE_SCHOOL || data.eventType === CONSTANTS.EVENT_TYPE.CREATE_SCHOOL
if (data.eventType === CONSTANTS.EVENT_TYPE.UPDATE_SCHOOL
|| data.eventType === CONSTANTS.EVENT_TYPE.UPDATE_AUTHORITY || data.eventType === CONSTANTS.EVENT_TYPE.CREATE_AUTHORITY
|| data.eventType === CONSTANTS.EVENT_TYPE.UPDATE_DISTRICT || data.eventType === CONSTANTS.EVENT_TYPE.CREATE_DISTRICT) {
await handleInstituteEvent('NT');
await handleInstituteEvent('NT', CONSTANTS.INSTITUTE_CACHE_REFRESH_TOPIC);
}else if (data.eventType === CONSTANTS.EVENT_TYPE.CREATE_SCHOOL){
await handleInstituteEvent(data, CONSTANTS.WS_CREATE_SCHOOL_TOPIC);
}
msg.ack(); // acknowledge to JetStream
} catch (e) {
logger.error('Error while handling school data from update school event', e);
}
};

async function handleInstituteEvent(data) {
logger.info('Received institute message: ' + JSON.stringify(data));
NATS.publishMessage(CONSTANTS.INSTITUTE_CACHE_REFRESH_TOPIC, StringCodec().encode(safeStringify(data))).then(() => { // publish the message only if key was present in redis, otherwise just acknowledge to STAN.
logger.info(`Message published to ${CONSTANTS.INSTITUTE_CACHE_REFRESH_TOPIC}`, data);
async function handleInstituteEvent(data, topic) {
logger.debug('Received institute message: ' + JSON.stringify(data));
NATS.publishMessage(topic, StringCodec().encode(safeStringify(data))).then(() => { // publish the message only if key was present in redis, otherwise just acknowledge to STAN.
logger.info(`Message published to ${topic}`, data);
});
}

Expand Down
2 changes: 2 additions & 0 deletions backend/src/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const EVENT_OUTCOME = Object.freeze({
const EVENT_WS_TOPIC = 'EVENT_WS_TOPIC';
const INSTITUTE_CACHE_REFRESH_TOPIC = 'INSTITUTE_CACHE_REFRESH_TOPIC';
const WS_MOVE_SCHOOL_TOPIC = 'WS_MOVE_SCHOOL_TOPIC';
const WS_CREATE_SCHOOL_TOPIC = 'WS_CREATE_SCHOOL_TOPIC';
const WS_NEW_SECURE_MESSAGE_TOPIC = 'WS_NEW_SECURE_MESSAGE_TOPIC';
module.exports = {
FILTER_OPERATION,
Expand All @@ -179,5 +180,6 @@ module.exports = {
INSTITUTE_CACHE_REFRESH_TOPIC,
CACHE_KEYS,
WS_MOVE_SCHOOL_TOPIC,
WS_CREATE_SCHOOL_TOPIC,
WS_NEW_SECURE_MESSAGE_TOPIC
};
18 changes: 18 additions & 0 deletions frontend/src/components/institute/SchoolList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ import {authStore} from '@/store/modules/auth';
import {appStore} from '@/store/modules/app';
import {edxStore} from '@/store/modules/edx';
import {instituteStore} from '@/store/modules/institute';
import {notificationsStore} from "@/store/modules/notifications";
export default {
name: 'SchoolListPage',
Expand Down Expand Up @@ -483,6 +484,7 @@ export default {
...mapState(authStore, ['userInfo', 'SCHOOL_ADMIN_ROLE', 'INDEPENDENT_SCHOOLS_ADMIN_ROLE', 'OFFSHORE_SCHOOLS_ADMIN_ROLE']),
...mapState(appStore, ['schoolsMap']),
...mapState(edxStore, ['schoolSearchParams']),
...mapState(notificationsStore, ['notification']),
...mapState(instituteStore, ['facilityTypeCodes', 'activeFacilityTypeCodes', 'schoolCategoryFacilityTypesMap', 'activeSchoolCategoryTypeCodes', 'schoolCategoryTypeCodes', 'schoolReportingRequirementTypeCodes']),
schoolFacilityTypes() {
if (!this.activeFacilityTypeCodes || !this.schoolCategoryTypeFilter) {
Expand All @@ -496,6 +498,22 @@ export default {
},
},
watch: {
notification(notificationData) {
if (notificationData) {
console.log('Here: ' + JSON.stringify(notificationData));
if (notificationData.eventType === 'CREATE_SCHOOL' && notificationData.eventOutcome === 'SCHOOL_CREATED' && notificationData.eventPayload) {
try {
const schoolData = JSON.parse(notificationData.eventPayload);
if (schoolData.schoolId) {
const message = `School created successfully. <a style="font-weight: bold" href="/institute/school/${schoolData.schoolId}/details">Click here to go to new school</a>.`;
this.setSuccessAlert(message);
}
} catch (e) {
console.error(e);
}
}
}
},
pageSize() {
this.getSchoolList();
},
Expand Down

0 comments on commit a579d63

Please sign in to comment.