@@ -122,7 +122,15 @@ async function createUserSkill (userId, skillProviderName, skillName, certifierI
122
122
}
123
123
const skillProvider = await helper . getUbahnSingleRecord ( '/skillsProviders' , { name : skillProviderName } )
124
124
const skill = await helper . getUbahnSingleRecord ( '/skills' , { skillProviderId : skillProvider . id , name : skillName } )
125
- await helper . createUbahnRecord ( `/users/${ userId } /skills` , { certifierId, certifiedDate, metricValue, skillId : skill . id } )
125
+
126
+ // Does the skill already exist on the user?
127
+ const existingSkill = await helper . getUbahnSingleRecord ( `/users/${ userId } /skills/${ skill . id } ` , { } , true )
128
+
129
+ if ( ! existingSkill ) {
130
+ await helper . createUbahnRecord ( `/users/${ userId } /skills` , { certifierId, certifiedDate, metricValue, skillId : skill . id } )
131
+ } else {
132
+ await helper . updateUBahnRecord ( `/users/${ userId } /skills/${ skill . id } ` , { certifierId, certifiedDate, metricValue } )
133
+ }
126
134
}
127
135
128
136
/**
@@ -143,7 +151,13 @@ async function createAchievement (userId, providerName, certifierId, certifiedDa
143
151
return
144
152
}
145
153
const achievementsProvider = await helper . getUbahnSingleRecord ( '/achievementsProviders' , { name : providerName } )
146
- await helper . createUbahnRecord ( `/users/${ userId } /achievements` , { certifierId, certifiedDate, name, uri, achievementsProviderId : achievementsProvider . id } )
154
+ const existingAchievement = await helper . getUbahnSingleRecord ( `/users/${ userId } /achievements/${ achievementsProvider . id } ` , { } , true )
155
+
156
+ if ( ! existingAchievement ) {
157
+ await helper . createUbahnRecord ( `/users/${ userId } /achievements` , { certifierId, certifiedDate, name, uri, achievementsProviderId : achievementsProvider . id } )
158
+ } else {
159
+ await helper . updateUBahnRecord ( `/users/${ userId } /achievements/${ achievementsProvider . id } ` , { certifierId, certifiedDate, name, uri } )
160
+ }
147
161
}
148
162
149
163
/**
@@ -164,7 +178,14 @@ async function createUserAttributes (userId, record) {
164
178
const attributeGroup = await helper . getUbahnSingleRecord ( '/attributeGroups' , { name : record [ `attributeGroupName${ i } ` ] } )
165
179
const attribute = await helper . getUbahnSingleRecord ( '/attributes' , { attributeGroupId : attributeGroup . id , name : record [ `attributeName${ i } ` ] } )
166
180
const value = _ . toString ( record [ `attributeValue${ i } ` ] )
167
- await helper . createUbahnRecord ( `/users/${ userId } /attributes` , { attributeId : attribute . id , value } )
181
+
182
+ const existingAttribute = await helper . getUbahnSingleRecord ( `/users/${ userId } /attributes/${ attribute . id } ` , { } , true )
183
+
184
+ if ( ! existingAttribute ) {
185
+ await helper . createUbahnRecord ( `/users/${ userId } /attributes` , { attributeId : attribute . id , value } )
186
+ } else {
187
+ await helper . updateUBahnRecord ( `/users/${ userId } /attributes/${ attribute . id } ` , { value } )
188
+ }
168
189
i ++
169
190
}
170
191
}
0 commit comments