fix: merge duplicate types

This commit is contained in:
Dominik Pschenitschni 2022-07-21 19:16:13 +02:00
parent 305bfac578
commit e6654140c7
Signed by: dpschen
GPG Key ID: B257AC0149F43A77
3 changed files with 36 additions and 39 deletions

View File

@ -6,6 +6,7 @@ import LabelModel, { type ILabel } from '@/models/label'
import AttachmentModel, {type IAttachment} from '@/models/attachment' import AttachmentModel, {type IAttachment} from '@/models/attachment'
import SubscriptionModel, { type ISubscription } from '@/models/subscription' import SubscriptionModel, { type ISubscription } from '@/models/subscription'
import type { IList } from '@/models/list' import type { IList } from '@/models/list'
import type {IRepeats} from '@/types/IRepeats'
import {parseDateOrNull} from '@/helpers/parseDateOrNull' import {parseDateOrNull} from '@/helpers/parseDateOrNull'
import type { IBucket } from './bucket' import type { IBucket } from './bucket'
@ -21,11 +22,6 @@ export const TASK_REPEAT_MODES = {
export type TaskRepeatMode = typeof TASK_REPEAT_MODES[keyof typeof TASK_REPEAT_MODES] export type TaskRepeatMode = typeof TASK_REPEAT_MODES[keyof typeof TASK_REPEAT_MODES]
export interface RepeatAfter {
type: 'hours' | 'weeks' | 'months' | 'years' | 'days'
amount: number
}
export interface ITask extends AbstractModel { export interface ITask extends AbstractModel {
id: number id: number
title: string title: string
@ -39,7 +35,7 @@ export interface ITask extends AbstractModel {
dueDate: Date | null dueDate: Date | null
startDate: Date | null startDate: Date | null
endDate: Date | null endDate: Date | null
repeatAfter: number | RepeatAfter repeatAfter: number | IRepeats
repeatFromCurrentDate: boolean repeatFromCurrentDate: boolean
repeatMode: TaskRepeatMode repeatMode: TaskRepeatMode
reminderDates: Date[] reminderDates: Date[]
@ -77,7 +73,7 @@ export default class TaskModel extends AbstractModel implements ITask {
dueDate: Date | null dueDate: Date | null
startDate: Date | null startDate: Date | null
endDate: Date | null endDate: Date | null
declare repeatAfter: number | RepeatAfter declare repeatAfter: number | IRepeats
declare repeatFromCurrentDate: boolean declare repeatFromCurrentDate: boolean
declare repeatMode: TaskRepeatMode declare repeatMode: TaskRepeatMode
reminderDates: Date[] reminderDates: Date[]
@ -99,6 +95,7 @@ export default class TaskModel extends AbstractModel implements ITask {
updated: Date updated: Date
listId: IList['id'] // Meta, only used when creating a new task listId: IList['id'] // Meta, only used when creating a new task
declare bucketId: IBucket['id']
constructor(data: Partial<ITask>) { constructor(data: Partial<ITask>) {
super(data) super(data)
@ -160,7 +157,6 @@ export default class TaskModel extends AbstractModel implements ITask {
this.listId = Number(this.listId) this.listId = Number(this.listId)
} }
bucketId: number
defaults() { defaults() {
return { return {
@ -198,6 +194,7 @@ bucketId: number
updated: null, updated: null,
listId: 0, // Meta, only used when creating a new task listId: 0, // Meta, only used when creating a new task
bucketId: 0,
} }
} }

View File

@ -1,5 +1,6 @@
import {parseDate} from '../helpers/time/parseDate' import {parseDate} from '../helpers/time/parseDate'
import {PRIORITIES} from '@/models/constants/priorities' import {PRIORITIES} from '@/models/constants/priorities'
import {REPEAT_TYPES, type IRepeats, type RepeatType} from '@/types/IRepeats'
const VIKUNJA_PREFIXES: Prefixes = { const VIKUNJA_PREFIXES: Prefixes = {
label: '*', label: '*',
@ -27,24 +28,9 @@ export const PREFIXES = {
[PrefixMode.Todoist]: TODOIST_PREFIXES, [PrefixMode.Todoist]: TODOIST_PREFIXES,
} }
const priorities = PRIORITIES
enum RepeatType {
Hours = 'hours',
Days = 'days',
Weeks = 'weeks',
Months = 'months',
Years = 'years',
}
interface Repeats {
type: RepeatType,
amount: number,
}
interface repeatParsedResult { interface repeatParsedResult {
textWithoutMatched: string, textWithoutMatched: string,
repeats: Repeats | null, repeats: IRepeats | null,
} }
export interface ParsedTaskText { export interface ParsedTaskText {
@ -54,7 +40,7 @@ export interface ParsedTaskText {
list: string | null, list: string | null,
priority: number | null, priority: number | null,
assignees: string[], assignees: string[],
repeats: Repeats | null, repeats: IRepeats | null,
} }
interface Prefixes { interface Prefixes {
@ -144,7 +130,7 @@ const getPriority = (text: string, prefix: string): number | null => {
} }
for (const p of ps) { for (const p of ps) {
for (const pi of Object.values(priorities)) { for (const pi of Object.values(PRIORITIES)) {
if (pi === parseInt(p)) { if (pi === parseInt(p)) {
return parseInt(p) return parseInt(p)
} }
@ -199,55 +185,55 @@ const getRepeats = (text: string): repeatParsedResult => {
default: default:
amount = results[3] ? parseInt(results[3]) : 1 amount = results[3] ? parseInt(results[3]) : 1
} }
let type: RepeatType = RepeatType.Hours let type: RepeatType = REPEAT_TYPES.Hours
switch (results[0]) { switch (results[0]) {
case 'biennially': case 'biennially':
type = RepeatType.Years type = REPEAT_TYPES.Years
amount = 2 amount = 2
break break
case 'bianually': case 'bianually':
case 'semiannually': case 'semiannually':
type = RepeatType.Months type = REPEAT_TYPES.Months
amount = 6 amount = 6
break break
case 'yearly': case 'yearly':
case 'anually': case 'anually':
type = RepeatType.Years type = REPEAT_TYPES.Years
break break
case 'daily': case 'daily':
type = RepeatType.Days type = REPEAT_TYPES.Days
break break
case 'hourly': case 'hourly':
type = RepeatType.Hours type = REPEAT_TYPES.Hours
break break
case 'monthly': case 'monthly':
type = RepeatType.Months type = REPEAT_TYPES.Months
break break
case 'weekly': case 'weekly':
type = RepeatType.Weeks type = REPEAT_TYPES.Weeks
break break
default: default:
switch (results[5]) { switch (results[5]) {
case 'hour': case 'hour':
case 'hours': case 'hours':
type = RepeatType.Hours type = REPEAT_TYPES.Hours
break break
case 'day': case 'day':
case 'days': case 'days':
type = RepeatType.Days type = REPEAT_TYPES.Days
break break
case 'week': case 'week':
case 'weeks': case 'weeks':
type = RepeatType.Weeks type = REPEAT_TYPES.Weeks
break break
case 'month': case 'month':
case 'months': case 'months':
type = RepeatType.Months type = REPEAT_TYPES.Months
break break
case 'year': case 'year':
case 'years': case 'years':
type = RepeatType.Years type = REPEAT_TYPES.Years
break break
} }
} }

14
src/types/IRepeats.ts Normal file
View File

@ -0,0 +1,14 @@
export const REPEAT_TYPES = {
Hours: 'hours',
Days: 'days',
Weeks: 'weeks',
Months: 'months',
Years: 'years',
} as const
export type RepeatType = typeof REPEAT_TYPES[keyof typeof REPEAT_TYPES]
export interface IRepeats {
type: RepeatType,
amount: number,
}