feat: add TSDoc definition to some models

This commit is contained in:
Dominik Pschenitschni 2022-02-13 19:57:12 +01:00 committed by kolaente
parent 658ca4c955
commit 16d8c2224b
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
5 changed files with 169 additions and 36 deletions

View file

@ -1,4 +1,7 @@
export const parseDateOrNull = date => {
/**
* Make date objects from timestamps
*/
export function parseDateOrNull(date) {
if (date instanceof Date) {
return date
}

View file

@ -9,31 +9,64 @@ export default class ListModel extends AbstractModel {
constructor(data) {
super(data)
if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
this.hexColor = '#' + this.hexColor
}
this.owner = new UserModel(this.owner)
/** @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
this.tasks = this.tasks.map(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) {
this.subscription = new SubscriptionModel(this.subscription)
}
/** @type {number} */
this.id
/** @type {boolean} */
this.isArchived
/** @type {number} */
this.position
/** @type {Date} */
this.created = new Date(this.created)
/** @type {Date} */
this.updated = new Date(this.updated)
}

View file

@ -4,8 +4,21 @@ import UserModel from '@/models/user'
export default class SubscriptionModel extends AbstractModel {
constructor(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)
/** @type {UserModel} */
this.user = new UserModel(this.user)
}
defaults() {

View file

@ -13,41 +13,81 @@ export default class TaskModel extends AbstractModel {
constructor(data) {
super(data)
/** @type {number} */
this.id = Number(this.id)
this.title = this.title?.trim()
this.listId = Number(this.listId)
// Make date objects from timestamps
this.dueDate = parseDateOrNull(this.dueDate)
this.startDate = parseDateOrNull(this.startDate)
this.endDate = parseDateOrNull(this.endDate)
/** @type {string} */
this.title = this.title?.trim()
/** @type {string} */
this.description
/** @type {boolean} */
this.done
/** @type */
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))
// Cancel all scheduled notifications for this task to be sure to only have available notifications
this.cancelScheduledNotifications().then(() => {
// Every time we see a reminder, we schedule a notification for it
this.reminderDates.forEach(d => this.scheduleNotification(d))
})
// Parse the repeat after into something usable
this.parseRepeatAfter()
/** @type {number} */
this.parentTaskId
// Parse the assignees into user models
this.assignees = this.assignees.map(a => {
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)
/** @type {string} */
this.hexColor
if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
this.hexColor = '#' + this.hexColor
}
/** @type {number} */
this.percentDone
/** @type {{ [relationKind: string]: TaskModel }} */
this.relatedTasks
// Make all subtasks to task models
Object.keys(this.relatedTasks).forEach(relationKind => {
this.relatedTasks[relationKind] = this.relatedTasks[relationKind].map(t => {
@ -56,21 +96,47 @@ export default class TaskModel extends AbstractModel {
})
// Make all attachments to attachment models
this.attachments = this.attachments.map(a => {
return new AttachmentModel(a)
})
/** @type {AttachmentModel[]} */
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
if (this.identifier === `-${this.index}`) {
this.identifier = ''
}
/** @type {number} */
this.index
/** @type {boolean} */
this.isFavorite
/** @type {SubscriptionModel} */
this.subscription
if (typeof this.subscription !== 'undefined' && this.subscription !== null) {
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)
/** @type {Date} */
this.updated = new Date(this.updated)
/** @type {number} */
this.listId = Number(this.listId)
}
defaults() {

View file

@ -5,12 +5,30 @@ export default class UserModel extends AbstractModel {
constructor(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) {
this.settings = new UserSettingsModel(this.settings)
}
this.created = new Date(this.created)
this.updated = new Date(this.updated)
}
defaults() {