From eb4ec33b44fd362a60526f7454f64d3dec8b9b26 Mon Sep 17 00:00:00 2001 From: Marco Villeneuve Date: Fri, 15 Dec 2023 15:36:17 -0800 Subject: [PATCH 1/3] Added pulling correct contact name --- backend/src/components/institute/institute.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/src/components/institute/institute.js b/backend/src/components/institute/institute.js index c0d7da23f..8f71b28a0 100644 --- a/backend/src/components/institute/institute.js +++ b/backend/src/components/institute/institute.js @@ -1026,7 +1026,19 @@ async function getSchoolHistoryPaginated(req, res) { searchCriteriaList: JSON.stringify(historySearchCriteria) } }; + + let edxUsers = await getData(config.get('server:edx:edxUsersURL')); let response = await getData(config.get('server:institute:rootURL') + '/school/history/paginated', schoolHistorySearchParam); + + response.content.forEach((element) => { + if(element.updateUser?.length > 10){ + let val = edxUsers.find(user => user.edxUserID === element.updateUser.replace('EDX/', '')); + if(val){ + element.updateUser = (val.firstName + ' ' + val.lastName).trim(); + } + } + }); + return res.status(HttpStatus.OK).json(response); } catch (e) { logApiError(e, 'getSchoolsPaginated', 'Error occurred while attempting to GET schools paginated.'); From 3582e6b7f36781c47b80adf0b1066832cc4b431c Mon Sep 17 00:00:00 2001 From: Marco Villeneuve Date: Fri, 15 Dec 2023 15:41:35 -0800 Subject: [PATCH 2/3] Switch to a promise --- backend/src/components/institute/institute.js | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/backend/src/components/institute/institute.js b/backend/src/components/institute/institute.js index 8f71b28a0..72b3d11ad 100644 --- a/backend/src/components/institute/institute.js +++ b/backend/src/components/institute/institute.js @@ -1,8 +1,8 @@ 'use strict'; -const { logApiError, getData, errorResponse } = require('../utils'); +const { logApiError, getData, errorResponse, getCodeTable, putData} = require('../utils'); const HttpStatus = require('http-status-codes'); const cacheService = require('../cache-service'); -const {FILTER_OPERATION, VALUE_TYPE, CONDITION} = require('../../util/constants'); +const {FILTER_OPERATION, VALUE_TYPE, CONDITION, CACHE_KEYS} = require('../../util/constants'); const config = require('../../config'); const {LocalDateTime, LocalDate, DateTimeFormatter} = require('@js-joda/core'); const utils = require('../utils'); @@ -1027,19 +1027,27 @@ async function getSchoolHistoryPaginated(req, res) { } }; - let edxUsers = await getData(config.get('server:edx:edxUsersURL')); - let response = await getData(config.get('server:institute:rootURL') + '/school/history/paginated', schoolHistorySearchParam); + Promise.all([ + getData(config.get('server:edx:edxUsersURL')), + getData(config.get('server:institute:rootURL') + '/school/history/paginated', schoolHistorySearchParam) + ]) + .then(async ([edxUserResponse, schoolHistoryResponse]) => { + if (edxUserResponse && schoolHistoryResponse) { + schoolHistoryResponse.content.forEach((element) => { + if(element.updateUser?.length > 10){ + let val = edxUserResponse.find(user => user.edxUserID === element.updateUser.replace('EDX/', '')); + if(val){ + element.updateUser = (val.firstName + ' ' + val.lastName).trim(); + } + } + }); - response.content.forEach((element) => { - if(element.updateUser?.length > 10){ - let val = edxUsers.find(user => user.edxUserID === element.updateUser.replace('EDX/', '')); - if(val){ - element.updateUser = (val.firstName + ' ' + val.lastName).trim(); + return res.status(HttpStatus.OK).json(schoolHistoryResponse); } - } - }); - - return res.status(HttpStatus.OK).json(response); + }).catch(async e => { + await logApiError(e, 'getSchoolsPaginated', 'Error occurred while attempting to GET schools paginated.'); + return errorResponse(res); + }); } catch (e) { logApiError(e, 'getSchoolsPaginated', 'Error occurred while attempting to GET schools paginated.'); return errorResponse(res); From 4ffb91cf4ebac7dd2e2d3456cefdd0b50738fae2 Mon Sep 17 00:00:00 2001 From: Marco Villeneuve Date: Fri, 15 Dec 2023 15:42:22 -0800 Subject: [PATCH 3/3] Cleanup --- backend/src/components/institute/institute.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/components/institute/institute.js b/backend/src/components/institute/institute.js index 72b3d11ad..fb5d790a5 100644 --- a/backend/src/components/institute/institute.js +++ b/backend/src/components/institute/institute.js @@ -1,8 +1,8 @@ 'use strict'; -const { logApiError, getData, errorResponse, getCodeTable, putData} = require('../utils'); +const { logApiError, getData, errorResponse} = require('../utils'); const HttpStatus = require('http-status-codes'); const cacheService = require('../cache-service'); -const {FILTER_OPERATION, VALUE_TYPE, CONDITION, CACHE_KEYS} = require('../../util/constants'); +const {FILTER_OPERATION, VALUE_TYPE, CONDITION} = require('../../util/constants'); const config = require('../../config'); const {LocalDateTime, LocalDate, DateTimeFormatter} = require('@js-joda/core'); const utils = require('../utils');