Make sure to use date objects everywhere where dealing with dates

This commit is contained in:
kolaente 2020-02-08 14:16:06 +01:00
parent fc17518e8c
commit 161f853361
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
31 changed files with 203 additions and 62 deletions

View file

@ -7,7 +7,7 @@ export default class AttachmentModel extends AbstractModel {
super(data) super(data)
this.created_by = new UserModel(this.created_by) this.created_by = new UserModel(this.created_by)
this.file = new FileModel(this.file) this.file = new FileModel(this.file)
this.created = new Date(this.created * 1000) this.created = new Date(this.created)
} }
defaults() { defaults() {
@ -16,7 +16,7 @@ export default class AttachmentModel extends AbstractModel {
task_id: 0, task_id: 0,
file: FileModel, file: FileModel,
created_by: UserModel, created_by: UserModel,
created: 0, created: null,
} }
} }
} }

View file

@ -1,13 +1,18 @@
import AbstractModel from './abstractModel' import AbstractModel from './abstractModel'
export default class FileModel extends AbstractModel { export default class FileModel extends AbstractModel {
constructor(data) {
super(data)
this.created = new Date(this.created)
}
defaults() { defaults() {
return { return {
id: 0, id: 0,
mime: '', mime: '',
name: '', name: '',
size: '', size: '',
created: 0, created: null,
} }
} }

View file

@ -13,6 +13,9 @@ export default class LabelModel extends AbstractModel {
} }
this.textColor = this.hasDarkColor() ? '#4a4a4a' : '#e5e5e5' this.textColor = this.hasDarkColor() ? '#4a4a4a' : '#e5e5e5'
this.created_by = new UserModel(this.created_by) this.created_by = new UserModel(this.created_by)
this.created = new Date(this.created)
this.updated = new Date(this.updated)
} }
defaults() { defaults() {
@ -25,8 +28,8 @@ export default class LabelModel extends AbstractModel {
listID: 0, listID: 0,
textColor: '', textColor: '',
created: 0, created: null,
updated: 0 updated: null,
} }
} }

View file

@ -8,6 +8,9 @@ export default class ListModel extends AbstractModel {
super(data) super(data)
this.shared_by = new UserModel(this.shared_by) 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. // Default attributes that define the "empty" state.
@ -20,8 +23,8 @@ export default class ListModel extends AbstractModel {
sharing_type: 0, sharing_type: 0,
listID: 0, listID: 0,
created: 0, created: null,
updated: 0, updated: null,
} }
} }
} }

View file

@ -13,6 +13,9 @@ export default class ListModel extends AbstractModel {
}) })
this.owner = new UserModel(this.owner) 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. // Default attributes that define the "empty" state.
@ -25,8 +28,8 @@ export default class ListModel extends AbstractModel {
tasks: [], tasks: [],
namespaceID: 0, namespaceID: 0,
created: 0, created: null,
updated: 0, updated: null,
} }
} }
} }

View file

@ -10,6 +10,9 @@ export default class NamespaceModel extends AbstractModel {
return new ListModel(l) return new ListModel(l)
}) })
this.owner = new UserModel(this.owner) 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. // Default attributes that define the 'empty' state.
@ -21,8 +24,8 @@ export default class NamespaceModel extends AbstractModel {
owner: UserModel, owner: UserModel,
lists: [], lists: [],
created: 0, created: null,
updated: 0, updated: null,
} }
} }
} }

View file

@ -12,12 +12,12 @@ export default class TaskModel extends AbstractModel {
this.listID = Number(this.listID) this.listID = Number(this.listID)
// Make date objects from timestamps // Make date objects from timestamps
this.dueDate = this.parseDateIfNessecary(this.dueDate) this.dueDate = new Date(this.dueDate)
this.startDate = this.parseDateIfNessecary(this.startDate) this.startDate = new Date(this.startDate)
this.endDate = this.parseDateIfNessecary(this.endDate) this.endDate = new Date(this.endDate)
this.reminderDates = this.reminderDates.map(d => { this.reminderDates = this.reminderDates.map(d => {
return this.parseDateIfNessecary(d) return new Date(d)
}) })
this.reminderDates.push(null) // To trigger the datepicker this.reminderDates.push(null) // To trigger the datepicker
@ -53,6 +53,9 @@ export default class TaskModel extends AbstractModel {
this.attachments = this.attachments.map(a => { this.attachments = this.attachments.map(a => {
return new AttachmentModel(a) return new AttachmentModel(a)
}) })
this.created = new Date(this.created)
this.updated = new Date(this.updated)
} }
defaults() { defaults() {
@ -77,8 +80,8 @@ export default class TaskModel extends AbstractModel {
attachments: [], attachments: [],
createdBy: UserModel, createdBy: UserModel,
created: 0, created: null,
updated: 0, updated: null,
listID: 0, // Meta, only used when creating a new task listID: 0, // Meta, only used when creating a new task
} }
@ -88,19 +91,6 @@ export default class TaskModel extends AbstractModel {
// Helper functions // 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. * 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. * This function should only be called from the constructor.

View file

@ -1,9 +1,14 @@
import AbstractModel from './abstractModel' import AbstractModel from './abstractModel'
export default class TaskAssigneeModel extends AbstractModel { export default class TaskAssigneeModel extends AbstractModel {
constructor(data) {
super(data)
this.created = new Date(this.created)
}
defaults() { defaults() {
return { return {
created: 0, created: null,
user_id: 0, user_id: 0,
task_id: 0, task_id: 0,
} }

View file

@ -1,10 +1,11 @@
import AbstractModel from './abstractModel' import AbstractModel from './abstractModel'
import UserModel from "./user"; import UserModel from './user'
export default class TaskRelationModel extends AbstractModel { export default class TaskRelationModel extends AbstractModel {
constructor(data) { constructor(data) {
super(data) super(data)
this.created_by = new UserModel(this.created_by) this.created_by = new UserModel(this.created_by)
this.created = new Date(this.created)
} }
defaults() { defaults() {
@ -15,7 +16,7 @@ export default class TaskRelationModel extends AbstractModel {
relation_kind: '', relation_kind: '',
created_by: UserModel, created_by: UserModel,
created: 0, created: null,
} }
} }
} }

View file

@ -11,6 +11,9 @@ export default class TeamModel extends AbstractModel {
return new TeamMemberModel(m) return new TeamMemberModel(m)
}) })
this.createdBy = new UserModel(this.createdBy) this.createdBy = new UserModel(this.createdBy)
this.created = new Date(this.created)
this.updated = new Date(this.updated)
} }
defaults() { defaults() {
@ -22,8 +25,8 @@ export default class TeamModel extends AbstractModel {
right: 0, right: 0,
createdBy: {}, createdBy: {},
created: 0, created: null,
updated: 0 updated: null,
} }
} }
} }

View file

@ -1,5 +1,5 @@
import TeamShareBaseModel from './teamShareBase' import TeamShareBaseModel from './teamShareBase'
import {merge} from "lodash"; import {merge} from 'lodash'
export default class TeamListModel extends TeamShareBaseModel { export default class TeamListModel extends TeamShareBaseModel {
defaults() { defaults() {

View file

@ -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. * It is extended in a way so it can be used for namespaces as well for lists.
*/ */
export default class TeamShareBaseModel extends AbstractModel { export default class TeamShareBaseModel extends AbstractModel {
constructor(data) {
super(data)
this.created = new Date(this.created)
this.updated = new Date(this.updated)
}
defaults() { defaults() {
return { return {
teamID: 0, teamID: 0,
right: 0, right: 0,
created: 0, created: null,
updated: 0 updated: null
} }
} }
} }

View file

@ -1,14 +1,20 @@
import AbstractModel from './abstractModel' import AbstractModel from './abstractModel'
export default class UserModel extends AbstractModel { export default class UserModel extends AbstractModel {
constructor(data) {
super(data)
this.created = new Date(this.created)
this.updated = new Date(this.updated)
}
defaults() { defaults() {
return { return {
id: 0, id: 0,
avatarUrl: '', avatarUrl: '',
email: '', email: '',
username: '', username: '',
created: 0, created: null,
updated: 0 updated: null,
} }
} }
} }

View file

@ -1,13 +1,19 @@
import AbstractModel from './abstractModel' import AbstractModel from './abstractModel'
export default class UserShareBaseModel extends AbstractModel { export default class UserShareBaseModel extends AbstractModel {
constructor(data) {
super(data)
this.created = new Date(this.created)
this.updated = new Date(this.updated)
}
defaults() { defaults() {
return { return {
userID: 0, userID: 0,
right: 0, right: 0,
created: 0, created: null,
updated: 0, updated: null,
} }
} }
} }

View file

@ -1,5 +1,6 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import AttachmentModel from '../models/attachment' import AttachmentModel from '../models/attachment'
import moment from 'moment'
export default class AttachmentService extends AbstractService { export default class AttachmentService extends AbstractService {
constructor() { constructor() {
@ -10,6 +11,11 @@ export default class AttachmentService extends AbstractService {
}) })
} }
processModel(model) {
model.created = moment(model.created).toISOString()
return model
}
uploadProgress = 0 uploadProgress = 0
useCreateInterceptor() { useCreateInterceptor() {
@ -82,9 +88,4 @@ export default class AttachmentService extends AbstractService {
cancel() cancel()
}) })
} }
processModel(model) {
model.created = Math.round(+new Date(model.created) / 1000)
return model
}
} }

View file

@ -1,5 +1,6 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import LabelModel from '../models/label' import LabelModel from '../models/label'
import moment from 'moment'
export default class LabelService extends AbstractService { export default class LabelService extends AbstractService {
constructor() { constructor() {
@ -12,6 +13,12 @@ export default class LabelService extends AbstractService {
}) })
} }
processModel(model) {
model.created = moment(model.created).toISOString()
model.updated = moment(model.updated).toISOString()
return model
}
modelFactory(data) { modelFactory(data) {
return new LabelModel(data) return new LabelModel(data)
} }

View file

@ -1,5 +1,6 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import LinkShareModel from '../models/linkShare' import LinkShareModel from '../models/linkShare'
import moment from 'moment'
export default class ListService extends AbstractService { export default class ListService extends AbstractService {
constructor() { 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) { modelFactory(data) {
return new LinkShareModel(data) return new LinkShareModel(data)
} }

View file

@ -1,6 +1,7 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import ListModel from '../models/list' import ListModel from '../models/list'
import TaskService from './task' import TaskService from './task'
import moment from 'moment'
export default class ListService extends AbstractService { export default class ListService extends AbstractService {
constructor() { constructor() {
@ -12,6 +13,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) { modelFactory(data) {
return new ListModel(data) return new ListModel(data)
} }

View file

@ -1,5 +1,6 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import UserModel from '../models/user' import UserModel from '../models/user'
import moment from 'moment'
export default class ListUserService extends AbstractService { export default class ListUserService extends AbstractService {
constructor() { constructor() {
@ -8,6 +9,12 @@ export default class ListUserService extends AbstractService {
}) })
} }
processModel(model) {
model.created = moment(model.created).toISOString()
model.updated = moment(model.updated).toISOString()
return model
}
modelFactory(data) { modelFactory(data) {
return new UserModel(data) return new UserModel(data)
} }

View file

@ -1,5 +1,6 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import NamespaceModel from '../models/namespace' import NamespaceModel from '../models/namespace'
import moment from 'moment'
export default class NamespaceService extends AbstractService { export default class NamespaceService extends AbstractService {
constructor() { 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) { modelFactory(data) {
return new NamespaceModel(data) return new NamespaceModel(data)
} }

View file

@ -1,6 +1,7 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import TaskModel from '../models/task' import TaskModel from '../models/task'
import AttachmentService from './attachment' import AttachmentService from './attachment'
import moment from 'moment'
export default class TaskService extends AbstractService { export default class TaskService extends AbstractService {
constructor() { constructor() {
@ -29,10 +30,12 @@ export default class TaskService extends AbstractService {
// Ensure the listID is an int // Ensure the listID is an int
model.listID = Number(model.listID) model.listID = Number(model.listID)
// Convert the date in a unix timestamp // Convert dates into an iso string
model.dueDate = model.dueDate !== null ? Math.round(+new Date(model.dueDate) / 1000) : model.dueDate model.dueDate = moment(model.dueDate).toISOString()
model.startDate = model.startDate !== null ? Math.round(+new Date(model.startDate) / 1000): model.startDate model.startDate = moment(model.startDate).toISOString()
model.endDate = model.endDate !== null ? Math.round(+new Date(model.endDate) / 1000) : model.endDate 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 // remove all nulls, these would create empty reminders
for (const index in model.reminderDates) { for (const index in model.reminderDates) {
@ -44,7 +47,7 @@ export default class TaskService extends AbstractService {
// Make normal timestamps from js dates // Make normal timestamps from js dates
if(model.reminderDates.length > 0) { if(model.reminderDates.length > 0) {
model.reminderDates = model.reminderDates.map(r => { model.reminderDates = model.reminderDates.map(r => {
return Math.round(+new Date(r) / 1000) return moment(r).toISOString()
}) })
} }

View file

@ -1,5 +1,6 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import TaskAssigneeModel from '../models/taskAssignee' import TaskAssigneeModel from '../models/taskAssignee'
import moment from 'moment'
export default class TaskAssigneeService extends AbstractService { export default class TaskAssigneeService extends AbstractService {
constructor() { constructor() {
@ -9,6 +10,11 @@ export default class TaskAssigneeService extends AbstractService {
}) })
} }
processModel(model) {
model.created = moment(model.created).toISOString()
return model
}
modelFactory(data) { modelFactory(data) {
return new TaskAssigneeModel(data) return new TaskAssigneeModel(data)
} }

View file

@ -1,5 +1,6 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import TaskModel from '../models/task' import TaskModel from '../models/task'
import moment from 'moment'
export default class TaskCollectionService extends AbstractService { export default class TaskCollectionService extends AbstractService {
constructor() { constructor() {
@ -8,6 +9,12 @@ export default class TaskCollectionService extends AbstractService {
}) })
} }
processModel(model) {
model.created = moment(model.created).toISOString()
model.updated = moment(model.updated).toISOString()
return model
}
modelFactory(data) { modelFactory(data) {
return new TaskModel(data) return new TaskModel(data)
} }

View file

@ -1,5 +1,6 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import TaskRelationModel from '../models/taskRelation' import TaskRelationModel from '../models/taskRelation'
import moment from 'moment'
export default class TaskRelationService extends AbstractService { export default class TaskRelationService extends AbstractService {
constructor() { constructor() {
@ -9,6 +10,11 @@ export default class TaskRelationService extends AbstractService {
}) })
} }
processModel(model) {
model.created = moment(model.created).toISOString()
return model
}
modelFactory(data) { modelFactory(data) {
return new TaskRelationModel(data) return new TaskRelationModel(data)
} }

View file

@ -1,5 +1,6 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import TeamModel from '../models/team' import TeamModel from '../models/team'
import moment from 'moment'
export default class TeamService extends AbstractService { export default class TeamService extends AbstractService {
constructor() { 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) { modelFactory(data) {
return new TeamModel(data) return new TeamModel(data)
} }

View file

@ -1,6 +1,7 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import TeamListModel from '../models/teamList' import TeamListModel from '../models/teamList'
import TeamModel from '../models/team' import TeamModel from '../models/team'
import moment from 'moment'
export default class TeamListService extends AbstractService { export default class TeamListService extends AbstractService {
constructor() { 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) { modelFactory(data) {
return new TeamListModel(data) return new TeamListModel(data)
} }

View file

@ -1,5 +1,6 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import TeamMemberModel from '../models/teamMember' import TeamMemberModel from '../models/teamMember'
import moment from 'moment'
export default class TeamMemberService extends AbstractService { export default class TeamMemberService extends AbstractService {
constructor() { constructor() {
@ -9,6 +10,12 @@ export default class TeamMemberService extends AbstractService {
}); });
} }
processModel(model) {
model.created = moment(model.created).toISOString()
model.updated = moment(model.updated).toISOString()
return model
}
modelFactory(data) { modelFactory(data) {
return new TeamMemberModel(data) return new TeamMemberModel(data)
} }

View file

@ -1,6 +1,7 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import TeamNamespaceModel from '../models/teamNamespace' import TeamNamespaceModel from '../models/teamNamespace'
import TeamModel from '../models/team' import TeamModel from '../models/team'
import moment from 'moment'
export default class TeamNamespaceService extends AbstractService { export default class TeamNamespaceService extends AbstractService {
constructor() { 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) { modelFactory(data) {
return new TeamNamespaceModel(data) return new TeamNamespaceModel(data)
} }

View file

@ -1,5 +1,6 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import UserModel from '../models/user' import UserModel from '../models/user'
import moment from 'moment'
export default class UserService extends AbstractService { export default class UserService extends AbstractService {
constructor() { constructor() {
@ -8,6 +9,12 @@ export default class UserService extends AbstractService {
}) })
} }
processModel(model) {
model.created = moment(model.created).toISOString()
model.updated = moment(model.updated).toISOString()
return model
}
modelFactory(data) { modelFactory(data) {
return new UserModel(data) return new UserModel(data)
} }

View file

@ -1,6 +1,7 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import UserListModel from '../models/userList' import UserListModel from '../models/userList'
import UserModel from '../models/user' import UserModel from '../models/user'
import moment from 'moment'
export default class UserListService extends AbstractService { export default class UserListService extends AbstractService {
constructor() { 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) { modelFactory(data) {
return new UserListModel(data) return new UserListModel(data)
} }

View file

@ -1,6 +1,7 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import UserNamespaceModel from '../models/userNamespace' import UserNamespaceModel from '../models/userNamespace'
import UserModel from '../models/user' import UserModel from '../models/user'
import moment from 'moment'
export default class UserNamespaceService extends AbstractService { export default class UserNamespaceService extends AbstractService {
constructor() { 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) { modelFactory(data) {
return new UserNamespaceModel(data) return new UserNamespaceModel(data)
} }