From 16d8c2224bd76f8a82c9454e85672770b4cd7703 Mon Sep 17 00:00:00 2001 From: Dominik Pschenitschni Date: Sun, 13 Feb 2022 19:57:12 +0100 Subject: [PATCH] feat: add TSDoc definition to some models --- src/helpers/parseDateOrNull.ts | 5 +- src/models/list.ts | 53 +++++++++++++--- src/models/subscription.ts | 15 ++++- src/models/task.ts | 108 ++++++++++++++++++++++++++------- src/models/user.ts | 24 +++++++- 5 files changed, 169 insertions(+), 36 deletions(-) diff --git a/src/helpers/parseDateOrNull.ts b/src/helpers/parseDateOrNull.ts index 7fd1cf280..656e36dfc 100644 --- a/src/helpers/parseDateOrNull.ts +++ b/src/helpers/parseDateOrNull.ts @@ -1,4 +1,7 @@ -export const parseDateOrNull = date => { +/** + * Make date objects from timestamps +*/ +export function parseDateOrNull(date) { if (date instanceof Date) { return date } diff --git a/src/models/list.ts b/src/models/list.ts index 5093d195c..f846920ca 100644 --- a/src/models/list.ts +++ b/src/models/list.ts @@ -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) }) + + /** @type {number} */ + this.namespaceId - this.owner = new UserModel(this.owner) + /** @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) } diff --git a/src/models/subscription.ts b/src/models/subscription.ts index 68d0be855..81a86541f 100644 --- a/src/models/subscription.ts +++ b/src/models/subscription.ts @@ -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() { diff --git a/src/models/task.ts b/src/models/task.ts index 3d3e2258b..537a0e22e 100644 --- a/src/models/task.ts +++ b/src/models/task.ts @@ -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() { diff --git a/src/models/user.ts b/src/models/user.ts index ef6a48ef2..90d71ca7a 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -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() {