fix: use new assignData method for default data
This commit is contained in:
parent
8be1f81848
commit
8416b1f448
34 changed files with 317 additions and 615 deletions
|
@ -14,23 +14,12 @@ export default abstract class AbstractModel<Model extends IAbstract = IAbstract>
|
|||
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)
|
||||
|
||||
// Put all data in our model while overriding those with a value of null or undefined with their defaults
|
||||
Object.assign(
|
||||
this,
|
||||
this.defaults(),
|
||||
omitBy(data, isNil),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Default attributes that define the "empty" state.
|
||||
*/
|
||||
defaults(): Object {
|
||||
return {}
|
||||
Object.assign(this, omitBy(data, isNil))
|
||||
}
|
||||
}
|
|
@ -11,26 +11,18 @@ export interface IAttachment extends IAbstract {
|
|||
}
|
||||
|
||||
export default class AttachmentModel extends AbstractModel implements IAttachment {
|
||||
id!: number
|
||||
taskId!: number
|
||||
createdBy: IUser
|
||||
file: IFile
|
||||
created: Date
|
||||
id = 0
|
||||
taskId = 0
|
||||
createdBy: IUser = UserModel
|
||||
file: IFile = FileModel
|
||||
created: Date = null
|
||||
|
||||
constructor(data: Partial<IAttachment>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
this.createdBy = new UserModel(this.createdBy)
|
||||
this.file = new FileModel(this.file)
|
||||
this.created = new Date(this.created)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
taskId: 0,
|
||||
createdBy: UserModel,
|
||||
file: FileModel,
|
||||
created: null,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,10 @@ export interface IAvatar extends IAbstract {
|
|||
}
|
||||
|
||||
export default class AvatarModel extends AbstractModel implements IAvatar {
|
||||
avatarProvider!: AvatarProvider
|
||||
avatarProvider: AvatarProvider = 'default'
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
avatarProvider: '',
|
||||
}
|
||||
constructor(data: Partial<IAvatar>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
}
|
||||
}
|
|
@ -12,22 +12,17 @@ export interface IBackgroundImage extends IAbstract {
|
|||
}
|
||||
|
||||
export default class BackgroundImageModel extends AbstractModel implements IBackgroundImage {
|
||||
id!: number
|
||||
url!: string
|
||||
thumb!: string
|
||||
info!: {
|
||||
id = 0
|
||||
url = ''
|
||||
thumb = ''
|
||||
info: {
|
||||
author: string
|
||||
authorName: string
|
||||
}
|
||||
blurHash!: string
|
||||
} = {}
|
||||
blurHash = ''
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
url: '',
|
||||
thumb: '',
|
||||
info: {},
|
||||
blurHash: '',
|
||||
}
|
||||
constructor(data: Partial<IBackgroundImage>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
}
|
||||
}
|
|
@ -17,20 +17,21 @@ export interface IBucket extends IAbstract {
|
|||
}
|
||||
|
||||
export default class BucketModel extends AbstractModel implements IBucket {
|
||||
id!: number
|
||||
title!: string
|
||||
listId!: number
|
||||
limit!: number
|
||||
tasks!: ITask[]
|
||||
isDoneBucket!: boolean
|
||||
position!: number
|
||||
id = 0
|
||||
title = ''
|
||||
listId = ''
|
||||
limit = 0
|
||||
tasks: ITask[] = []
|
||||
isDoneBucket: false
|
||||
position: 0
|
||||
|
||||
createdBy: IUser
|
||||
created: Date
|
||||
updated: Date
|
||||
createdBy: IUser = null
|
||||
created: Date = null
|
||||
updated: Date = null
|
||||
|
||||
constructor(bucket) {
|
||||
super(bucket)
|
||||
constructor(data: Partial<IBucket>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
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.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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,13 +6,12 @@ export interface ICaldavToken extends IAbstract {
|
|||
}
|
||||
|
||||
export default class CaldavTokenModel extends AbstractModel implements ICaldavToken {
|
||||
id!: number
|
||||
created!: Date
|
||||
id: number
|
||||
created: Date
|
||||
|
||||
constructor(data? : Object) {
|
||||
super(data)
|
||||
|
||||
this.id
|
||||
constructor(data? : Partial<CaldavTokenModel>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
if (this.created) {
|
||||
this.created = new Date(this.created)
|
||||
|
|
|
@ -6,13 +6,11 @@ interface IEmailUpdate extends IAbstract {
|
|||
}
|
||||
|
||||
export default class EmailUpdateModel extends AbstractModel implements IEmailUpdate {
|
||||
newEmail!: string
|
||||
password!: string
|
||||
newEmail = ''
|
||||
password = ''
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
newEmail: '',
|
||||
password: '',
|
||||
}
|
||||
constructor(data : Partial<IEmailUpdate>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
}
|
||||
}
|
|
@ -9,27 +9,19 @@ export interface IFile extends IAbstract {
|
|||
}
|
||||
|
||||
export default class FileModel extends AbstractModel implements IFile {
|
||||
id!: number
|
||||
mime!: string
|
||||
name!: string
|
||||
size!: number
|
||||
created: Date
|
||||
id = 0
|
||||
mime = ''
|
||||
name = ''
|
||||
size = 0
|
||||
created: Date = null
|
||||
|
||||
constructor(data: Partial<IFile>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
this.created = new Date(this.created)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
mime: '',
|
||||
name: '',
|
||||
size: 0,
|
||||
created: null,
|
||||
}
|
||||
}
|
||||
|
||||
getHumanSize() {
|
||||
const sizes = {
|
||||
0: 'B',
|
||||
|
|
|
@ -18,25 +18,23 @@ export interface ILabel extends IAbstract {
|
|||
}
|
||||
|
||||
export default class LabelModel extends AbstractModel implements ILabel {
|
||||
id!: number
|
||||
title!: string
|
||||
hexColor!: string
|
||||
description!: string
|
||||
createdBy!: IUser
|
||||
listId!: number
|
||||
textColor!: string
|
||||
|
||||
created: Date
|
||||
updated: Date
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
id = 0
|
||||
title = ''
|
||||
// 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
|
||||
}
|
||||
hexColor = DEFAULT_LABEL_BACKGROUND_COLOR
|
||||
description = ''
|
||||
createdBy: IUser
|
||||
listId = 0
|
||||
textColor = ''
|
||||
|
||||
created: Date = null
|
||||
updated: Date = null
|
||||
|
||||
constructor(data: Partial<ILabel>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
if (this.hexColor.substring(0, 1) !== '#') {
|
||||
this.hexColor = '#' + this.hexColor
|
||||
}
|
||||
|
@ -46,19 +44,4 @@ export default class LabelModel extends AbstractModel implements ILabel {
|
|||
this.created = new Date(this.created)
|
||||
this.updated = new Date(this.updated)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
title: '',
|
||||
hexColor: '',
|
||||
description: '',
|
||||
createdBy: UserModel,
|
||||
listId: 0,
|
||||
textColor: '',
|
||||
|
||||
created: null,
|
||||
updated: null,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,15 +7,12 @@ export interface ILabelTask extends IAbstract {
|
|||
}
|
||||
|
||||
export default class LabelTask extends AbstractModel implements ILabelTask {
|
||||
id!: number
|
||||
taskId!: number
|
||||
labelId!: number
|
||||
id = 0
|
||||
taskId = 0
|
||||
labelId = 0
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
taskId: 0,
|
||||
labelId: 0,
|
||||
}
|
||||
constructor(data: Partial<ILabelTask>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
}
|
||||
}
|
|
@ -16,41 +16,24 @@ export interface ILinkShare extends IAbstract {
|
|||
}
|
||||
|
||||
export default class LinkShareModel extends AbstractModel implements ILinkShare {
|
||||
id!: number
|
||||
hash!: string
|
||||
right!: Right
|
||||
sharedBy: IUser
|
||||
sharingType!: number // FIXME: use correct numbers
|
||||
listId!: number
|
||||
name!: string
|
||||
password!: string
|
||||
created: Date
|
||||
updated: Date
|
||||
id = 0
|
||||
hash = ''
|
||||
right: Right = RIGHTS.READ
|
||||
sharedBy: IUser = UserModel
|
||||
sharingType = 0 // FIXME: use correct numbers
|
||||
listId = 0
|
||||
name: ''
|
||||
password: ''
|
||||
created: Date = null
|
||||
updated: Date = null
|
||||
|
||||
constructor(data) {
|
||||
// The constructor of AbstractModel handles all the default parsing.
|
||||
super(data)
|
||||
constructor(data: Partial<ILinkShare>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
this.sharedBy = new UserModel(this.sharedBy)
|
||||
|
||||
this.created = new Date(this.created)
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ export interface IList extends IAbstract {
|
|||
isArchived: boolean
|
||||
hexColor: string
|
||||
identifier: string
|
||||
backgroundInformation: any
|
||||
backgroundInformation: any // FIXME: improve type
|
||||
isFavorite: boolean
|
||||
subscription: ISubscription
|
||||
position: number
|
||||
|
@ -27,26 +27,27 @@ export interface IList extends IAbstract {
|
|||
}
|
||||
|
||||
export default class ListModel extends AbstractModel implements IList {
|
||||
id!: number
|
||||
title!: string
|
||||
description!: string
|
||||
owner: IUser
|
||||
tasks: ITask[]
|
||||
namespaceId!: INamespace['id']
|
||||
isArchived!: boolean
|
||||
hexColor!: string
|
||||
identifier!: string
|
||||
backgroundInformation!: any
|
||||
isFavorite!: boolean
|
||||
subscription!: ISubscription
|
||||
position!: number
|
||||
backgroundBlurHash!: string
|
||||
id = 0
|
||||
title = ''
|
||||
description = ''
|
||||
owner: IUser = UserModel
|
||||
tasks: ITask[] = []
|
||||
namespaceId: INamespace['id'] = 0
|
||||
isArchived = false
|
||||
hexColor = ''
|
||||
identifier = ''
|
||||
backgroundInformation: any = null
|
||||
isFavorite = false
|
||||
subscription: ISubscription = null
|
||||
position = 0
|
||||
backgroundBlurHash = ''
|
||||
|
||||
created: Date
|
||||
updated: Date
|
||||
created: Date = null
|
||||
updated: Date = null
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
constructor(data: Partial<IList>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
this.owner = new UserModel(this.owner)
|
||||
|
||||
|
@ -67,29 +68,6 @@ export default class ListModel extends AbstractModel implements IList {
|
|||
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() {
|
||||
return this.getSavedFilterId() > 0
|
||||
}
|
||||
|
|
|
@ -9,20 +9,14 @@ export interface IListDuplicate extends IAbstract {
|
|||
}
|
||||
|
||||
export default class ListDuplicateModel extends AbstractModel implements IListDuplicate {
|
||||
listId!: number
|
||||
namespaceId!: INamespace['id']
|
||||
list: IList
|
||||
listId = 0
|
||||
namespaceId: INamespace['id'] = 0
|
||||
list: IList = ListModel
|
||||
|
||||
constructor(data : Partial<IListDuplicate>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
this.list = new ListModel(this.list)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
listId: 0,
|
||||
namespaceId: 0,
|
||||
list: ListModel,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,20 +18,21 @@ export interface INamespace extends IAbstract {
|
|||
}
|
||||
|
||||
export default class NamespaceModel extends AbstractModel implements INamespace {
|
||||
id!: number
|
||||
title!: string
|
||||
description!: string
|
||||
owner: IUser
|
||||
lists: IList[]
|
||||
isArchived!: boolean
|
||||
hexColor!: string
|
||||
subscription!: ISubscription
|
||||
id = 0
|
||||
title = ''
|
||||
description = ''
|
||||
owner: IUser = UserModel
|
||||
lists: IList[] = []
|
||||
isArchived = false
|
||||
hexColor = ''
|
||||
subscription: ISubscription = null
|
||||
|
||||
created: Date
|
||||
updated: Date
|
||||
created: Date = null
|
||||
updated: Date = null
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
constructor(data: Partial<INamespace>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
|
||||
this.hexColor = '#' + this.hexColor
|
||||
|
@ -50,21 +51,4 @@ export default class NamespaceModel extends AbstractModel implements INamespace
|
|||
this.created = new Date(this.created)
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import {parseDateOrNull} from '@/helpers/parseDateOrNull'
|
|||
import UserModel, { type IUser } from '@/models/user'
|
||||
import TaskModel, { type ITask } from '@/models/task'
|
||||
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'
|
||||
|
||||
export const NOTIFICATION_NAMES = {
|
||||
|
@ -33,6 +33,7 @@ interface NotificationDeleted extends Notification {
|
|||
|
||||
interface NotificationCreated extends Notification {
|
||||
task: ITask
|
||||
list: IList
|
||||
}
|
||||
|
||||
interface NotificationMemberAdded extends Notification {
|
||||
|
@ -51,16 +52,17 @@ export interface INotification extends IAbstract {
|
|||
}
|
||||
|
||||
export default class NotificationModel extends AbstractModel implements INotification {
|
||||
id!: number
|
||||
name!: string
|
||||
notification!: NotificationTask | NotificationAssigned | NotificationDeleted | NotificationCreated | NotificationMemberAdded
|
||||
read!: boolean
|
||||
readAt: Date | null
|
||||
id = 0
|
||||
name = ''
|
||||
notification: NotificationTask | NotificationAssigned | NotificationDeleted | NotificationCreated | NotificationMemberAdded = null
|
||||
read = false
|
||||
readAt: Date | null = null
|
||||
|
||||
created: Date
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
constructor(data: Partial<INotification>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
switch (this.name) {
|
||||
case NOTIFICATION_NAMES.TASK_COMMENT:
|
||||
|
@ -102,16 +104,6 @@ export default class NotificationModel extends AbstractModel implements INotific
|
|||
this.readAt = parseDateOrNull(this.readAt)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
name: '',
|
||||
notification: null,
|
||||
read: false,
|
||||
readAt: null,
|
||||
}
|
||||
}
|
||||
|
||||
toText(user = null) {
|
||||
let who = ''
|
||||
|
||||
|
|
|
@ -7,21 +7,14 @@ export interface IPasswordReset extends IAbstract {
|
|||
}
|
||||
|
||||
export default class PasswordResetModel extends AbstractModel implements IPasswordReset {
|
||||
token: string
|
||||
newPassword!: string
|
||||
email!: string
|
||||
token = ''
|
||||
newPassword = ''
|
||||
email = ''
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
constructor(data: Partial<IPasswordReset>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
this.token = localStorage.getItem('passwordResetToken')
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
token: '',
|
||||
newPassword: '',
|
||||
email: '',
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,13 +6,11 @@ export interface IPasswordUpdate extends IAbstract {
|
|||
}
|
||||
|
||||
export default class PasswordUpdateModel extends AbstractModel implements IPasswordUpdate {
|
||||
newPassword!: string
|
||||
oldPassword!: string
|
||||
newPassword = ''
|
||||
oldPassword = ''
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
newPassword: '',
|
||||
oldPassword: '',
|
||||
}
|
||||
constructor(data: Partial<IPasswordUpdate>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ import AbstractModel, { type IAbstract } from '@/models/abstractModel'
|
|||
import UserModel, { type IUser } from '@/models/user'
|
||||
|
||||
export interface ISavedFilter extends IAbstract {
|
||||
id: 0
|
||||
id: number
|
||||
title: string
|
||||
description: string
|
||||
filters: {
|
||||
|
@ -21,10 +21,10 @@ export interface ISavedFilter extends IAbstract {
|
|||
}
|
||||
|
||||
export default class SavedFilterModel extends AbstractModel implements ISavedFilter {
|
||||
id!: 0
|
||||
title!: string
|
||||
description!: string
|
||||
filters!: {
|
||||
id = 0
|
||||
title = ''
|
||||
description = ''
|
||||
filters: {
|
||||
sortBy: ('done' | 'id')[]
|
||||
orderBy: ('asc' | 'desc')[]
|
||||
filterBy: 'done'[]
|
||||
|
@ -32,27 +32,7 @@ export default class SavedFilterModel extends AbstractModel implements ISavedFil
|
|||
filterComparator: 'equals'[]
|
||||
filterConcat: 'and'
|
||||
filterIncludeNulls: boolean
|
||||
}
|
||||
|
||||
owner: IUser
|
||||
created: Date
|
||||
updated: Date
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
|
||||
this.owner = new UserModel(this.owner)
|
||||
|
||||
this.created = new Date(this.created)
|
||||
this.updated = new Date(this.updated)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
title: '',
|
||||
description: '',
|
||||
filters: {
|
||||
} = {
|
||||
sortBy: ['done', 'id'],
|
||||
orderBy: ['asc', 'desc'],
|
||||
filterBy: ['done'],
|
||||
|
@ -60,12 +40,20 @@ export default class SavedFilterModel extends AbstractModel implements ISavedFil
|
|||
filterComparator: ['equals'],
|
||||
filterConcat: 'and',
|
||||
filterIncludeNulls: true,
|
||||
},
|
||||
|
||||
owner: {},
|
||||
created: null,
|
||||
updated: null,
|
||||
}
|
||||
|
||||
owner: IUser = {}
|
||||
created: Date = null
|
||||
updated: Date = null
|
||||
|
||||
constructor(data: Partial<ISavedFilter>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
this.owner = new UserModel(this.owner)
|
||||
|
||||
this.created = new Date(this.created)
|
||||
this.updated = new Date(this.updated)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,27 +11,18 @@ export interface ISubscription extends IAbstract {
|
|||
}
|
||||
|
||||
export default class SubscriptionModel extends AbstractModel implements ISubscription {
|
||||
id!: number
|
||||
entity!: string // FIXME: correct type?
|
||||
entityId!: number // FIXME: correct type?
|
||||
user: IUser
|
||||
id = 0
|
||||
entity = ''
|
||||
entityId = 0
|
||||
user: IUser = {}
|
||||
|
||||
created: Date
|
||||
created: Date = null
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
constructor(data : Partial<ISubscription>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
this.created = new Date(this.created)
|
||||
this.user = new UserModel(this.user)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
entity: '',
|
||||
entityId: 0,
|
||||
created: null,
|
||||
user: {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 UserModel, { type IUser } from '@/models/user'
|
||||
|
@ -61,44 +61,45 @@ export interface ITask extends IAbstract {
|
|||
}
|
||||
|
||||
export default class TaskModel extends AbstractModel implements ITask {
|
||||
id: number
|
||||
title: string
|
||||
description!: string
|
||||
done!: boolean
|
||||
doneAt: Date | null
|
||||
priority!: Priority
|
||||
labels: ILabel[]
|
||||
assignees: IUser[]
|
||||
id = 0
|
||||
title = ''
|
||||
description = ''
|
||||
done = false
|
||||
doneAt: Date | null = null
|
||||
priority: Priority = PRIORITIES.UNSET
|
||||
labels: ILabel[] = []
|
||||
assignees: IUser[] = []
|
||||
|
||||
dueDate: Date | null
|
||||
startDate: Date | null
|
||||
endDate: Date | null
|
||||
repeatAfter!: number | IRepeats
|
||||
repeatFromCurrentDate!: boolean
|
||||
repeatMode!: TaskRepeatMode
|
||||
reminderDates: Date[]
|
||||
parentTaskId!: ITask['id']
|
||||
hexColor!: string
|
||||
percentDone!: number
|
||||
relatedTasks!: { [relationKind: string]: ITask } // FIXME: use relationKinds
|
||||
attachments: IAttachment[]
|
||||
identifier!: string
|
||||
index!: number
|
||||
isFavorite!: boolean
|
||||
subscription!: ISubscription
|
||||
dueDate: Date | null = 0
|
||||
startDate: Date | null = 0
|
||||
endDate: Date | null = 0
|
||||
repeatAfter: number | IRepeats = 0
|
||||
repeatFromCurrentDate = false
|
||||
repeatMode: TaskRepeatMode = TASK_REPEAT_MODES.REPEAT_MODE_DEFAULT
|
||||
reminderDates: Date[] = []
|
||||
parentTaskId: ITask['id'] = 0
|
||||
hexColor = ''
|
||||
percentDone = 0
|
||||
relatedTasks: { [relationKind: string]: ITask } = {}
|
||||
attachments: IAttachment[] = []
|
||||
identifier = ''
|
||||
index = 0
|
||||
isFavorite = false
|
||||
subscription: ISubscription = null
|
||||
|
||||
position!: number
|
||||
kanbanPosition!: number
|
||||
position = 0
|
||||
kanbanPosition = 0
|
||||
|
||||
createdBy: IUser
|
||||
created: Date
|
||||
updated: Date
|
||||
createdBy: IUser = UserModel
|
||||
created: Date = null
|
||||
updated: Date = null
|
||||
|
||||
listId: IList['id'] // Meta, only used when creating a new task
|
||||
bucketId!: IBucket['id']
|
||||
listId: IList['id'] = 0
|
||||
bucketId: IBucket['id'] = 0
|
||||
|
||||
constructor(data: Partial<ITask>) {
|
||||
super(data)
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
this.id = Number(this.id)
|
||||
this.title = this.title?.trim()
|
||||
|
@ -158,46 +159,6 @@ export default class TaskModel extends AbstractModel implements ITask {
|
|||
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() {
|
||||
if (this.identifier === '') {
|
||||
return `#${this.index}`
|
||||
|
|
|
@ -9,20 +9,13 @@ export interface ITaskAssignee extends IAbstract {
|
|||
}
|
||||
|
||||
export default class TaskAssigneeModel extends AbstractModel implements ITaskAssignee {
|
||||
created: Date
|
||||
userId!: IUser['id']
|
||||
taskId!: ITask['id']
|
||||
created: Date = null
|
||||
userId: IUser['id'] = 0
|
||||
taskId: ITask['id'] = 0
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
constructor(data: Partial<ITaskAssignee>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
this.created = new Date(this.created)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
created: null,
|
||||
userId: 0,
|
||||
taskId: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,29 +13,20 @@ export interface ITaskComment extends IAbstract {
|
|||
}
|
||||
|
||||
export default class TaskCommentModel extends AbstractModel implements ITaskComment {
|
||||
id!: number
|
||||
taskId!: ITask['id']
|
||||
comment!: string
|
||||
author: IUser
|
||||
id = 0
|
||||
taskId: ITask['id'] = 0
|
||||
comment = ''
|
||||
author: IUser = UserModel
|
||||
|
||||
created: Date
|
||||
updated: Date
|
||||
created: Date = null
|
||||
updated: Date = null
|
||||
|
||||
constructor(data: Partial<ITaskComment>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
this.author = new UserModel(this.author)
|
||||
this.created = new Date(this.created)
|
||||
this.updated = new Date(this.updated)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
taskId: 0,
|
||||
comment: '',
|
||||
author: UserModel,
|
||||
created: null,
|
||||
updated: null,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,29 +30,19 @@ export interface ITaskRelation extends IAbstract {
|
|||
}
|
||||
|
||||
export default class TaskRelationModel extends AbstractModel implements ITaskRelation {
|
||||
id!: number
|
||||
otherTaskId!: ITask['id']
|
||||
taskId!: ITask['id']
|
||||
relationKind!: RelationKind
|
||||
id = 0
|
||||
otherTaskId: ITask['id'] = 0
|
||||
taskId: ITask['id'] = 0
|
||||
relationKind: RelationKind = ''
|
||||
|
||||
createdBy: IUser
|
||||
created: Date
|
||||
createdBy: IUser = UserModel
|
||||
created: Date = null
|
||||
|
||||
constructor(data: Partial<ITaskRelation>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
this.createdBy = new UserModel(this.createdBy)
|
||||
this.created = new Date(this.created)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
otherTaskId: 0,
|
||||
taskId: 0,
|
||||
relationKind: '',
|
||||
|
||||
createdBy: UserModel,
|
||||
created: null,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,18 +16,19 @@ export interface ITeam extends IAbstract {
|
|||
}
|
||||
|
||||
export default class TeamModel extends AbstractModel implements ITeam {
|
||||
id!: number
|
||||
name!: string
|
||||
description!: string
|
||||
members: ITeamMember[]
|
||||
right!: Right
|
||||
id = 0
|
||||
name = ''
|
||||
description = ''
|
||||
members: ITeamMember[] = []
|
||||
right: Right = RIGHTS.READ
|
||||
|
||||
createdBy: IUser
|
||||
created: Date
|
||||
updated: Date
|
||||
createdBy: IUser = {} // FIXME: seems wrong
|
||||
created: Date = null
|
||||
updated: Date = null
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
constructor(data: Partial<ITeam>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
// Make the members to usermodels
|
||||
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.updated = new Date(this.updated)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
name: '',
|
||||
description: '',
|
||||
members: [],
|
||||
right: RIGHTS.READ,
|
||||
|
||||
createdBy: {},
|
||||
created: null,
|
||||
updated: null,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,12 +6,10 @@ export interface ITeamList extends TeamShareBaseModel {
|
|||
}
|
||||
|
||||
export default class TeamListModel extends TeamShareBaseModel implements ITeamList {
|
||||
listId!: IList['id']
|
||||
listId: IList['id'] = 0
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
...super.defaults(),
|
||||
listId: 0,
|
||||
}
|
||||
constructor(data: Partial<ITeamList>) {
|
||||
super(data)
|
||||
this.assignData(data)
|
||||
}
|
||||
}
|
|
@ -7,14 +7,11 @@ export interface ITeamMember extends UserModel {
|
|||
}
|
||||
|
||||
export default class TeamMemberModel extends UserModel implements ITeamMember {
|
||||
admin!: boolean
|
||||
teamId!: IList['id']
|
||||
admin = false
|
||||
teamId: IList['id'] = 0
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
...super.defaults(),
|
||||
admin: false,
|
||||
teamId: 0,
|
||||
}
|
||||
constructor(data: Partial<ITeamMember>) {
|
||||
super(data)
|
||||
this.assignData(data)
|
||||
}
|
||||
}
|
|
@ -6,12 +6,10 @@ export interface ITeamNamespace extends TeamShareBaseModel {
|
|||
}
|
||||
|
||||
export default class TeamNamespaceModel extends TeamShareBaseModel implements ITeamNamespace {
|
||||
namespaceId!: INamespace['id']
|
||||
namespaceId: INamespace['id'] = 0
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
...super.defaults(),
|
||||
namespaceId: 0,
|
||||
}
|
||||
constructor(data: Partial<ITeamNamespace>) {
|
||||
super(data)
|
||||
this.assignData(data)
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
*/
|
||||
export default class TeamShareBaseModel extends AbstractModel implements ITeamShareBase {
|
||||
teamId!: ITeam['id']
|
||||
right!: Right
|
||||
teamId: ITeam['id'] = 0
|
||||
right: Right = RIGHTS.READ
|
||||
|
||||
created: Date
|
||||
updated: Date
|
||||
created: Date = null
|
||||
updated: Date = null
|
||||
|
||||
constructor(data: Partial<ITeamShareBase>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
this.created = new Date(this.created)
|
||||
this.updated = new Date(this.updated)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
teamId: 0,
|
||||
right: RIGHTS.READ,
|
||||
|
||||
created: null,
|
||||
updated: null,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,16 +6,13 @@ export interface ITotp extends IAbstract {
|
|||
url: string
|
||||
}
|
||||
|
||||
export default class TotpModel extends AbstractModel implements ITotp{
|
||||
secret!: string
|
||||
enabled!: boolean
|
||||
url!: string
|
||||
export default class TotpModel extends AbstractModel implements ITotp {
|
||||
secret = ''
|
||||
enabled = false
|
||||
url = ''
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
secret: '',
|
||||
enabled: false,
|
||||
url: '',
|
||||
}
|
||||
constructor(data: Partial<ITotp>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
}
|
||||
}
|
|
@ -13,17 +13,18 @@ export interface IUser extends IAbstract {
|
|||
}
|
||||
|
||||
export default class UserModel extends AbstractModel implements IUser {
|
||||
id!: number
|
||||
email!: string
|
||||
username!: string
|
||||
name!: string
|
||||
id = 0
|
||||
email = ''
|
||||
username = ''
|
||||
name = ''
|
||||
|
||||
created: Date
|
||||
updated: Date
|
||||
settings: IUserSettings
|
||||
created: Date = null
|
||||
updated: Date = null
|
||||
settings: IUserSettings = null
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
constructor(data: Partial<IUser>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
this.created = new Date(this.created)
|
||||
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) {
|
||||
return `${window.API_URL}/avatar/${this.username}?size=${size}`
|
||||
}
|
||||
|
|
|
@ -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
|
||||
export default class UserListModel extends UserShareBaseModel implements IUserList {
|
||||
listId!: IList['id']
|
||||
listId: IList['id'] = 0
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
...super.defaults(),
|
||||
listId: 0,
|
||||
}
|
||||
constructor(data: Partial<IUserList>) {
|
||||
super(data)
|
||||
this.assignData(data)
|
||||
}
|
||||
}
|
|
@ -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
|
||||
export default class UserNamespaceModel extends UserShareBaseModel implements IUserNamespace {
|
||||
namespaceId!: INamespace['id']
|
||||
namespaceId: INamespace['id'] = 0
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
...super.defaults(),
|
||||
namespaceId: 0,
|
||||
}
|
||||
constructor(data: Partial<IUserNamespace>) {
|
||||
super(data)
|
||||
this.assignData(data)
|
||||
}
|
||||
}
|
|
@ -14,25 +14,17 @@ export interface IUserSettings extends IAbstract {
|
|||
}
|
||||
|
||||
export default class UserSettingsModel extends AbstractModel implements IUserSettings {
|
||||
name!: string
|
||||
emailRemindersEnabled!: boolean
|
||||
discoverableByName!: boolean
|
||||
discoverableByEmail!: boolean
|
||||
overdueTasksRemindersEnabled!: boolean
|
||||
defaultListId!: undefined | IList['id']
|
||||
weekStart!: 0 | 1 | 2 | 3 | 4 | 5 | 6
|
||||
timezone!: string
|
||||
name = ''
|
||||
emailRemindersEnabled = true
|
||||
discoverableByName = false
|
||||
discoverableByEmail = false
|
||||
overdueTasksRemindersEnabled = true
|
||||
defaultListId: undefined | IList['id'] = undefined
|
||||
weekStart: 0 | 1 | 2 | 3 | 4 | 5 | 6 = 0
|
||||
timezone = ''
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
name: '',
|
||||
emailRemindersEnabled: true,
|
||||
discoverableByName: false,
|
||||
discoverableByEmail: false,
|
||||
overdueTasksRemindersEnabled: true,
|
||||
defaultListId: undefined,
|
||||
weekStart: 0,
|
||||
timezone: '',
|
||||
}
|
||||
constructor(data: Partial<IUserSettings>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
}
|
||||
}
|
|
@ -11,25 +11,17 @@ export interface IUserShareBase extends IAbstract {
|
|||
}
|
||||
|
||||
export default class UserShareBaseModel extends AbstractModel implements IUserShareBase {
|
||||
userId!: IUser['id']
|
||||
right!: Right
|
||||
userId: IUser['id'] = ''
|
||||
right: Right = RIGHTS.READ
|
||||
|
||||
created: Date
|
||||
updated: Date
|
||||
created: Date = null
|
||||
updated: Date = null
|
||||
|
||||
constructor(data: Partial<IUserShareBase>) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
constructor(data) {
|
||||
super(data)
|
||||
this.created = new Date(this.created)
|
||||
this.updated = new Date(this.updated)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
userId: '',
|
||||
right: RIGHTS.READ,
|
||||
|
||||
created: null,
|
||||
updated: null,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue