export async function canDeleteAffiliation (userId, affiliationId) {
  const affiliation = await Affiliation.find(affiliationId)
  return affiliation.get('user_id') === userId
}

export async function createAffiliation (userId, { role, preposition, orgName, url }) {
  if (userId && role && preposition && orgName) {
    return Affiliation.create({
      userId,
      role,
      preposition,
      orgName,
      url
    })
  } else {
    throw new Error(`Invalid parameters to create affiliation`)
  }
}

export function deleteAffiliation (userId, id) {
  if (userId && id && canDeleteAffiliation(userId, id)) {
    return Affiliation.delete(id)
  } else {
    throw new Error(`Invalid parameters to delete affiliation`)
  }
}

@@ -1,28 +1,63 @@
+import validator from 'validator'%0A%0A
 export async function canDel
@@ -291,24 +291,98 @@
 e, url %7D) %7B%0A
+  if (!validator.isURL(url)) throw new Error(%60Please enter a valid URL.%60)%0A
   if (userId

add some url validation when adding an affiliation