Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / server / serializers / rest / troupe-ban-strategy.js
blobc8088805ae6b24a105c84b3fdd6de9a4b80e41b0
1 'use strict';
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;
11 });
12 var banningUsers = troupeBans.map(function(troupeBan) {
13 return troupeBan.bannedBy;
14 });
16 return userIdStategy.preload(userIds.concat(banningUsers));
19 this.map = function(troupeBan) {
20 var bannedBy = userIdStategy.map(troupeBan.bannedBy);
22 const serializedData = {
23 bannedBy: bannedBy,
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;