initial commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import type { Medium } from '../types/review'
|
||||
|
||||
export const MEDIUMS: Record<Medium, { label: string, creator: string }> = {
|
||||
book: { label: 'Book', creator: 'Author' },
|
||||
movie: { label: 'Movie', creator: 'Director' },
|
||||
album: { label: 'Album', creator: 'Artist' }
|
||||
}
|
||||
|
||||
export const MEDIUM_KEYS = Object.keys(MEDIUMS) as [Medium, ...Medium[]]
|
||||
@@ -0,0 +1,25 @@
|
||||
import { z } from 'zod'
|
||||
import { MEDIUM_KEYS } from './medium'
|
||||
|
||||
const isoDate = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'Pick a date')
|
||||
const requiredText = z.string().trim().min(1, 'Write something first')
|
||||
|
||||
export const newNoteSchema = z.object({
|
||||
date: isoDate,
|
||||
text: requiredText
|
||||
})
|
||||
|
||||
export const newReviewSchema = z.object({
|
||||
medium: z.enum(MEDIUM_KEYS, { error: 'Pick a medium' }),
|
||||
date: isoDate,
|
||||
title: z.string().trim().min(1, 'Add a title'),
|
||||
author: z.string().trim().optional(),
|
||||
text: requiredText
|
||||
})
|
||||
|
||||
export const loginSchema = z.object({
|
||||
password: z.string().min(1)
|
||||
})
|
||||
|
||||
export type NewNoteInput = z.output<typeof newNoteSchema>
|
||||
export type NewReviewInput = z.output<typeof newReviewSchema>
|
||||
Reference in New Issue
Block a user