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 SubscriptionModel, { type ISubscription } from '@/models/subscription'
import type { IList } from '@/models/list'
import type {IRepeats} from '@/types/IRepeats'
import {parseDateOrNull} from '@/helpers/parseDateOrNull'
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 interface RepeatAfter {
type: 'hours' | 'weeks' | 'months' | 'years' | 'days'
amount: number
}
export interface ITask extends AbstractModel {
id: number
title: string
@ -39,7 +35,7 @@ export interface ITask extends AbstractModel {
dueDate: Date | null
startDate: Date | null
endDate: Date | null
repeatAfter: number | RepeatAfter
repeatAfter: number | IRepeats
repeatFromCurrentDate: boolean
repeatMode: TaskRepeatMode
reminderDates: Date[]
@ -77,7 +73,7 @@ export default class TaskModel extends AbstractModel implements ITask {
dueDate: Date | null
startDate: Date | null
endDate: Date | null
declare repeatAfter: number | RepeatAfter
declare repeatAfter: number | IRepeats
declare repeatFromCurrentDate: boolean
declare repeatMode: TaskRepeatMode
reminderDates: Date[]
@ -99,6 +95,7 @@ export default class TaskModel extends AbstractModel implements ITask {
updated: Date
listId: IList['id'] // Meta, only used when creating a new task
declare bucketId: IBucket['id']
constructor(data: Partial<ITask>) {
super(data)
@ -160,7 +157,6 @@ export default class TaskModel extends AbstractModel implements ITask {
this.listId = Number(this.listId)
}
bucketId: number
defaults() {
return {
@ -198,6 +194,7 @@ bucketId: number
updated: null,
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 {PRIORITIES} from '@/models/constants/priorities'
import {REPEAT_TYPES, type IRepeats, type RepeatType} from '@/types/IRepeats'
const VIKUNJA_PREFIXES: Prefixes = {
label: '*',
@ -27,24 +28,9 @@ export const 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 {
textWithoutMatched: string,
repeats: Repeats | null,
repeats: IRepeats | null,
}
export interface ParsedTaskText {
@ -54,7 +40,7 @@ export interface ParsedTaskText {
list: string | null,
priority: number | null,
assignees: string[],
repeats: Repeats | null,
repeats: IRepeats | null,
}
interface Prefixes {
@ -144,7 +130,7 @@ const getPriority = (text: string, prefix: string): number | null => {
}
for (const p of ps) {
for (const pi of Object.values(priorities)) {
for (const pi of Object.values(PRIORITIES)) {
if (pi === parseInt(p)) {
return parseInt(p)
}
@ -199,55 +185,55 @@ const getRepeats = (text: string): repeatParsedResult => {
default:
amount = results[3] ? parseInt(results[3]) : 1
}
let type: RepeatType = RepeatType.Hours
let type: RepeatType = REPEAT_TYPES.Hours
switch (results[0]) {
case 'biennially':
type = RepeatType.Years
type = REPEAT_TYPES.Years
amount = 2
break
case 'bianually':
case 'semiannually':
type = RepeatType.Months
type = REPEAT_TYPES.Months
amount = 6
break
case 'yearly':
case 'anually':
type = RepeatType.Years
type = REPEAT_TYPES.Years
break
case 'daily':
type = RepeatType.Days
type = REPEAT_TYPES.Days
break
case 'hourly':
type = RepeatType.Hours
type = REPEAT_TYPES.Hours
break
case 'monthly':
type = RepeatType.Months
type = REPEAT_TYPES.Months
break
case 'weekly':
type = RepeatType.Weeks
type = REPEAT_TYPES.Weeks
break
default:
switch (results[5]) {
case 'hour':
case 'hours':
type = RepeatType.Hours
type = REPEAT_TYPES.Hours
break
case 'day':
case 'days':
type = RepeatType.Days
type = REPEAT_TYPES.Days
break
case 'week':
case 'weeks':
type = RepeatType.Weeks
type = REPEAT_TYPES.Weeks
break
case 'month':
case 'months':
type = RepeatType.Months
type = REPEAT_TYPES.Months
break
case 'year':
case 'years':
type = RepeatType.Years
type = REPEAT_TYPES.Years
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,
}