Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 2259e13

Browse files
updated user import to update badges
1 parent db849be commit 2259e13

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

server/services/admin/admin.class.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-unused-vars */
22

33
const { asyncForEach, genInviteCode } = require('../../helper/seed-helpers');
4-
const { keyBy, isEmpty, isString } = require('lodash');
4+
const { keyBy, isEmpty, isString, difference, merge } = require('lodash');
55

66
class Service {
77
constructor (options) {
@@ -147,9 +147,31 @@ class Service {
147147
}
148148
});
149149
if (!userWithEmail.total) {
150+
// create new user
150151
const res = await this.app.service('invites').create(query);
151152
output.push(res);
153+
} else if (userWithEmail.total === 1 && difference(query.badgeIds, userWithEmail.data[0].badgeIds).length) {
154+
// update badges of existing user
155+
156+
let user = await this.app.service('users').find({
157+
query: {
158+
email: invite.email,
159+
$select: '_id'
160+
}
161+
});
162+
if (!user.total === 1) {
163+
return;
164+
}
165+
user = user.data.pop();
166+
let res = await this.app.service('users').patch(user._id, {
167+
$set: {
168+
badgeIds: merge(query.badgeIds, userWithEmail.data[0].badgeIds)
169+
}
170+
});
171+
res.wasUpdated = true;
172+
output.push(res);
152173
}
174+
153175
} catch (err) {
154176
this.app.error(err);
155177
}

0 commit comments

Comments
 (0)