@@ -114,6 +114,9 @@ async function getUserId (user) {
114
114
* @returns {Promise }
115
115
*/
116
116
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
+ }
117
120
const skillProvider = await helper . getUbahnSingleRecord ( '/skillsProviders' , { name : skillProviderName } )
118
121
const skill = await helper . getUbahnSingleRecord ( '/skills' , { skillProviderId : skillProvider . id , name : skillName } )
119
122
await helper . createUbahnRecord ( `/users/${ userId } /skills` , { certifierId, certifiedDate, metricValue, skillId : skill . id } )
@@ -130,6 +133,9 @@ async function createUserSkill (userId, skillProviderName, skillName, certifierI
130
133
* @returns {Promise }
131
134
*/
132
135
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
+ }
133
139
const achievementsProvider = await helper . getUbahnSingleRecord ( '/achievementsProviders' , { name : providerName } )
134
140
await helper . createUbahnRecord ( `/users/${ userId } /achievements` , { certifierId, certifiedDate, name, uri, achievementsProviderId : achievementsProvider . id } )
135
141
}
@@ -143,6 +149,9 @@ async function createAchievement (userId, providerName, certifierId, certifiedDa
143
149
async function createUserAttributes ( userId , record ) {
144
150
let i = 1
145
151
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
+ }
146
155
const attributeGroup = await helper . getUbahnSingleRecord ( '/attributeGroups' , { name : record [ `attributeGroupName${ i } ` ] } )
147
156
const attribute = await helper . getUbahnSingleRecord ( '/attributes' , { attributeGroupId : attributeGroup . id , name : record [ `attributeName${ i } ` ] } )
148
157
const value = _ . toString ( record [ `attributeValue${ i } ` ] )
0 commit comments