@@ -144,8 +144,17 @@ async function createUserSkill (userId, skillProviderName, skillName, certifierI
144
144
return
145
145
}
146
146
const skillProvider = await helper . getUbahnSingleRecord ( '/skillsProviders' , { name : skillProviderName } )
147
+
148
+ if ( ! skillProvider ) {
149
+ throw Error ( `Cannot find skill provider with name ${ skillProviderName } ` )
150
+ }
151
+
147
152
const skill = await helper . getUbahnSingleRecord ( '/skills' , { skillProviderId : skillProvider . id , name : skillName } )
148
153
154
+ if ( ! skill ) {
155
+ throw Error ( `Cannot find skill with name ${ skillName } under skill provider ${ skillProviderName } ` )
156
+ }
157
+
149
158
// Does the skill already exist on the user?
150
159
const existingSkill = await helper . getUbahnSingleRecord ( `/users/${ userId } /skills/${ skill . id } ` , { } , true )
151
160
@@ -174,6 +183,11 @@ async function createAchievement (userId, providerName, certifierId, certifiedDa
174
183
return
175
184
}
176
185
const achievementsProvider = await helper . getUbahnSingleRecord ( '/achievementsProviders' , { name : providerName } )
186
+
187
+ if ( ! achievementsProvider ) {
188
+ throw Error ( `Cannot find achievement provider with name ${ providerName } ` )
189
+ }
190
+
177
191
const existingAchievement = await helper . getUbahnSingleRecord ( `/users/${ userId } /achievements/${ achievementsProvider . id } ` , { } , true )
178
192
179
193
if ( ! existingAchievement || ! existingAchievement . id ) {
@@ -201,7 +215,17 @@ async function createUserAttributes (userId, record) {
201
215
return
202
216
}
203
217
const attributeGroup = await helper . getUbahnSingleRecord ( '/attributeGroups' , { name : record [ `attributeGroupName${ i } ` ] } )
218
+
219
+ if ( ! attributeGroup ) {
220
+ throw Error ( `Cannot find attribute group with name ${ record [ `attributeGroupName${ i } ` ] } ` )
221
+ }
222
+
204
223
const attribute = await helper . getUbahnSingleRecord ( '/attributes' , { attributeGroupId : attributeGroup . id , name : record [ `attributeName${ i } ` ] } )
224
+
225
+ if ( ! attribute ) {
226
+ throw Error ( `Cannot find attribute with name ${ record [ `attributeName${ i } ` ] } under attribute group wth name ${ record [ `attributeGroupName${ i } ` ] } ` )
227
+ }
228
+
205
229
const value = _ . toString ( record [ `attributeValue${ i } ` ] )
206
230
const existingAttribute = await helper . getUbahnSingleRecord ( `/users/${ userId } /attributes/${ attribute . id } ` , { } , true )
207
231
0 commit comments