File size: 1,066 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
exports.up = function(r, conn) {
const updateReputation = (userId, communityId, score, type) => {
return r
.table('usersCommunities')
.getAll(userId, { index: 'userId' })
.filter({ communityId })
.update({
reputation: r.row('reputation').add(score),
})
.run(conn)
.then(() => {
return r
.table('reputationEvents')
.insert({
timestamp: new Date(),
userId,
type,
communityId,
score,
})
.run(conn);
});
};
return r
.table('threads')
.filter(row => row.hasFields('deletedAt').not())
.run(conn)
.then(cursor => cursor.toArray())
.then(threads => {
const threadPromises = threads.map(thread => {
return updateReputation(
thread.creatorId,
thread.communityId,
100,
'thread created'
);
});
return Promise.all(threadPromises);
});
};
exports.down = function(r, conn) {
return Promise.resolve();
};
|