diff --git a/README.md b/README.md index 2024f68..dffe173 100755 --- a/README.md +++ b/README.md @@ -62,11 +62,5 @@ Configuration for the application is at `config/default.js` and `config/producti - TEMPLATE_S3_BUCKET: the template s3 bucket name, default value is 'ubahn' - UPLOAD_S3_BUCKET: the upload s3 bucket name, default value is 'ubahn' - S3_OBJECT_URL_EXPIRY_TIME: the s3 url expiry time, default value is '1 hour' -- EMSI_CLIENT_ID: emsi oAuth 2.0 client id, used to get emis oAuth 2.0 token -- EMSI_CLIENT_SECRET: emsi oAuth 2.0 client secret, used to get emsi oAuth 2.0 token -- EMSI_GRANT_TYPE: emsi oAuth 2.0 grant_type, used to get emsi oAuth 2.0 token, should always be the string 'client_credentials' -- EMSI_SCOPE: emsi oAuth 2.0 scope, used to get emsi oAuth 2.0 token, default value is 'emsi_open' -- EMSI_AUTH_URL: emsi oAuth 2.0 auth url, used to get emsi oAuth 2.0 token, default value is 'https://auth.emsicloud.com/connect/token' -- EMSI_BASE_URL: emsi base url, used to get emsi skills, default value is 'https://skills.emsicloud.com/versions/latest' Also check out the client folder's README file for additional configurations to set for the front end. You can find the required configurations under client/src/config.js diff --git a/client/README.md b/client/README.md index d7ebb26..769df2c 100644 --- a/client/README.md +++ b/client/README.md @@ -11,8 +11,6 @@ REACT_APP_API_URL => The endpoint from which the application retrieves the users REACT_BULK_UPLOAD_TEMPLATE_ID => The id of the database record which is associated with the bulk upload template file. You would need to query the backend to get the id and then set it against this variable -REACT_APP_EMSI_SKILLPROVIDER_ID => The skill provider id with name 'EMSI'. Denotes that the skills with an externalId are using EMSI as the skill provider. - REACT_APP_ATTRIBUTE_ID_LOCATION REACT_APP_ATTRIBUTE_ID_COMPANY REACT_APP_ATTRIBUTE_ID_TITLE diff --git a/client/src/components/EditProfileModal/index.jsx b/client/src/components/EditProfileModal/index.jsx index 7957b93..dc2a733 100644 --- a/client/src/components/EditProfileModal/index.jsx +++ b/client/src/components/EditProfileModal/index.jsx @@ -10,7 +10,6 @@ import ProfileCard from "../ProfileCard"; import SuggestionBox from "../SuggestionBox"; import style from "./style.module.scss"; -import config from "../../config"; export default function EditProfileModal({ onCancel, @@ -64,7 +63,9 @@ export default function EditProfileModal({ const addSkill = (skill) => { // Verify that the skill does not already exist on the user const index = localUser.skills.findIndex( - (existingSkill) => existingSkill.externalId === skill.id + (existingSkill) => + existingSkill.skillProviderId === skill.skillProviderId && + existingSkill.externalId === skill.skillId ); const exists = localUser.skills[index]; @@ -78,10 +79,10 @@ export default function EditProfileModal({ delete skills[index].isDeleted; } else { skills.push({ - externalId: skill.id, // The skill id returned from EMSI becomes externalId in our db + externalId: skill.skillId, // The skill id returned from API becomes externalId in our db isNew: true, name: skill.name, - skillProviderId: config.EMSI_SKILLPROVIDER_ID, + skillProviderId: skill.skillProviderId, }); } diff --git a/client/src/components/FiltersSideMenu/filters.js b/client/src/components/FiltersSideMenu/filters.js index f54d0d8..a3f87a3 100644 --- a/client/src/components/FiltersSideMenu/filters.js +++ b/client/src/components/FiltersSideMenu/filters.js @@ -142,7 +142,13 @@ export default function SearchTabFilters() { const addSkillToFilter = (skill) => { const skillFilters = JSON.parse(JSON.stringify(search.selectedSkills)); - if (skillFilters.findIndex((s) => s.id === skill.id) !== -1) { + if ( + skillFilters.findIndex( + (s) => + s.skillProviderId === skill.skillProviderId && + s.skillId === skill.skillId + ) !== -1 + ) { return; } @@ -152,7 +158,11 @@ export default function SearchTabFilters() { const removeSkillFromFilter = (skill) => { const skillFilters = JSON.parse(JSON.stringify(search.selectedSkills)); - const index = skillFilters.findIndex((s) => s.id === skill.id); + const index = skillFilters.findIndex( + (s) => + s.skillProviderId === skill.skillProviderId && + s.skillId === skill.skillId + ); if (index === -1) { return; diff --git a/client/src/components/SuggestionBox/index.jsx b/client/src/components/SuggestionBox/index.jsx index b1a79d3..220832f 100644 --- a/client/src/components/SuggestionBox/index.jsx +++ b/client/src/components/SuggestionBox/index.jsx @@ -2,6 +2,7 @@ import React from "react"; import Autosuggest from "react-autosuggest"; import config from "../../config"; import api from "../../services/api"; +import { getSingleOrg } from "../../services/user-org"; import style from "./style.module.scss"; import _ from "lodash"; import { useSearch, FILTERS } from "../../lib/search"; @@ -59,12 +60,13 @@ const getSkillsSuggestions = async (apiClient, inputValue) => { } term = encodeURIComponent(term); + const organizationId = getSingleOrg(); - const url = `${config.API_PREFIX}/skills?q=${term}`; + const url = `${config.API_URL}/search/skills?organizationId=${organizationId}&keyword=${term}`; const { data } = await apiClient.get(url); - return data.skills; + return data; }; /** @@ -118,7 +120,7 @@ export default function SuggestionBox({ const [suggestions, setSuggestions] = React.useState([]); const [value, setValue] = React.useState(""); - const onChange = (event, { newValue }) => setValue(newValue.trim()); + const onChange = (event, { newValue }) => setValue(newValue); const onSuggestionsFetchRequested = async ({ value }) => { if (purpose === "locations") { diff --git a/client/src/config.js b/client/src/config.js index 02249be..408f2e2 100644 --- a/client/src/config.js +++ b/client/src/config.js @@ -9,7 +9,6 @@ export default { GROUPS_PER_PAGE: process.env.REACT_APP_GROUPS_PER_PAGE || 1000, BULK_UPLOAD_TEMPLATE_ID: process.env.REACT_APP_BULK_UPLOAD_TEMPLATE_ID, - EMSI_SKILLPROVIDER_ID: process.env.REACT_APP_EMSI_SKILLPROVIDER_ID, DEFAULT_SORT_ORDER: "name", ITEMS_PER_PAGE: 12, diff --git a/config/default.js b/config/default.js index b65d80b..08b7fcb 100755 --- a/config/default.js +++ b/config/default.js @@ -43,14 +43,5 @@ module.exports = { TEMPLATE_FILE_MIMETYPE: process.env.TEMPLATE_FILE_MIMETYPE || 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', TEMPLATE_S3_BUCKET: process.env.TEMPLATE_S3_BUCKET || 'ubahn', UPLOAD_S3_BUCKET: process.env.UPLOAD_S3_BUCKET || 'ubahn', - S3_OBJECT_URL_EXPIRY_TIME: process.env.S3_OBJECT_URL_EXPIRY_TIME || 60 * 60, - - EMSI: { - CLIENT_ID: process.env.EMSI_CLIENT_ID, - CLIENT_SECRET: process.env.EMSI_CLIENT_SECRET, - GRANT_TYPE: process.env.EMSI_GRANT_TYPE || 'client_credentials', - SCOPE: process.env.EMSI_SCOPE || 'emsi_open', - AUTH_URL: process.env.EMSI_AUTH_URL || 'https://auth.emsicloud.com/connect/token', - BASE_URL: process.env.EMSI_BASE_URL || 'https://skills.emsicloud.com/versions/latest' - } + S3_OBJECT_URL_EXPIRY_TIME: process.env.S3_OBJECT_URL_EXPIRY_TIME || 60 * 60 } diff --git a/docker/sample.api.env b/docker/sample.api.env index 62623b4..9304279 100644 --- a/docker/sample.api.env +++ b/docker/sample.api.env @@ -8,8 +8,6 @@ AUTH_SECRET= AWS_ACCESS_KEY_ID= AWS_REGION= AWS_SECRET_ACCESS_KEY= -EMSI_CLIENT_ID= -EMSI_CLIENT_SECRET= NODE_ENV= REACT_APP_API_PREFIX= REACT_APP_API_URL= @@ -17,7 +15,6 @@ REACT_APP_AUTH0_AUDIENCE= REACT_APP_AUTH0_CLIENTID= REACT_APP_AUTH0_DOMAIN= REACT_APP_BULK_UPLOAD_TEMPLATE_ID= -REACT_APP_EMSI_SKILLPROVIDER_ID= REACT_APP_GROUPS_API_URL= TEMPLATE_S3_BUCKET= TOKEN_CACHE_TIME= diff --git a/src/common/helper.js b/src/common/helper.js index d83f019..98ad448 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -288,40 +288,6 @@ async function postEvent (topic, payload) { await busApiClient.postEvent(message) } -// cache the emsi token -const tokenCache = new NodeCache() - -/** - * Get emsi token - * @returns {string} the emsi token - */ -async function getEmsiToken () { - let token = tokenCache.get('emsi_token') - if (!token) { - const res = await axios.post(config.EMSI.AUTH_URL, querystring.stringify({ - client_id: config.EMSI.CLIENT_ID, - client_secret: config.EMSI.CLIENT_SECRET, - grant_type: config.EMSI.GRANT_TYPE, - scope: config.EMSI.SCOPE - })) - token = res.data.access_token - tokenCache.set('emsi_token', token, res.data.expires_in) - } - return token -} - -/** - * Get data from emsi - * @param {String} path the emsi endpoint path - * @param {String} params get params - * @returns {Object} response data - */ -async function getEmsiObject (path, params) { - const token = await getEmsiToken() - const res = await axios.get(`${config.EMSI.BASE_URL}${path}`, { params, headers: { authorization: `Bearer ${token}` } }) - return res.data -} - module.exports = { wrapExpress, autoWrapExpress, @@ -334,6 +300,5 @@ module.exports = { generateS3Url, scan, validateDuplicate, - postEvent, - getEmsiObject + postEvent } diff --git a/src/controllers/SkillController.js b/src/controllers/SkillController.js deleted file mode 100644 index a46b3eb..0000000 --- a/src/controllers/SkillController.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Controller for Skill endpoints - */ -const service = require('../services/SkillService') - -/** - * Get skills - * @param {Object} req the request - * @param {Object} res the response - */ -async function getEntity (req, res) { - const result = await service.getEntity(req.query.q) - res.send(result) -} - -module.exports = { - getEntity -} diff --git a/src/routes.js b/src/routes.js index 69da571..64323c6 100644 --- a/src/routes.js +++ b/src/routes.js @@ -66,15 +66,6 @@ module.exports = { scopes: [constants.Scopes.GetTemplate, constants.Scopes.AllTemplate] } }, - '/skills': { - get: { - controller: 'SkillController', - method: 'getEntity', - auth: 'jwt', - access: constants.AllAuthenticatedUsers, - scopes: [constants.Scopes.GetSkill, constants.Scopes.AllSkill] - } - }, '/health': { get: { controller: 'HealthCheckController', diff --git a/src/services/SkillService.js b/src/services/SkillService.js deleted file mode 100644 index 9eaed08..0000000 --- a/src/services/SkillService.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * This service provides operations of skills. - */ -const helper = require('../common/helper') -const logger = require('../common/logger') - -/** - * Get skills by query param q. - * @param {String} q the query param - * @returns {Object} the Object with skills - */ -async function getEntity (q) { - const res = await helper.getEmsiObject('/skills', { q }) - return res -} - -module.exports = { - getEntity -} - -logger.buildService(module.exports)