diff --git a/src/models/attachment.js b/src/models/attachment.js index 1c8650e0..09db232f 100644 --- a/src/models/attachment.js +++ b/src/models/attachment.js @@ -7,7 +7,7 @@ export default class AttachmentModel extends AbstractModel { super(data) this.created_by = new UserModel(this.created_by) this.file = new FileModel(this.file) - this.created = new Date(this.created * 1000) + this.created = new Date(this.created) } defaults() { @@ -16,7 +16,7 @@ export default class AttachmentModel extends AbstractModel { task_id: 0, file: FileModel, created_by: UserModel, - created: 0, + created: null, } } } diff --git a/src/models/file.js b/src/models/file.js index 74bfd050..d3da0bad 100644 --- a/src/models/file.js +++ b/src/models/file.js @@ -1,13 +1,18 @@ import AbstractModel from './abstractModel' export default class FileModel extends AbstractModel { + constructor(data) { + super(data) + this.created = new Date(this.created) + } + defaults() { return { id: 0, mime: '', name: '', size: '', - created: 0, + created: null, } } diff --git a/src/models/label.js b/src/models/label.js index 394d3973..a9e02a64 100644 --- a/src/models/label.js +++ b/src/models/label.js @@ -13,6 +13,9 @@ export default class LabelModel extends AbstractModel { } this.textColor = this.hasDarkColor() ? '#4a4a4a' : '#e5e5e5' this.created_by = new UserModel(this.created_by) + + this.created = new Date(this.created) + this.updated = new Date(this.updated) } defaults() { @@ -25,8 +28,8 @@ export default class LabelModel extends AbstractModel { listID: 0, textColor: '', - created: 0, - updated: 0 + created: null, + updated: null, } } diff --git a/src/models/linkShare.js b/src/models/linkShare.js index e18e7dc4..6c287758 100644 --- a/src/models/linkShare.js +++ b/src/models/linkShare.js @@ -8,6 +8,9 @@ export default class ListModel extends AbstractModel { super(data) this.shared_by = new UserModel(this.shared_by) + + this.created = new Date(this.created) + this.updated = new Date(this.updated) } // Default attributes that define the "empty" state. @@ -20,8 +23,8 @@ export default class ListModel extends AbstractModel { sharing_type: 0, listID: 0, - created: 0, - updated: 0, + created: null, + updated: null, } } } \ No newline at end of file diff --git a/src/models/list.js b/src/models/list.js index eff269fb..1289a836 100644 --- a/src/models/list.js +++ b/src/models/list.js @@ -13,8 +13,11 @@ export default class ListModel extends AbstractModel { }) this.owner = new UserModel(this.owner) + + this.created = new Date(this.created) + this.updated = new Date(this.updated) } - + // Default attributes that define the "empty" state. defaults() { return { @@ -24,9 +27,9 @@ export default class ListModel extends AbstractModel { owner: UserModel, tasks: [], namespaceID: 0, - - created: 0, - updated: 0, + + created: null, + updated: null, } } } \ No newline at end of file diff --git a/src/models/namespace.js b/src/models/namespace.js index 6e9738a5..0db10967 100644 --- a/src/models/namespace.js +++ b/src/models/namespace.js @@ -10,6 +10,9 @@ export default class NamespaceModel extends AbstractModel { return new ListModel(l) }) this.owner = new UserModel(this.owner) + + this.created = new Date(this.created) + this.updated = new Date(this.updated) } // Default attributes that define the 'empty' state. @@ -21,8 +24,8 @@ export default class NamespaceModel extends AbstractModel { owner: UserModel, lists: [], - created: 0, - updated: 0, + created: null, + updated: null, } } } \ No newline at end of file diff --git a/src/models/task.js b/src/models/task.js index de16a168..9d20831b 100644 --- a/src/models/task.js +++ b/src/models/task.js @@ -12,12 +12,12 @@ export default class TaskModel extends AbstractModel { this.listID = Number(this.listID) // Make date objects from timestamps - this.dueDate = this.parseDateIfNessecary(this.dueDate) - this.startDate = this.parseDateIfNessecary(this.startDate) - this.endDate = this.parseDateIfNessecary(this.endDate) + this.dueDate = new Date(this.dueDate) + this.startDate = new Date(this.startDate) + this.endDate = new Date(this.endDate) this.reminderDates = this.reminderDates.map(d => { - return this.parseDateIfNessecary(d) + return new Date(d) }) this.reminderDates.push(null) // To trigger the datepicker @@ -53,6 +53,9 @@ export default class TaskModel extends AbstractModel { this.attachments = this.attachments.map(a => { return new AttachmentModel(a) }) + + this.created = new Date(this.created) + this.updated = new Date(this.updated) } defaults() { @@ -77,8 +80,8 @@ export default class TaskModel extends AbstractModel { attachments: [], createdBy: UserModel, - created: 0, - updated: 0, + created: null, + updated: null, listID: 0, // Meta, only used when creating a new task } @@ -88,19 +91,6 @@ export default class TaskModel extends AbstractModel { // Helper functions /////////////// - /** - * Makes a js date object from a unix timestamp (in seconds). - * @param unixTimestamp - * @returns {*} - */ - parseDateIfNessecary(unixTimestamp) { - let dateobj = new Date(unixTimestamp * 1000) - if (unixTimestamp === 0) { - return null - } - return dateobj - } - /** * Parses the "repeat after x seconds" from the task into a usable js object inside the task. * This function should only be called from the constructor. diff --git a/src/models/taskAssignee.js b/src/models/taskAssignee.js index 6ded11bc..61ec8ae9 100644 --- a/src/models/taskAssignee.js +++ b/src/models/taskAssignee.js @@ -1,9 +1,14 @@ import AbstractModel from './abstractModel' export default class TaskAssigneeModel extends AbstractModel { + constructor(data) { + super(data) + this.created = new Date(this.created) + } + defaults() { return { - created: 0, + created: null, user_id: 0, task_id: 0, } diff --git a/src/models/taskRelation.js b/src/models/taskRelation.js index d88e8686..3c108e2f 100644 --- a/src/models/taskRelation.js +++ b/src/models/taskRelation.js @@ -1,10 +1,11 @@ import AbstractModel from './abstractModel' -import UserModel from "./user"; +import UserModel from './user' export default class TaskRelationModel extends AbstractModel { constructor(data) { super(data) this.created_by = new UserModel(this.created_by) + this.created = new Date(this.created) } defaults() { @@ -15,7 +16,7 @@ export default class TaskRelationModel extends AbstractModel { relation_kind: '', created_by: UserModel, - created: 0, + created: null, } } } \ No newline at end of file diff --git a/src/models/team.js b/src/models/team.js index ef53ff85..645b40ad 100644 --- a/src/models/team.js +++ b/src/models/team.js @@ -11,6 +11,9 @@ export default class TeamModel extends AbstractModel { return new TeamMemberModel(m) }) this.createdBy = new UserModel(this.createdBy) + + this.created = new Date(this.created) + this.updated = new Date(this.updated) } defaults() { @@ -22,8 +25,8 @@ export default class TeamModel extends AbstractModel { right: 0, createdBy: {}, - created: 0, - updated: 0 + created: null, + updated: null, } } } \ No newline at end of file diff --git a/src/models/teamList.js b/src/models/teamList.js index b960980f..994d62d3 100644 --- a/src/models/teamList.js +++ b/src/models/teamList.js @@ -1,5 +1,5 @@ import TeamShareBaseModel from './teamShareBase' -import {merge} from "lodash"; +import {merge} from 'lodash' export default class TeamListModel extends TeamShareBaseModel { defaults() { diff --git a/src/models/teamShareBase.js b/src/models/teamShareBase.js index 05393ce5..a2fd81e5 100644 --- a/src/models/teamShareBase.js +++ b/src/models/teamShareBase.js @@ -5,13 +5,19 @@ import AbstractModel from './abstractModel' * It is extended in a way so it can be used for namespaces as well for lists. */ export default class TeamShareBaseModel extends AbstractModel { + constructor(data) { + super(data) + this.created = new Date(this.created) + this.updated = new Date(this.updated) + } + defaults() { return { teamID: 0, right: 0, - created: 0, - updated: 0 + created: null, + updated: null } } } \ No newline at end of file diff --git a/src/models/user.js b/src/models/user.js index 30d68c40..c9bbae67 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -1,14 +1,20 @@ import AbstractModel from './abstractModel' export default class UserModel extends AbstractModel { + constructor(data) { + super(data) + this.created = new Date(this.created) + this.updated = new Date(this.updated) + } + defaults() { return { id: 0, avatarUrl: '', email: '', username: '', - created: 0, - updated: 0 + created: null, + updated: null, } } } \ No newline at end of file diff --git a/src/models/userShareBase.js b/src/models/userShareBase.js index f6aa0a16..7ca5ff95 100644 --- a/src/models/userShareBase.js +++ b/src/models/userShareBase.js @@ -1,13 +1,19 @@ import AbstractModel from './abstractModel' export default class UserShareBaseModel extends AbstractModel { + constructor(data) { + super(data) + this.created = new Date(this.created) + this.updated = new Date(this.updated) + } + defaults() { return { userID: 0, right: 0, - created: 0, - updated: 0, + created: null, + updated: null, } } } \ No newline at end of file diff --git a/src/services/attachment.js b/src/services/attachment.js index 19eef1e3..36815d7c 100644 --- a/src/services/attachment.js +++ b/src/services/attachment.js @@ -1,5 +1,6 @@ import AbstractService from './abstractService' import AttachmentModel from '../models/attachment' +import moment from 'moment' export default class AttachmentService extends AbstractService { constructor() { @@ -10,6 +11,11 @@ export default class AttachmentService extends AbstractService { }) } + processModel(model) { + model.created = moment(model.created).toISOString() + return model + } + uploadProgress = 0 useCreateInterceptor() { @@ -82,9 +88,4 @@ export default class AttachmentService extends AbstractService { cancel() }) } - - processModel(model) { - model.created = Math.round(+new Date(model.created) / 1000) - return model - } } diff --git a/src/services/label.js b/src/services/label.js index a0f523ef..741ec3eb 100644 --- a/src/services/label.js +++ b/src/services/label.js @@ -1,5 +1,6 @@ import AbstractService from './abstractService' import LabelModel from '../models/label' +import moment from 'moment' export default class LabelService extends AbstractService { constructor() { @@ -11,7 +12,13 @@ export default class LabelService extends AbstractService { delete: '/labels/{id}', }) } - + + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new LabelModel(data) } diff --git a/src/services/linkShare.js b/src/services/linkShare.js index 363025fc..57416e3c 100644 --- a/src/services/linkShare.js +++ b/src/services/linkShare.js @@ -1,5 +1,6 @@ import AbstractService from './abstractService' import LinkShareModel from '../models/linkShare' +import moment from 'moment' export default class ListService extends AbstractService { constructor() { @@ -11,6 +12,12 @@ export default class ListService extends AbstractService { }) } + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new LinkShareModel(data) } diff --git a/src/services/list.js b/src/services/list.js index c35eb3d9..d6ffcdca 100644 --- a/src/services/list.js +++ b/src/services/list.js @@ -1,6 +1,7 @@ import AbstractService from './abstractService' import ListModel from '../models/list' import TaskService from './task' +import moment from 'moment' export default class ListService extends AbstractService { constructor() { @@ -11,7 +12,13 @@ export default class ListService extends AbstractService { delete: '/lists/{id}', }) } - + + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new ListModel(data) } diff --git a/src/services/listUsers.js b/src/services/listUsers.js index f8f6ed93..a7699983 100644 --- a/src/services/listUsers.js +++ b/src/services/listUsers.js @@ -1,5 +1,6 @@ import AbstractService from './abstractService' import UserModel from '../models/user' +import moment from 'moment' export default class ListUserService extends AbstractService { constructor() { @@ -7,7 +8,13 @@ export default class ListUserService extends AbstractService { getAll: '/lists/{listID}/listusers' }) } - + + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new UserModel(data) } diff --git a/src/services/namespace.js b/src/services/namespace.js index 1c5b6cad..86ecebdc 100644 --- a/src/services/namespace.js +++ b/src/services/namespace.js @@ -1,5 +1,6 @@ import AbstractService from './abstractService' import NamespaceModel from '../models/namespace' +import moment from 'moment' export default class NamespaceService extends AbstractService { constructor() { @@ -12,6 +13,12 @@ export default class NamespaceService extends AbstractService { }); } + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new NamespaceModel(data) } diff --git a/src/services/task.js b/src/services/task.js index a3903090..96a4d2e2 100644 --- a/src/services/task.js +++ b/src/services/task.js @@ -1,6 +1,7 @@ import AbstractService from './abstractService' import TaskModel from '../models/task' import AttachmentService from './attachment' +import moment from 'moment' export default class TaskService extends AbstractService { constructor() { @@ -29,10 +30,12 @@ export default class TaskService extends AbstractService { // Ensure the listID is an int model.listID = Number(model.listID) - // Convert the date in a unix timestamp - model.dueDate = model.dueDate !== null ? Math.round(+new Date(model.dueDate) / 1000) : model.dueDate - model.startDate = model.startDate !== null ? Math.round(+new Date(model.startDate) / 1000): model.startDate - model.endDate = model.endDate !== null ? Math.round(+new Date(model.endDate) / 1000) : model.endDate + // Convert dates into an iso string + model.dueDate = moment(model.dueDate).toISOString() + model.startDate = moment(model.startDate).toISOString() + model.endDate = moment(model.endDate).toISOString() + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() // remove all nulls, these would create empty reminders for (const index in model.reminderDates) { @@ -44,7 +47,7 @@ export default class TaskService extends AbstractService { // Make normal timestamps from js dates if(model.reminderDates.length > 0) { model.reminderDates = model.reminderDates.map(r => { - return Math.round(+new Date(r) / 1000) + return moment(r).toISOString() }) } diff --git a/src/services/taskAssignee.js b/src/services/taskAssignee.js index 33ac90d3..e788bee1 100644 --- a/src/services/taskAssignee.js +++ b/src/services/taskAssignee.js @@ -1,5 +1,6 @@ import AbstractService from './abstractService' import TaskAssigneeModel from '../models/taskAssignee' +import moment from 'moment' export default class TaskAssigneeService extends AbstractService { constructor() { @@ -8,7 +9,12 @@ export default class TaskAssigneeService extends AbstractService { delete: '/tasks/{task_id}/assignees/{user_id}', }) } - + + processModel(model) { + model.created = moment(model.created).toISOString() + return model + } + modelFactory(data) { return new TaskAssigneeModel(data) } diff --git a/src/services/taskCollection.js b/src/services/taskCollection.js index 28808e33..dc7f499e 100644 --- a/src/services/taskCollection.js +++ b/src/services/taskCollection.js @@ -1,5 +1,6 @@ import AbstractService from './abstractService' import TaskModel from '../models/task' +import moment from 'moment' export default class TaskCollectionService extends AbstractService { constructor() { @@ -7,7 +8,13 @@ export default class TaskCollectionService extends AbstractService { getAll: '/lists/{listID}/tasks', }) } - + + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new TaskModel(data) } diff --git a/src/services/taskRelation.js b/src/services/taskRelation.js index 2c304a71..3f36fb93 100644 --- a/src/services/taskRelation.js +++ b/src/services/taskRelation.js @@ -1,5 +1,6 @@ import AbstractService from './abstractService' import TaskRelationModel from '../models/taskRelation' +import moment from 'moment' export default class TaskRelationService extends AbstractService { constructor() { @@ -8,7 +9,12 @@ export default class TaskRelationService extends AbstractService { delete: '/tasks/{task_id}/relations', }) } - + + processModel(model) { + model.created = moment(model.created).toISOString() + return model + } + modelFactory(data) { return new TaskRelationModel(data) } diff --git a/src/services/team.js b/src/services/team.js index 9824455a..f9b937da 100644 --- a/src/services/team.js +++ b/src/services/team.js @@ -1,5 +1,6 @@ import AbstractService from './abstractService' import TeamModel from '../models/team' +import moment from 'moment' export default class TeamService extends AbstractService { constructor() { @@ -12,6 +13,12 @@ export default class TeamService extends AbstractService { }); } + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new TeamModel(data) } diff --git a/src/services/teamList.js b/src/services/teamList.js index 2a9199e9..85724fb2 100644 --- a/src/services/teamList.js +++ b/src/services/teamList.js @@ -1,6 +1,7 @@ import AbstractService from './abstractService' import TeamListModel from '../models/teamList' import TeamModel from '../models/team' +import moment from 'moment' export default class TeamListService extends AbstractService { constructor() { @@ -12,6 +13,12 @@ export default class TeamListService extends AbstractService { }) } + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new TeamListModel(data) } diff --git a/src/services/teamMember.js b/src/services/teamMember.js index a9624d2b..b1985548 100644 --- a/src/services/teamMember.js +++ b/src/services/teamMember.js @@ -1,5 +1,6 @@ import AbstractService from './abstractService' import TeamMemberModel from '../models/teamMember' +import moment from 'moment' export default class TeamMemberService extends AbstractService { constructor() { @@ -8,7 +9,13 @@ export default class TeamMemberService extends AbstractService { delete: '/teams/{teamID}/members/{id}', // "id" is the user id because we're intheriting from a normal user }); } - + + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new TeamMemberModel(data) } diff --git a/src/services/teamNamespace.js b/src/services/teamNamespace.js index a66722e8..a469eec6 100644 --- a/src/services/teamNamespace.js +++ b/src/services/teamNamespace.js @@ -1,6 +1,7 @@ import AbstractService from './abstractService' import TeamNamespaceModel from '../models/teamNamespace' import TeamModel from '../models/team' +import moment from 'moment' export default class TeamNamespaceService extends AbstractService { constructor() { @@ -12,6 +13,12 @@ export default class TeamNamespaceService extends AbstractService { }) } + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new TeamNamespaceModel(data) } diff --git a/src/services/user.js b/src/services/user.js index 4ac8dde7..8beef892 100644 --- a/src/services/user.js +++ b/src/services/user.js @@ -1,5 +1,6 @@ import AbstractService from './abstractService' import UserModel from '../models/user' +import moment from 'moment' export default class UserService extends AbstractService { constructor() { @@ -7,7 +8,13 @@ export default class UserService extends AbstractService { getAll: '/users' }) } - + + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new UserModel(data) } diff --git a/src/services/userList.js b/src/services/userList.js index 70c0bad4..3670c939 100644 --- a/src/services/userList.js +++ b/src/services/userList.js @@ -1,6 +1,7 @@ import AbstractService from './abstractService' import UserListModel from '../models/userList' import UserModel from '../models/user' +import moment from 'moment' export default class UserListService extends AbstractService { constructor() { @@ -12,6 +13,12 @@ export default class UserListService extends AbstractService { }) } + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new UserListModel(data) } diff --git a/src/services/userNamespace.js b/src/services/userNamespace.js index 02c82bd8..5904fb0d 100644 --- a/src/services/userNamespace.js +++ b/src/services/userNamespace.js @@ -1,6 +1,7 @@ import AbstractService from './abstractService' import UserNamespaceModel from '../models/userNamespace' import UserModel from '../models/user' +import moment from 'moment' export default class UserNamespaceService extends AbstractService { constructor() { @@ -12,6 +13,12 @@ export default class UserNamespaceService extends AbstractService { }) } + processModel(model) { + model.created = moment(model.created).toISOString() + model.updated = moment(model.updated).toISOString() + return model + } + modelFactory(data) { return new UserNamespaceModel(data) }