homeman-deno/models.ts

68 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-01-05 21:10:38 -06:00
import { z } from 'https://deno.land/x/zod@v3.21.4/mod.ts'
2024-01-07 02:24:36 -06:00
2024-01-05 21:10:38 -06:00
const User = z.object({
id: z.string().ulid().describe('primary'),
createdAt: z.date(),
name: z.string(),
2024-01-07 16:21:14 -06:00
avatarUrl: z.string(),
color: z.string(),
2024-01-05 21:10:38 -06:00
})
2024-01-07 10:55:18 -06:00
export const UserModel = User
2024-01-05 21:10:38 -06:00
export type User = z.infer<typeof User>
2024-01-07 02:24:36 -06:00
export type UserWithTodos = User & {
assignedTodos: Todo[]
}
2024-01-05 21:10:38 -06:00
const Todo = z.object({
id: z.string().ulid().describe('primary'),
createdAt: z.date(),
description: z.string(),
emoji: z.string().nullable(),
2024-01-05 13:22:56 -06:00
2024-01-05 21:10:38 -06:00
doneAt: z.date().nullable(),
assigneeUserId: z.string().ulid().nullable(),
})
2024-01-07 10:55:18 -06:00
export const TodoModel = Todo
2024-01-05 21:10:38 -06:00
export type Todo = z.infer<typeof Todo>
const DailyPhase = z.enum([
'Morning',
'Midday',
'Evening',
'Bedtime',
'Night',
])
export const DailyPhaseModel = DailyPhase
export type DailyPhase = z.infer<typeof DailyPhase>
export function toPhase(dt?: Date | null): z.infer<typeof DailyPhase> {
const d = dt || new Date()
const h = d.getHours()
2024-01-16 16:15:10 -06:00
if (h >= 6 && h < 12) {
return 'Morning'
} else if (h >= 12 && h < 17) {
return 'Midday'
} else if (h >= 17 && h < 19) {
return 'Evening'
} else if (h >= 19 && h < 23) {
return 'Bedtime'
}
2024-01-05 21:10:38 -06:00
// if (h >= 21 || h < 6) {
return 'Night'
// } else
}
2024-01-05 21:10:38 -06:00
const Task = z.object({
2024-01-21 14:02:10 -06:00
id: z.string(),
2024-01-21 14:23:45 -06:00
description: z.string(),
emoji: z.string().nullable(),
doneAt: z.date().nullable(),
phase: DailyPhase,
})
export const TaskModel = Task
export type Task = z.infer<typeof Task>