summaryrefslogtreecommitdiffstats
path: root/models/wekanmapper.js
blob: f4c110f768ce59d197c08087ce6cefec4be7e5ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
export function getMembersToMap(data) {
  // we will work on the list itself (an ordered array of objects) when a
  // mapping is done, we add a 'wekan' field to the object representing the
  // imported member
  const membersToMap = data.members;
  const users = data.users;
  // auto-map based on username
  membersToMap.forEach((importedMember) => {
    importedMember.id = importedMember.userId;
    delete importedMember.userId;
    const user = users.filter((user) => {
      return user._id === importedMember.id;
    })[0];
    if (user.profile && user.profile.fullname) {
      importedMember.fullName = user.profile.fullname;
    }
    importedMember.username = user.username;
    const wekanUser = Users.findOne({ username: importedMember.username });
    if (wekanUser) {
      importedMember.wekanId = wekanUser._id;
    }
  });
  return membersToMap;
}