feat: add TSDoc definition to some models
This commit is contained in:
parent
658ca4c955
commit
16d8c2224b
5 changed files with 169 additions and 36 deletions
|
@ -1,4 +1,7 @@
|
||||||
export const parseDateOrNull = date => {
|
/**
|
||||||
|
* Make date objects from timestamps
|
||||||
|
*/
|
||||||
|
export function parseDateOrNull(date) {
|
||||||
if (date instanceof Date) {
|
if (date instanceof Date) {
|
||||||
return date
|
return date
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,31 +9,64 @@ export default class ListModel extends AbstractModel {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
super(data)
|
super(data)
|
||||||
|
|
||||||
if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
|
this.owner = new UserModel(this.owner)
|
||||||
this.hexColor = '#' + this.hexColor
|
|
||||||
}
|
/** @type {number} */
|
||||||
|
this.id
|
||||||
|
|
||||||
|
/** @type {string} */
|
||||||
|
this.title
|
||||||
|
|
||||||
|
/** @type {string} */
|
||||||
|
this.description
|
||||||
|
|
||||||
|
/** @type {UserModel} */
|
||||||
|
this.owner
|
||||||
|
|
||||||
|
/** @type {TaskModel[]} */
|
||||||
|
this.tasks
|
||||||
|
|
||||||
// Make all tasks to task models
|
// Make all tasks to task models
|
||||||
this.tasks = this.tasks.map(t => {
|
this.tasks = this.tasks.map(t => {
|
||||||
return new TaskModel(t)
|
return new TaskModel(t)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.owner = new UserModel(this.owner)
|
/** @type {number} */
|
||||||
|
this.namespaceId
|
||||||
|
|
||||||
|
/** @type {boolean} */
|
||||||
|
this.isArchived
|
||||||
|
|
||||||
|
/** @type {string} */
|
||||||
|
this.hexColor
|
||||||
|
|
||||||
|
if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
|
||||||
|
this.hexColor = '#' + this.hexColor
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {string} */
|
||||||
|
this.identifier
|
||||||
|
|
||||||
|
/** @type */
|
||||||
|
this.backgroundInformation
|
||||||
|
|
||||||
|
/** @type {boolean} */
|
||||||
|
this.isFavorite
|
||||||
|
|
||||||
|
/** @type */
|
||||||
|
this.subscription
|
||||||
|
|
||||||
if (typeof this.subscription !== 'undefined' && this.subscription !== null) {
|
if (typeof this.subscription !== 'undefined' && this.subscription !== null) {
|
||||||
this.subscription = new SubscriptionModel(this.subscription)
|
this.subscription = new SubscriptionModel(this.subscription)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {number} */
|
|
||||||
this.id
|
|
||||||
|
|
||||||
/** @type {boolean} */
|
|
||||||
this.isArchived
|
|
||||||
|
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
this.position
|
this.position
|
||||||
|
|
||||||
|
/** @type {Date} */
|
||||||
this.created = new Date(this.created)
|
this.created = new Date(this.created)
|
||||||
|
|
||||||
|
/** @type {Date} */
|
||||||
this.updated = new Date(this.updated)
|
this.updated = new Date(this.updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,21 @@ import UserModel from '@/models/user'
|
||||||
export default class SubscriptionModel extends AbstractModel {
|
export default class SubscriptionModel extends AbstractModel {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
super(data)
|
super(data)
|
||||||
this.user = new UserModel(this.user)
|
|
||||||
|
/** @type {number} */
|
||||||
|
this.id
|
||||||
|
|
||||||
|
/** @type {string} */
|
||||||
|
this.entity
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
|
this.entityId
|
||||||
|
|
||||||
|
/** @type {Date} */
|
||||||
this.created = new Date(this.created)
|
this.created = new Date(this.created)
|
||||||
|
|
||||||
|
/** @type {UserModel} */
|
||||||
|
this.user = new UserModel(this.user)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaults() {
|
defaults() {
|
||||||
|
|
|
@ -13,41 +13,81 @@ export default class TaskModel extends AbstractModel {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
super(data)
|
super(data)
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
this.id = Number(this.id)
|
this.id = Number(this.id)
|
||||||
this.title = this.title?.trim()
|
|
||||||
this.listId = Number(this.listId)
|
|
||||||
|
|
||||||
// Make date objects from timestamps
|
/** @type {string} */
|
||||||
this.dueDate = parseDateOrNull(this.dueDate)
|
this.title = this.title?.trim()
|
||||||
this.startDate = parseDateOrNull(this.startDate)
|
|
||||||
this.endDate = parseDateOrNull(this.endDate)
|
/** @type {string} */
|
||||||
|
this.description
|
||||||
|
|
||||||
|
/** @type {boolean} */
|
||||||
|
this.done
|
||||||
|
|
||||||
|
/** @type */
|
||||||
this.doneAt = parseDateOrNull(this.doneAt)
|
this.doneAt = parseDateOrNull(this.doneAt)
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
|
this.priority
|
||||||
|
|
||||||
|
/** @type {LabelModel[]} */
|
||||||
|
this.labels = this.labels
|
||||||
|
.map(l => new LabelModel(l))
|
||||||
|
.sort((f, s) => f.title > s.title ? 1 : -1)
|
||||||
|
|
||||||
|
/** @type {UserModel[]} */
|
||||||
|
// Parse the assignees into user models
|
||||||
|
this.assignees = this.assignees.map(a => {
|
||||||
|
return new UserModel(a)
|
||||||
|
})
|
||||||
|
|
||||||
|
/** @type {Date} */
|
||||||
|
this.dueDate = parseDateOrNull(this.dueDate)
|
||||||
|
|
||||||
|
/** @type {Date} */
|
||||||
|
this.startDate = parseDateOrNull(this.startDate)
|
||||||
|
|
||||||
|
/** @type {Date} */
|
||||||
|
this.endDate = parseDateOrNull(this.endDate)
|
||||||
|
|
||||||
|
/** @type */
|
||||||
|
this.repeatAfter
|
||||||
|
|
||||||
|
// Parse the repeat after into something usable
|
||||||
|
this.parseRepeatAfter()
|
||||||
|
|
||||||
|
/** @type {boolean} */
|
||||||
|
this.repeatFromCurrentDate
|
||||||
|
|
||||||
|
/** @type {TaskRepeatMode: 0 | 1 | 2} */
|
||||||
|
this.repeatMode
|
||||||
|
|
||||||
|
/** @type {Date[]} */
|
||||||
this.reminderDates = this.reminderDates.map(d => new Date(d))
|
this.reminderDates = this.reminderDates.map(d => new Date(d))
|
||||||
|
|
||||||
// Cancel all scheduled notifications for this task to be sure to only have available notifications
|
// Cancel all scheduled notifications for this task to be sure to only have available notifications
|
||||||
this.cancelScheduledNotifications().then(() => {
|
this.cancelScheduledNotifications().then(() => {
|
||||||
// Every time we see a reminder, we schedule a notification for it
|
// Every time we see a reminder, we schedule a notification for it
|
||||||
this.reminderDates.forEach(d => this.scheduleNotification(d))
|
this.reminderDates.forEach(d => this.scheduleNotification(d))
|
||||||
})
|
})
|
||||||
|
|
||||||
// Parse the repeat after into something usable
|
/** @type {number} */
|
||||||
this.parseRepeatAfter()
|
this.parentTaskId
|
||||||
|
|
||||||
// Parse the assignees into user models
|
/** @type {string} */
|
||||||
this.assignees = this.assignees.map(a => {
|
this.hexColor
|
||||||
return new UserModel(a)
|
|
||||||
})
|
|
||||||
this.createdBy = new UserModel(this.createdBy)
|
|
||||||
|
|
||||||
this.labels = this.labels.map(l => {
|
|
||||||
return new LabelModel(l)
|
|
||||||
})
|
|
||||||
.sort((f, s) => f.title > s.title ? 1 : -1)
|
|
||||||
|
|
||||||
if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
|
if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
|
||||||
this.hexColor = '#' + this.hexColor
|
this.hexColor = '#' + this.hexColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
|
this.percentDone
|
||||||
|
|
||||||
|
/** @type {{ [relationKind: string]: TaskModel }} */
|
||||||
|
this.relatedTasks
|
||||||
|
|
||||||
// Make all subtasks to task models
|
// Make all subtasks to task models
|
||||||
Object.keys(this.relatedTasks).forEach(relationKind => {
|
Object.keys(this.relatedTasks).forEach(relationKind => {
|
||||||
this.relatedTasks[relationKind] = this.relatedTasks[relationKind].map(t => {
|
this.relatedTasks[relationKind] = this.relatedTasks[relationKind].map(t => {
|
||||||
|
@ -56,21 +96,47 @@ export default class TaskModel extends AbstractModel {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Make all attachments to attachment models
|
// Make all attachments to attachment models
|
||||||
this.attachments = this.attachments.map(a => {
|
/** @type {AttachmentModel[]} */
|
||||||
return new AttachmentModel(a)
|
this.attachments = this.attachments.map(a => new AttachmentModel(a))
|
||||||
})
|
|
||||||
|
/** @type {string} */
|
||||||
|
this.identifier
|
||||||
|
|
||||||
// Set the task identifier to empty if the list does not have one
|
// Set the task identifier to empty if the list does not have one
|
||||||
if (this.identifier === `-${this.index}`) {
|
if (this.identifier === `-${this.index}`) {
|
||||||
this.identifier = ''
|
this.identifier = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
|
this.index
|
||||||
|
|
||||||
|
/** @type {boolean} */
|
||||||
|
this.isFavorite
|
||||||
|
|
||||||
|
/** @type {SubscriptionModel} */
|
||||||
|
this.subscription
|
||||||
|
|
||||||
if (typeof this.subscription !== 'undefined' && this.subscription !== null) {
|
if (typeof this.subscription !== 'undefined' && this.subscription !== null) {
|
||||||
this.subscription = new SubscriptionModel(this.subscription)
|
this.subscription = new SubscriptionModel(this.subscription)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
|
this.position
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
|
this.kanbanPosition
|
||||||
|
|
||||||
|
/** @type {UserModel} */
|
||||||
|
this.createdBy = new UserModel(this.createdBy)
|
||||||
|
|
||||||
|
/** @type {Date} */
|
||||||
this.created = new Date(this.created)
|
this.created = new Date(this.created)
|
||||||
|
|
||||||
|
/** @type {Date} */
|
||||||
this.updated = new Date(this.updated)
|
this.updated = new Date(this.updated)
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
|
this.listId = Number(this.listId)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaults() {
|
defaults() {
|
||||||
|
|
|
@ -5,12 +5,30 @@ export default class UserModel extends AbstractModel {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
super(data)
|
super(data)
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
|
this.id
|
||||||
|
|
||||||
|
/** @type {string} */
|
||||||
|
this.email
|
||||||
|
|
||||||
|
/** @type {string} */
|
||||||
|
this.username
|
||||||
|
|
||||||
|
/** @type {string} */
|
||||||
|
this.name
|
||||||
|
|
||||||
|
/** @type {Date} */
|
||||||
|
this.created = new Date(this.created)
|
||||||
|
|
||||||
|
/** @type {Date} */
|
||||||
|
this.updated = new Date(this.updated)
|
||||||
|
|
||||||
|
/** @type {UserSettingsModel} */
|
||||||
|
this.settings
|
||||||
|
|
||||||
if (this.settings !== null) {
|
if (this.settings !== null) {
|
||||||
this.settings = new UserSettingsModel(this.settings)
|
this.settings = new UserSettingsModel(this.settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.created = new Date(this.created)
|
|
||||||
this.updated = new Date(this.updated)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defaults() {
|
defaults() {
|
||||||
|
|
Loading…
Reference in a new issue