11const db = require ( '../db' )
22const { unpack, ValidationError, checkRequiredProperties, PropertyRequiredError } = require ( '../lib/utils' )
3- const { map, has, propEq, anyPass, forEach, mergeRight , prop, assoc, pick, keys } = require ( 'ramda' )
3+ const { map, has, propEq, anyPass, forEach, prop, assoc, pick, keys } = require ( 'ramda' )
44
55/**
66 * Given the profile type return the db table
@@ -40,7 +40,8 @@ const profileTypeValid = anyPass([
4040const visibilityValid = anyPass ( [
4141 propEq ( 'visibility' , 'public' ) ,
4242 propEq ( 'visibility' , 'team' ) ,
43- propEq ( 'visibility' , 'org' )
43+ propEq ( 'visibility' , 'org' ) ,
44+ propEq ( 'visibility' , 'org_staff' )
4445] )
4546
4647/**
@@ -51,7 +52,7 @@ const visibilityValid = anyPass([
5152 * @param {string } attribute.description Description of the attribute
5253 * @param {string } attribute.profileType enum: 'owner', 'user', 'team'
5354 * @param {boolean } attribute.required whether this attribute is required to be filled
54- * @param {enum } attribute.visibility enum: 'owner ', 'user', 'team'
55+ * @param {enum } attribute.visibility enum: 'org_staff', 'org ', 'user', 'team'
5556 */
5657function checkProfileKey ( attribute ) {
5758 checkRequiredProperties ( [ 'name' , 'profileType' ] , attribute )
@@ -61,7 +62,7 @@ function checkProfileKey (attribute) {
6162 }
6263
6364 if ( has ( 'visibility' , attribute ) && ! visibilityValid ( attribute ) ) {
64- throw new ValidationError ( 'visibility should be one of "public", "team" or "org "' )
65+ throw new ValidationError ( 'visibility should be one of "public", "team", "org" or "org_staff "' )
6566 }
6667}
6768
@@ -73,7 +74,7 @@ function checkProfileKey (attribute) {
7374 * @param {string } attributes[].description Description of the attribute
7475 * @param {string } attributes[].profileType enum: 'owner', 'user', 'team'
7576 * @param {boolean } attributes[].required whether this attribute is required to be filled
76- * @param {enum } attributes[].visibility enum: 'owner ', 'user', 'team'
77+ * @param {enum } attributes[].visibility enum: 'org_staff', 'org ', 'user', 'team'
7778 * @param {string } ownerType enum: 'owner', 'user', 'team'
7879 * @param {integer } ownerId iD in owner, user or team tables
7980 */
@@ -114,11 +115,11 @@ async function addProfileKeys (attributes, ownerType, ownerId) {
114115 * @param {integer } id id of key to modify
115116 * @param {string } attribute.description Description of the attribute
116117 * @param {boolean } attribute.required whether this attribute is required to be filled
117- * @param {enum } attribute.visibility enum: 'owner ', 'user', 'team'
118+ * @param {enum } attribute.visibility enum: 'org_staff', 'org ', 'user', 'team'
118119 */
119120async function modifyProfileKey ( id , attribute ) {
120121 if ( has ( 'visibility' , attribute ) && ! visibilityValid ( attribute ) ) {
121- throw new ValidationError ( 'visibility should be one of "public", "team" or "org "' )
122+ throw new ValidationError ( 'visibility should be one of "public", "team", "org" or "org_staff "' )
122123 }
123124
124125 const conn = await db ( )
@@ -209,10 +210,11 @@ async function setProfile (attributeValues, profileType, id) {
209210 tags = pick ( map ( prop ( 'id' ) , tagsInDB ) , tags )
210211
211212 // Add the attribute values
212- tags = attributeValues . reduce (
213- ( acc , curr ) => mergeRight ( acc , { [ curr [ 'key_id' ] ] : curr [ 'value' ] } ) ,
214- tags
215- )
213+ attributeValues . forEach ( tagPair => {
214+ if ( tagPair . key_id ) {
215+ tags [ tagPair . key_id ] = tagPair . value
216+ }
217+ } )
216218
217219 const table = getTableForProfileType ( profileType )
218220
0 commit comments