fix: use new assignData method for default data

This commit is contained in:
Dominik Pschenitschni 2022-08-14 12:15:45 +02:00
parent 8be1f81848
commit 8416b1f448
No known key found for this signature in database
GPG key ID: B257AC0149F43A77
34 changed files with 317 additions and 615 deletions

View file

@ -12,25 +12,14 @@ export default abstract class AbstractModel<Model extends IAbstract = IAbstract>
* The max right the user has on this object, as returned by the x-max-right header from the api. * The max right the user has on this object, as returned by the x-max-right header from the api.
*/ */
maxRight: Right | null = null maxRight: Right | null = null
/** /**
* The abstract constructor takes an object and merges its data with the default data of this model. * Takes an object and merges its data with the default data of this model.
*/ */
constructor(data : Object = {}) { assignData(data: Partial<Model>) {
data = objectToCamelCase(data) data = objectToCamelCase(data)
// Put all data in our model while overriding those with a value of null or undefined with their defaults // Put all data in our model while overriding those with a value of null or undefined with their defaults
Object.assign( Object.assign(this, omitBy(data, isNil))
this,
this.defaults(),
omitBy(data, isNil),
)
}
/**
* Default attributes that define the "empty" state.
*/
defaults(): Object {
return {}
} }
} }

View file

@ -11,26 +11,18 @@ export interface IAttachment extends IAbstract {
} }
export default class AttachmentModel extends AbstractModel implements IAttachment { export default class AttachmentModel extends AbstractModel implements IAttachment {
id!: number id = 0
taskId!: number taskId = 0
createdBy: IUser createdBy: IUser = UserModel
file: IFile file: IFile = FileModel
created: Date created: Date = null
constructor(data: Partial<IAttachment>) {
super()
this.assignData(data)
constructor(data) {
super(data)
this.createdBy = new UserModel(this.createdBy) this.createdBy = new UserModel(this.createdBy)
this.file = new FileModel(this.file) this.file = new FileModel(this.file)
this.created = new Date(this.created) this.created = new Date(this.created)
} }
defaults() {
return {
id: 0,
taskId: 0,
createdBy: UserModel,
file: FileModel,
created: null,
}
}
} }

View file

@ -7,11 +7,10 @@ export interface IAvatar extends IAbstract {
} }
export default class AvatarModel extends AbstractModel implements IAvatar { export default class AvatarModel extends AbstractModel implements IAvatar {
avatarProvider!: AvatarProvider avatarProvider: AvatarProvider = 'default'
defaults() { constructor(data: Partial<IAvatar>) {
return { super()
avatarProvider: '', this.assignData(data)
}
} }
} }

View file

@ -12,22 +12,17 @@ export interface IBackgroundImage extends IAbstract {
} }
export default class BackgroundImageModel extends AbstractModel implements IBackgroundImage { export default class BackgroundImageModel extends AbstractModel implements IBackgroundImage {
id!: number id = 0
url!: string url = ''
thumb!: string thumb = ''
info!: { info: {
author: string author: string
authorName: string authorName: string
} } = {}
blurHash!: string blurHash = ''
defaults() { constructor(data: Partial<IBackgroundImage>) {
return { super()
id: 0, this.assignData(data)
url: '',
thumb: '',
info: {},
blurHash: '',
}
} }
} }

View file

@ -17,20 +17,21 @@ export interface IBucket extends IAbstract {
} }
export default class BucketModel extends AbstractModel implements IBucket { export default class BucketModel extends AbstractModel implements IBucket {
id!: number id = 0
title!: string title = ''
listId!: number listId = ''
limit!: number limit = 0
tasks!: ITask[] tasks: ITask[] = []
isDoneBucket!: boolean isDoneBucket: false
position!: number position: 0
createdBy: IUser createdBy: IUser = null
created: Date created: Date = null
updated: Date updated: Date = null
constructor(bucket) { constructor(data: Partial<IBucket>) {
super(bucket) super()
this.assignData(data)
this.tasks = this.tasks.map(t => new TaskModel(t)) this.tasks = this.tasks.map(t => new TaskModel(t))
@ -38,20 +39,4 @@ export default class BucketModel extends AbstractModel implements IBucket {
this.created = new Date(this.created) this.created = new Date(this.created)
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
} }
defaults() {
return {
id: 0,
title: '',
listId: 0,
limit: 0,
tasks: [],
isDoneBucket: false,
position: 0,
createdBy: null,
created: null,
updated: null,
}
}
} }

View file

@ -6,14 +6,13 @@ export interface ICaldavToken extends IAbstract {
} }
export default class CaldavTokenModel extends AbstractModel implements ICaldavToken { export default class CaldavTokenModel extends AbstractModel implements ICaldavToken {
id!: number id: number
created!: Date created: Date
constructor(data? : Object) { constructor(data? : Partial<CaldavTokenModel>) {
super(data) super()
this.assignData(data)
this.id
if (this.created) { if (this.created) {
this.created = new Date(this.created) this.created = new Date(this.created)
} }

View file

@ -6,13 +6,11 @@ interface IEmailUpdate extends IAbstract {
} }
export default class EmailUpdateModel extends AbstractModel implements IEmailUpdate { export default class EmailUpdateModel extends AbstractModel implements IEmailUpdate {
newEmail!: string newEmail = ''
password!: string password = ''
defaults() { constructor(data : Partial<IEmailUpdate>) {
return { super()
newEmail: '', this.assignData(data)
password: '',
}
} }
} }

View file

@ -9,27 +9,19 @@ export interface IFile extends IAbstract {
} }
export default class FileModel extends AbstractModel implements IFile { export default class FileModel extends AbstractModel implements IFile {
id!: number id = 0
mime!: string mime = ''
name!: string name = ''
size!: number size = 0
created: Date created: Date = null
constructor(data: Partial<IFile>) {
super()
this.assignData(data)
constructor(data) {
super(data)
this.created = new Date(this.created) this.created = new Date(this.created)
} }
defaults() {
return {
id: 0,
mime: '',
name: '',
size: 0,
created: null,
}
}
getHumanSize() { getHumanSize() {
const sizes = { const sizes = {
0: 'B', 0: 'B',

View file

@ -18,25 +18,23 @@ export interface ILabel extends IAbstract {
} }
export default class LabelModel extends AbstractModel implements ILabel { export default class LabelModel extends AbstractModel implements ILabel {
id!: number id = 0
title!: string title = ''
hexColor!: string // FIXME: this should be empty and be definied in the client.
description!: string // that way it get's never send to the server db and is easier to change in future versions.
createdBy!: IUser hexColor = DEFAULT_LABEL_BACKGROUND_COLOR
listId!: number description = ''
textColor!: string createdBy: IUser
listId = 0
textColor = ''
created: Date created: Date = null
updated: Date updated: Date = null
constructor(data: Partial<ILabel>) {
super()
this.assignData(data)
constructor(data) {
super(data)
// FIXME: this should be empty and be definied in the client.
// that way it get's never send to the server db and is easier to change in future versions.
// Set the default color
if (this.hexColor === '') {
this.hexColor = DEFAULT_LABEL_BACKGROUND_COLOR
}
if (this.hexColor.substring(0, 1) !== '#') { if (this.hexColor.substring(0, 1) !== '#') {
this.hexColor = '#' + this.hexColor this.hexColor = '#' + this.hexColor
} }
@ -46,19 +44,4 @@ export default class LabelModel extends AbstractModel implements ILabel {
this.created = new Date(this.created) this.created = new Date(this.created)
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
} }
defaults() {
return {
id: 0,
title: '',
hexColor: '',
description: '',
createdBy: UserModel,
listId: 0,
textColor: '',
created: null,
updated: null,
}
}
} }

View file

@ -7,15 +7,12 @@ export interface ILabelTask extends IAbstract {
} }
export default class LabelTask extends AbstractModel implements ILabelTask { export default class LabelTask extends AbstractModel implements ILabelTask {
id!: number id = 0
taskId!: number taskId = 0
labelId!: number labelId = 0
defaults() { constructor(data: Partial<ILabelTask>) {
return { super()
id: 0, this.assignData(data)
taskId: 0,
labelId: 0,
}
} }
} }

View file

@ -16,41 +16,24 @@ export interface ILinkShare extends IAbstract {
} }
export default class LinkShareModel extends AbstractModel implements ILinkShare { export default class LinkShareModel extends AbstractModel implements ILinkShare {
id!: number id = 0
hash!: string hash = ''
right!: Right right: Right = RIGHTS.READ
sharedBy: IUser sharedBy: IUser = UserModel
sharingType!: number // FIXME: use correct numbers sharingType = 0 // FIXME: use correct numbers
listId!: number listId = 0
name!: string name: ''
password!: string password: ''
created: Date created: Date = null
updated: Date updated: Date = null
constructor(data) { constructor(data: Partial<ILinkShare>) {
// The constructor of AbstractModel handles all the default parsing. super()
super(data) this.assignData(data)
this.sharedBy = new UserModel(this.sharedBy) this.sharedBy = new UserModel(this.sharedBy)
this.created = new Date(this.created) this.created = new Date(this.created)
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
} }
// Default attributes that define the "empty" state.
defaults() {
return {
id: 0,
hash: '',
right: RIGHTS.READ,
sharedBy: UserModel,
sharingType: 0,
listId: 0,
name: '',
password: '',
created: null,
updated: null,
}
}
} }

View file

@ -16,7 +16,7 @@ export interface IList extends IAbstract {
isArchived: boolean isArchived: boolean
hexColor: string hexColor: string
identifier: string identifier: string
backgroundInformation: any backgroundInformation: any // FIXME: improve type
isFavorite: boolean isFavorite: boolean
subscription: ISubscription subscription: ISubscription
position: number position: number
@ -27,26 +27,27 @@ export interface IList extends IAbstract {
} }
export default class ListModel extends AbstractModel implements IList { export default class ListModel extends AbstractModel implements IList {
id!: number id = 0
title!: string title = ''
description!: string description = ''
owner: IUser owner: IUser = UserModel
tasks: ITask[] tasks: ITask[] = []
namespaceId!: INamespace['id'] namespaceId: INamespace['id'] = 0
isArchived!: boolean isArchived = false
hexColor!: string hexColor = ''
identifier!: string identifier = ''
backgroundInformation!: any backgroundInformation: any = null
isFavorite!: boolean isFavorite = false
subscription!: ISubscription subscription: ISubscription = null
position!: number position = 0
backgroundBlurHash!: string backgroundBlurHash = ''
created: Date created: Date = null
updated: Date updated: Date = null
constructor(data) { constructor(data: Partial<IList>) {
super(data) super()
this.assignData(data)
this.owner = new UserModel(this.owner) this.owner = new UserModel(this.owner)
@ -67,29 +68,6 @@ export default class ListModel extends AbstractModel implements IList {
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
} }
// Default attributes that define the "empty" state.
defaults() {
return {
id: 0,
title: '',
description: '',
owner: UserModel,
tasks: [],
namespaceId: 0,
isArchived: false,
hexColor: '',
identifier: '',
backgroundInformation: null,
isFavorite: false,
subscription: null,
position: 0,
backgroundBlurHash: '',
created: null,
updated: null,
}
}
isSavedFilter() { isSavedFilter() {
return this.getSavedFilterId() > 0 return this.getSavedFilterId() > 0
} }

View file

@ -9,20 +9,14 @@ export interface IListDuplicate extends IAbstract {
} }
export default class ListDuplicateModel extends AbstractModel implements IListDuplicate { export default class ListDuplicateModel extends AbstractModel implements IListDuplicate {
listId!: number listId = 0
namespaceId!: INamespace['id'] namespaceId: INamespace['id'] = 0
list: IList list: IList = ListModel
constructor(data : Partial<IListDuplicate>) {
super()
this.assignData(data)
constructor(data) {
super(data)
this.list = new ListModel(this.list) this.list = new ListModel(this.list)
} }
defaults() {
return {
listId: 0,
namespaceId: 0,
list: ListModel,
}
}
} }

View file

@ -18,20 +18,21 @@ export interface INamespace extends IAbstract {
} }
export default class NamespaceModel extends AbstractModel implements INamespace { export default class NamespaceModel extends AbstractModel implements INamespace {
id!: number id = 0
title!: string title = ''
description!: string description = ''
owner: IUser owner: IUser = UserModel
lists: IList[] lists: IList[] = []
isArchived!: boolean isArchived = false
hexColor!: string hexColor = ''
subscription!: ISubscription subscription: ISubscription = null
created: Date created: Date = null
updated: Date updated: Date = null
constructor(data) { constructor(data: Partial<INamespace>) {
super(data) super()
this.assignData(data)
if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') { if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
this.hexColor = '#' + this.hexColor this.hexColor = '#' + this.hexColor
@ -50,21 +51,4 @@ export default class NamespaceModel extends AbstractModel implements INamespace
this.created = new Date(this.created) this.created = new Date(this.created)
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
} }
// Default attributes that define the 'empty' state.
defaults() {
return {
id: 0,
title: '',
description: '',
owner: UserModel,
lists: [],
isArchived: false,
hexColor: '',
subscription: null,
created: null,
updated: null,
}
}
} }

View file

@ -3,7 +3,7 @@ import {parseDateOrNull} from '@/helpers/parseDateOrNull'
import UserModel, { type IUser } from '@/models/user' import UserModel, { type IUser } from '@/models/user'
import TaskModel, { type ITask } from '@/models/task' import TaskModel, { type ITask } from '@/models/task'
import TaskCommentModel, { type ITaskComment } from '@/models/taskComment' import TaskCommentModel, { type ITaskComment } from '@/models/taskComment'
import ListModel from '@/models/list' import ListModel, { type IList } from '@/models/list'
import TeamModel, { type ITeam } from '@/models/team' import TeamModel, { type ITeam } from '@/models/team'
export const NOTIFICATION_NAMES = { export const NOTIFICATION_NAMES = {
@ -33,6 +33,7 @@ interface NotificationDeleted extends Notification {
interface NotificationCreated extends Notification { interface NotificationCreated extends Notification {
task: ITask task: ITask
list: IList
} }
interface NotificationMemberAdded extends Notification { interface NotificationMemberAdded extends Notification {
@ -51,16 +52,17 @@ export interface INotification extends IAbstract {
} }
export default class NotificationModel extends AbstractModel implements INotification { export default class NotificationModel extends AbstractModel implements INotification {
id!: number id = 0
name!: string name = ''
notification!: NotificationTask | NotificationAssigned | NotificationDeleted | NotificationCreated | NotificationMemberAdded notification: NotificationTask | NotificationAssigned | NotificationDeleted | NotificationCreated | NotificationMemberAdded = null
read!: boolean read = false
readAt: Date | null readAt: Date | null = null
created: Date created: Date
constructor(data) { constructor(data: Partial<INotification>) {
super(data) super()
this.assignData(data)
switch (this.name) { switch (this.name) {
case NOTIFICATION_NAMES.TASK_COMMENT: case NOTIFICATION_NAMES.TASK_COMMENT:
@ -102,16 +104,6 @@ export default class NotificationModel extends AbstractModel implements INotific
this.readAt = parseDateOrNull(this.readAt) this.readAt = parseDateOrNull(this.readAt)
} }
defaults() {
return {
id: 0,
name: '',
notification: null,
read: false,
readAt: null,
}
}
toText(user = null) { toText(user = null) {
let who = '' let who = ''

View file

@ -7,21 +7,14 @@ export interface IPasswordReset extends IAbstract {
} }
export default class PasswordResetModel extends AbstractModel implements IPasswordReset { export default class PasswordResetModel extends AbstractModel implements IPasswordReset {
token: string token = ''
newPassword!: string newPassword = ''
email!: string email = ''
constructor(data) { constructor(data: Partial<IPasswordReset>) {
super(data) super()
this.assignData(data)
this.token = localStorage.getItem('passwordResetToken') this.token = localStorage.getItem('passwordResetToken')
} }
defaults() {
return {
token: '',
newPassword: '',
email: '',
}
}
} }

View file

@ -6,13 +6,11 @@ export interface IPasswordUpdate extends IAbstract {
} }
export default class PasswordUpdateModel extends AbstractModel implements IPasswordUpdate { export default class PasswordUpdateModel extends AbstractModel implements IPasswordUpdate {
newPassword!: string newPassword = ''
oldPassword!: string oldPassword = ''
defaults() { constructor(data: Partial<IPasswordUpdate>) {
return { super()
newPassword: '', this.assignData(data)
oldPassword: '',
}
} }
} }

View file

@ -2,7 +2,7 @@ import AbstractModel, { type IAbstract } from '@/models/abstractModel'
import UserModel, { type IUser } from '@/models/user' import UserModel, { type IUser } from '@/models/user'
export interface ISavedFilter extends IAbstract { export interface ISavedFilter extends IAbstract {
id: 0 id: number
title: string title: string
description: string description: string
filters: { filters: {
@ -21,10 +21,10 @@ export interface ISavedFilter extends IAbstract {
} }
export default class SavedFilterModel extends AbstractModel implements ISavedFilter { export default class SavedFilterModel extends AbstractModel implements ISavedFilter {
id!: 0 id = 0
title!: string title = ''
description!: string description = ''
filters!: { filters: {
sortBy: ('done' | 'id')[] sortBy: ('done' | 'id')[]
orderBy: ('asc' | 'desc')[] orderBy: ('asc' | 'desc')[]
filterBy: 'done'[] filterBy: 'done'[]
@ -32,14 +32,23 @@ export default class SavedFilterModel extends AbstractModel implements ISavedFil
filterComparator: 'equals'[] filterComparator: 'equals'[]
filterConcat: 'and' filterConcat: 'and'
filterIncludeNulls: boolean filterIncludeNulls: boolean
} = {
sortBy: ['done', 'id'],
orderBy: ['asc', 'desc'],
filterBy: ['done'],
filterValue: ['false'],
filterComparator: ['equals'],
filterConcat: 'and',
filterIncludeNulls: true,
} }
owner: IUser owner: IUser = {}
created: Date created: Date = null
updated: Date updated: Date = null
constructor(data) { constructor(data: Partial<ISavedFilter>) {
super(data) super()
this.assignData(data)
this.owner = new UserModel(this.owner) this.owner = new UserModel(this.owner)
@ -47,27 +56,6 @@ export default class SavedFilterModel extends AbstractModel implements ISavedFil
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
} }
defaults() {
return {
id: 0,
title: '',
description: '',
filters: {
sortBy: ['done', 'id'],
orderBy: ['asc', 'desc'],
filterBy: ['done'],
filterValue: ['false'],
filterComparator: ['equals'],
filterConcat: 'and',
filterIncludeNulls: true,
},
owner: {},
created: null,
updated: null,
}
}
/** /**
* Calculates the corresponding list id to this saved filter. * Calculates the corresponding list id to this saved filter.
* This function matches the one in the api. * This function matches the one in the api.

View file

@ -11,27 +11,18 @@ export interface ISubscription extends IAbstract {
} }
export default class SubscriptionModel extends AbstractModel implements ISubscription { export default class SubscriptionModel extends AbstractModel implements ISubscription {
id!: number id = 0
entity!: string // FIXME: correct type? entity = ''
entityId!: number // FIXME: correct type? entityId = 0
user: IUser user: IUser = {}
created: Date created: Date = null
constructor(data) { constructor(data : Partial<ISubscription>) {
super(data) super()
this.assignData(data)
this.created = new Date(this.created) this.created = new Date(this.created)
this.user = new UserModel(this.user) this.user = new UserModel(this.user)
} }
defaults() {
return {
id: 0,
entity: '',
entityId: 0,
created: null,
user: {},
}
}
} }

View file

@ -1,4 +1,4 @@
import type { Priority } from '@/constants/priorities' import { PRIORITIES, type Priority } from '@/constants/priorities'
import AbstractModel, { type IAbstract } from '@/models/abstractModel' import AbstractModel, { type IAbstract } from '@/models/abstractModel'
import UserModel, { type IUser } from '@/models/user' import UserModel, { type IUser } from '@/models/user'
@ -61,44 +61,45 @@ export interface ITask extends IAbstract {
} }
export default class TaskModel extends AbstractModel implements ITask { export default class TaskModel extends AbstractModel implements ITask {
id: number id = 0
title: string title = ''
description!: string description = ''
done!: boolean done = false
doneAt: Date | null doneAt: Date | null = null
priority!: Priority priority: Priority = PRIORITIES.UNSET
labels: ILabel[] labels: ILabel[] = []
assignees: IUser[] assignees: IUser[] = []
dueDate: Date | null dueDate: Date | null = 0
startDate: Date | null startDate: Date | null = 0
endDate: Date | null endDate: Date | null = 0
repeatAfter!: number | IRepeats repeatAfter: number | IRepeats = 0
repeatFromCurrentDate!: boolean repeatFromCurrentDate = false
repeatMode!: TaskRepeatMode repeatMode: TaskRepeatMode = TASK_REPEAT_MODES.REPEAT_MODE_DEFAULT
reminderDates: Date[] reminderDates: Date[] = []
parentTaskId!: ITask['id'] parentTaskId: ITask['id'] = 0
hexColor!: string hexColor = ''
percentDone!: number percentDone = 0
relatedTasks!: { [relationKind: string]: ITask } // FIXME: use relationKinds relatedTasks: { [relationKind: string]: ITask } = {}
attachments: IAttachment[] attachments: IAttachment[] = []
identifier!: string identifier = ''
index!: number index = 0
isFavorite!: boolean isFavorite = false
subscription!: ISubscription subscription: ISubscription = null
position!: number position = 0
kanbanPosition!: number kanbanPosition = 0
createdBy: IUser createdBy: IUser = UserModel
created: Date created: Date = null
updated: Date updated: Date = null
listId: IList['id'] // Meta, only used when creating a new task listId: IList['id'] = 0
bucketId!: IBucket['id'] bucketId: IBucket['id'] = 0
constructor(data: Partial<ITask>) { constructor(data: Partial<ITask>) {
super(data) super()
this.assignData(data)
this.id = Number(this.id) this.id = Number(this.id)
this.title = this.title?.trim() this.title = this.title?.trim()
@ -158,46 +159,6 @@ export default class TaskModel extends AbstractModel implements ITask {
this.listId = Number(this.listId) this.listId = Number(this.listId)
} }
defaults() {
return {
id: 0,
title: '',
description: '',
done: false,
doneAt: null,
priority: 0,
labels: [],
assignees: [],
dueDate: 0,
startDate: 0,
endDate: 0,
repeatAfter: 0,
repeatFromCurrentDate: false,
repeatMode: TASK_REPEAT_MODES.REPEAT_MODE_DEFAULT,
reminderDates: [],
parentTaskId: 0,
hexColor: '',
percentDone: 0,
relatedTasks: {},
attachments: [],
identifier: '',
index: 0,
isFavorite: false,
subscription: null,
position: 0,
kanbanPosition: 0,
createdBy: UserModel,
created: null,
updated: null,
listId: 0, // Meta, only used when creating a new task
bucketId: 0,
}
}
getTextIdentifier() { getTextIdentifier() {
if (this.identifier === '') { if (this.identifier === '') {
return `#${this.index}` return `#${this.index}`

View file

@ -9,20 +9,13 @@ export interface ITaskAssignee extends IAbstract {
} }
export default class TaskAssigneeModel extends AbstractModel implements ITaskAssignee { export default class TaskAssigneeModel extends AbstractModel implements ITaskAssignee {
created: Date created: Date = null
userId!: IUser['id'] userId: IUser['id'] = 0
taskId!: ITask['id'] taskId: ITask['id'] = 0
constructor(data) { constructor(data: Partial<ITaskAssignee>) {
super(data) super()
this.assignData(data)
this.created = new Date(this.created) this.created = new Date(this.created)
} }
defaults() {
return {
created: null,
userId: 0,
taskId: 0,
}
}
} }

View file

@ -13,29 +13,20 @@ export interface ITaskComment extends IAbstract {
} }
export default class TaskCommentModel extends AbstractModel implements ITaskComment { export default class TaskCommentModel extends AbstractModel implements ITaskComment {
id!: number id = 0
taskId!: ITask['id'] taskId: ITask['id'] = 0
comment!: string comment = ''
author: IUser author: IUser = UserModel
created: Date created: Date = null
updated: Date updated: Date = null
constructor(data: Partial<ITaskComment>) {
super()
this.assignData(data)
constructor(data) {
super(data)
this.author = new UserModel(this.author) this.author = new UserModel(this.author)
this.created = new Date(this.created) this.created = new Date(this.created)
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
} }
defaults() {
return {
id: 0,
taskId: 0,
comment: '',
author: UserModel,
created: null,
updated: null,
}
}
} }

View file

@ -30,29 +30,19 @@ export interface ITaskRelation extends IAbstract {
} }
export default class TaskRelationModel extends AbstractModel implements ITaskRelation { export default class TaskRelationModel extends AbstractModel implements ITaskRelation {
id!: number id = 0
otherTaskId!: ITask['id'] otherTaskId: ITask['id'] = 0
taskId!: ITask['id'] taskId: ITask['id'] = 0
relationKind!: RelationKind relationKind: RelationKind = ''
createdBy: IUser createdBy: IUser = UserModel
created: Date created: Date = null
constructor(data: Partial<ITaskRelation>) {
super()
this.assignData(data)
constructor(data) {
super(data)
this.createdBy = new UserModel(this.createdBy) this.createdBy = new UserModel(this.createdBy)
this.created = new Date(this.created) this.created = new Date(this.created)
} }
defaults() {
return {
id: 0,
otherTaskId: 0,
taskId: 0,
relationKind: '',
createdBy: UserModel,
created: null,
}
}
} }

View file

@ -16,18 +16,19 @@ export interface ITeam extends IAbstract {
} }
export default class TeamModel extends AbstractModel implements ITeam { export default class TeamModel extends AbstractModel implements ITeam {
id!: number id = 0
name!: string name = ''
description!: string description = ''
members: ITeamMember[] members: ITeamMember[] = []
right!: Right right: Right = RIGHTS.READ
createdBy: IUser createdBy: IUser = {} // FIXME: seems wrong
created: Date created: Date = null
updated: Date updated: Date = null
constructor(data) { constructor(data: Partial<ITeam>) {
super(data) super()
this.assignData(data)
// Make the members to usermodels // Make the members to usermodels
this.members = this.members.map(m => { this.members = this.members.map(m => {
@ -38,18 +39,4 @@ export default class TeamModel extends AbstractModel implements ITeam {
this.created = new Date(this.created) this.created = new Date(this.created)
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
} }
defaults() {
return {
id: 0,
name: '',
description: '',
members: [],
right: RIGHTS.READ,
createdBy: {},
created: null,
updated: null,
}
}
} }

View file

@ -6,12 +6,10 @@ export interface ITeamList extends TeamShareBaseModel {
} }
export default class TeamListModel extends TeamShareBaseModel implements ITeamList { export default class TeamListModel extends TeamShareBaseModel implements ITeamList {
listId!: IList['id'] listId: IList['id'] = 0
defaults() { constructor(data: Partial<ITeamList>) {
return { super(data)
...super.defaults(), this.assignData(data)
listId: 0,
}
} }
} }

View file

@ -7,14 +7,11 @@ export interface ITeamMember extends UserModel {
} }
export default class TeamMemberModel extends UserModel implements ITeamMember { export default class TeamMemberModel extends UserModel implements ITeamMember {
admin!: boolean admin = false
teamId!: IList['id'] teamId: IList['id'] = 0
defaults() { constructor(data: Partial<ITeamMember>) {
return { super(data)
...super.defaults(), this.assignData(data)
admin: false,
teamId: 0,
}
} }
} }

View file

@ -6,12 +6,10 @@ export interface ITeamNamespace extends TeamShareBaseModel {
} }
export default class TeamNamespaceModel extends TeamShareBaseModel implements ITeamNamespace { export default class TeamNamespaceModel extends TeamShareBaseModel implements ITeamNamespace {
namespaceId!: INamespace['id'] namespaceId: INamespace['id'] = 0
defaults() { constructor(data: Partial<ITeamNamespace>) {
return { super(data)
...super.defaults(), this.assignData(data)
namespaceId: 0,
}
} }
} }

View file

@ -15,25 +15,17 @@ export interface ITeamShareBase extends IAbstract {
* 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 implements ITeamShareBase { export default class TeamShareBaseModel extends AbstractModel implements ITeamShareBase {
teamId!: ITeam['id'] teamId: ITeam['id'] = 0
right!: Right right: Right = RIGHTS.READ
created: Date created: Date = null
updated: Date updated: Date = null
constructor(data: Partial<ITeamShareBase>) {
super()
this.assignData(data)
constructor(data) {
super(data)
this.created = new Date(this.created) this.created = new Date(this.created)
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
} }
defaults() {
return {
teamId: 0,
right: RIGHTS.READ,
created: null,
updated: null,
}
}
} }

View file

@ -6,16 +6,13 @@ export interface ITotp extends IAbstract {
url: string url: string
} }
export default class TotpModel extends AbstractModel implements ITotp{ export default class TotpModel extends AbstractModel implements ITotp {
secret!: string secret = ''
enabled!: boolean enabled = false
url!: string url = ''
defaults() { constructor(data: Partial<ITotp>) {
return { super()
secret: '', this.assignData(data)
enabled: false,
url: '',
}
} }
} }

View file

@ -13,17 +13,18 @@ export interface IUser extends IAbstract {
} }
export default class UserModel extends AbstractModel implements IUser { export default class UserModel extends AbstractModel implements IUser {
id!: number id = 0
email!: string email = ''
username!: string username = ''
name!: string name = ''
created: Date created: Date = null
updated: Date updated: Date = null
settings: IUserSettings settings: IUserSettings = null
constructor(data) { constructor(data: Partial<IUser>) {
super(data) super()
this.assignData(data)
this.created = new Date(this.created) this.created = new Date(this.created)
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
@ -33,19 +34,6 @@ export default class UserModel extends AbstractModel implements IUser {
} }
} }
defaults() {
return {
id: 0,
email: '',
username: '',
name: '',
created: null,
updated: null,
settings: null,
}
}
getAvatarUrl(size = 50) { getAvatarUrl(size = 50) {
return `${window.API_URL}/avatar/${this.username}?size=${size}` return `${window.API_URL}/avatar/${this.username}?size=${size}`
} }

View file

@ -7,12 +7,10 @@ export interface IUserList extends UserShareBaseModel {
// This class extends the user share model with a 'rights' parameter which is used in sharing // This class extends the user share model with a 'rights' parameter which is used in sharing
export default class UserListModel extends UserShareBaseModel implements IUserList { export default class UserListModel extends UserShareBaseModel implements IUserList {
listId!: IList['id'] listId: IList['id'] = 0
defaults() { constructor(data: Partial<IUserList>) {
return { super(data)
...super.defaults(), this.assignData(data)
listId: 0,
}
} }
} }

View file

@ -7,12 +7,10 @@ export interface IUserNamespace extends UserShareBaseModel {
// This class extends the user share model with a 'rights' parameter which is used in sharing // This class extends the user share model with a 'rights' parameter which is used in sharing
export default class UserNamespaceModel extends UserShareBaseModel implements IUserNamespace { export default class UserNamespaceModel extends UserShareBaseModel implements IUserNamespace {
namespaceId!: INamespace['id'] namespaceId: INamespace['id'] = 0
defaults() { constructor(data: Partial<IUserNamespace>) {
return { super(data)
...super.defaults(), this.assignData(data)
namespaceId: 0,
}
} }
} }

View file

@ -14,25 +14,17 @@ export interface IUserSettings extends IAbstract {
} }
export default class UserSettingsModel extends AbstractModel implements IUserSettings { export default class UserSettingsModel extends AbstractModel implements IUserSettings {
name!: string name = ''
emailRemindersEnabled!: boolean emailRemindersEnabled = true
discoverableByName!: boolean discoverableByName = false
discoverableByEmail!: boolean discoverableByEmail = false
overdueTasksRemindersEnabled!: boolean overdueTasksRemindersEnabled = true
defaultListId!: undefined | IList['id'] defaultListId: undefined | IList['id'] = undefined
weekStart!: 0 | 1 | 2 | 3 | 4 | 5 | 6 weekStart: 0 | 1 | 2 | 3 | 4 | 5 | 6 = 0
timezone!: string timezone = ''
defaults() { constructor(data: Partial<IUserSettings>) {
return { super()
name: '', this.assignData(data)
emailRemindersEnabled: true,
discoverableByName: false,
discoverableByEmail: false,
overdueTasksRemindersEnabled: true,
defaultListId: undefined,
weekStart: 0,
timezone: '',
}
} }
} }

View file

@ -11,25 +11,17 @@ export interface IUserShareBase extends IAbstract {
} }
export default class UserShareBaseModel extends AbstractModel implements IUserShareBase { export default class UserShareBaseModel extends AbstractModel implements IUserShareBase {
userId!: IUser['id'] userId: IUser['id'] = ''
right!: Right right: Right = RIGHTS.READ
created: Date created: Date = null
updated: Date updated: Date = null
constructor(data) { constructor(data: Partial<IUserShareBase>) {
super(data) super()
this.assignData(data)
this.created = new Date(this.created) this.created = new Date(this.created)
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
} }
defaults() {
return {
userId: '',
right: RIGHTS.READ,
created: null,
updated: null,
}
}
} }