3 var UserIdStrategy = require('./user-id-strategy');
5 function TroupeBanStrategy(options) {
6 var userIdStategy = new UserIdStrategy(options);
8 this.preload = function(troupeBans) {
9 var userIds = troupeBans.map(function(troupeBan) {
10 return troupeBan.userId;
12 var banningUsers = troupeBans.map(function(troupeBan) {
13 return troupeBan.bannedBy;
16 return userIdStategy.preload(userIds.concat(banningUsers));
19 this.map = function(troupeBan) {
20 var bannedBy = userIdStategy.map(troupeBan.bannedBy);
22 const serializedData = {
24 dateBanned: troupeBan.dateBanned
27 if (troupeBan.userId) {
28 const user = userIdStategy.map(troupeBan.userId);
29 serializedData.user = user;
32 if (troupeBan.virtualUser) {
33 serializedData.virtualUser = {
34 type: troupeBan.virtualUser.type,
35 externalId: troupeBan.virtualUser.externalId
39 return serializedData;
42 TroupeBanStrategy.prototype = {
43 name: 'TroupeBanStrategy'
46 module.exports = TroupeBanStrategy;