2015-07-22 11:52:22 +02:00
|
|
|
import Ember from 'ember';
|
|
|
|
/* global sjcl */
|
|
|
|
|
2016-01-28 12:34:56 +01:00
|
|
|
export default function(attr, key) {
|
|
|
|
const defaultAttr = {
|
2015-07-22 11:52:22 +02:00
|
|
|
id: 'test',
|
|
|
|
title: 'default title',
|
|
|
|
description: 'default description',
|
|
|
|
pollType: 'FindADate',
|
|
|
|
answerType: 'YesNo',
|
|
|
|
answers: [
|
|
|
|
{
|
2016-01-28 12:34:56 +01:00
|
|
|
type: 'yes',
|
|
|
|
labelTranslation: 'answerTypes.yes.label',
|
|
|
|
icon: 'glyphicon glyphicon-thumbs-up',
|
|
|
|
label: 'Ja'
|
2015-07-22 11:52:22 +02:00
|
|
|
},
|
|
|
|
{
|
2016-01-28 12:34:56 +01:00
|
|
|
type: 'no',
|
|
|
|
labelTranslation: 'answerTypes.no.label',
|
|
|
|
icon: 'glyphicon glyphicon-thumbs-down',
|
|
|
|
label: 'Nein'
|
2015-07-22 11:52:22 +02:00
|
|
|
}
|
|
|
|
],
|
|
|
|
options: [
|
|
|
|
{
|
2016-01-28 12:34:56 +01:00
|
|
|
title: '2017-12-24'
|
2015-07-22 11:52:22 +02:00
|
|
|
},
|
|
|
|
{
|
2016-01-28 12:34:56 +01:00
|
|
|
title: '2018-01-01'
|
2015-07-22 11:52:22 +02:00
|
|
|
}
|
|
|
|
],
|
2016-01-28 12:34:56 +01:00
|
|
|
creationDate: '2015-04-01T11:11:11.111Z',
|
2015-07-22 11:52:22 +02:00
|
|
|
forceAnswer: true,
|
|
|
|
anonymousUser: false,
|
|
|
|
isDateTime: false,
|
|
|
|
users: [],
|
2015-08-19 22:00:01 +02:00
|
|
|
expirationDate: '',
|
2015-07-22 11:52:22 +02:00
|
|
|
timezone: '',
|
|
|
|
version: 'v0.3'
|
|
|
|
};
|
2016-01-28 12:34:56 +01:00
|
|
|
|
|
|
|
const encrypt = function(prop) {
|
2015-08-19 22:00:01 +02:00
|
|
|
return sjcl.encrypt(
|
|
|
|
key,
|
|
|
|
JSON.stringify(prop)
|
|
|
|
);
|
2015-07-22 11:52:22 +02:00
|
|
|
};
|
|
|
|
|
2016-01-28 12:34:56 +01:00
|
|
|
let data = Ember.merge(defaultAttr, attr);
|
|
|
|
|
|
|
|
const users = data.users.map(function(user, index) {
|
2015-08-21 12:10:02 +02:00
|
|
|
return {
|
2016-01-28 12:34:56 +01:00
|
|
|
id: `${data.id}_${index}`,
|
2015-08-21 12:10:02 +02:00
|
|
|
creationDate: encrypt(user.creationDate),
|
|
|
|
name: encrypt(user.name),
|
|
|
|
poll: data.id,
|
|
|
|
selections: encrypt(user.selections),
|
|
|
|
version: data.version
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
return [
|
|
|
|
200,
|
2016-01-28 12:34:56 +01:00
|
|
|
{ 'Content-Type': 'application/json' },
|
2015-07-27 20:28:00 +02:00
|
|
|
JSON.stringify({
|
|
|
|
poll: {
|
|
|
|
id: data.id,
|
2015-08-19 22:00:01 +02:00
|
|
|
title: encrypt(data.title),
|
|
|
|
description: encrypt(data.description),
|
|
|
|
pollType: encrypt(data.pollType),
|
|
|
|
answerType: encrypt(data.answerType),
|
|
|
|
answers: encrypt(data.answers),
|
|
|
|
options: encrypt(data.options),
|
|
|
|
creationDate: encrypt(data.creationDate),
|
|
|
|
forceAnswer: encrypt(data.forceAnswer),
|
|
|
|
anonymousUser: encrypt(data.anonymousUser),
|
|
|
|
isDateTime: encrypt(data.isDateTime),
|
|
|
|
timezone: encrypt(data.timezone),
|
|
|
|
expirationDate: encrypt(data.expirationDate),
|
2016-01-28 12:34:56 +01:00
|
|
|
users,
|
2015-07-27 20:28:00 +02:00
|
|
|
version: data.version
|
|
|
|
}
|
|
|
|
})
|
|
|
|
];
|
2015-07-22 11:52:22 +02:00
|
|
|
}
|