Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 5201610

Browse files
Introduce checks about required data for each user property
1 parent 364948c commit 5201610

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/services/ProcessorService.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ async function getUserId (user) {
114114
* @returns {Promise}
115115
*/
116116
async function createUserSkill (userId, skillProviderName, skillName, certifierId, certifiedDate, metricValue) {
117+
if ((!skillProviderName || !skillName) && (certifierId || certifiedDate || metricValue)) {
118+
throw Error(`Skill provider or skill name is missing for user with id ${userId} `)
119+
}
117120
const skillProvider = await helper.getUbahnSingleRecord('/skillsProviders', { name: skillProviderName })
118121
const skill = await helper.getUbahnSingleRecord('/skills', { skillProviderId: skillProvider.id, name: skillName })
119122
await helper.createUbahnRecord(`/users/${userId}/skills`, { certifierId, certifiedDate, metricValue, skillId: skill.id })
@@ -130,6 +133,9 @@ async function createUserSkill (userId, skillProviderName, skillName, certifierI
130133
* @returns {Promise}
131134
*/
132135
async function createAchievement (userId, providerName, certifierId, certifiedDate, name, uri) {
136+
if (!providerName && (certifierId || certifiedDate || name || uri)) {
137+
throw Error(`Achievement provider name is missing for user with id ${userId}`)
138+
}
133139
const achievementsProvider = await helper.getUbahnSingleRecord('/achievementsProviders', { name: providerName })
134140
await helper.createUbahnRecord(`/users/${userId}/achievements`, { certifierId, certifiedDate, name, uri, achievementsProviderId: achievementsProvider.id })
135141
}
@@ -143,6 +149,9 @@ async function createAchievement (userId, providerName, certifierId, certifiedDa
143149
async function createUserAttributes (userId, record) {
144150
let i = 1
145151
while (record[`attributeValue${i}`]) {
152+
if ((!record[`attributeGroupName${i}`] || !record[`attributeName${i}`]) && record[`attributeValue${i}`]) {
153+
throw Error(`Attribute group name or attribute name is missing for user with id ${userId} and with attribute value ${record[`attributeValue${i}`]}`)
154+
}
146155
const attributeGroup = await helper.getUbahnSingleRecord('/attributeGroups', { name: record[`attributeGroupName${i}`] })
147156
const attribute = await helper.getUbahnSingleRecord('/attributes', { attributeGroupId: attributeGroup.id, name: record[`attributeName${i}`] })
148157
const value = _.toString(record[`attributeValue${i}`])

0 commit comments

Comments
 (0)