 utils = require './utils'
 
 module.exports = (con, config) ->
+  # replaces all ids in a group with pseudonyms
+  # (do not pass the ids to the user)
   desensetizeGroupQuery = (query) ->
     query.merge((g) ->
       users: idListToPseudonymList g("users")

        replaceStats: replaceStats
    )

  pseudonymListToIdList = (plist) ->
    rdb.expr(plist).map((p) -> rdb.table("Users").getAll(p,index:"pseudonym").nth(0)("id"))

  idListToPseudonymList = (idlist) ->
    idlist.map((id) -> rdb.table("Users").get(id)("pseudonym"))


  desensetizeGroup = (query) ->
    desensetizeGroupQuery(query).run(con)

  # see desensetizeGroupQuery
  desensetizeGroups = (query) ->
    desensetizeGroupQuery(query).run(con)

  # create new group for a user
  createGroup = (user_id, group_users) ->
    rdb.do(
      pseudonymListToIdList(group_users),
