import { z } from 'zod';
// TypeScript interface for Task
export interface Task {
id?: string;
title: string;
description?: string;
status: 'todo' | 'in_progress' | 'completed';
priority: 'low' | 'medium' | 'high';
due_date?: string;
created_at?: string;
updated_at?: string;
user_created?: string;
user_updated?: string;
}
// Zod schema for validation
export const TaskSchema = z.object({
id: z.string().uuid().optional(),
title: z.string().min(1, 'Title is required').max(255),
description: z.string().optional(),
status: z.enum(['todo', 'in_progress', 'completed']).default('todo'),
priority: z.enum(['low', 'medium', 'high']).default('medium'),
due_date: z.string().datetime().optional(),
created_at: z.string().datetime().optional(),
updated_at: z.string().datetime().optional(),
user_created: z.string().uuid().optional(),
user_updated: z.string().uuid().optional(),
});
// Schema for creating a new task (without system fields)
export const CreateTaskSchema = TaskSchema.omit({
id: true,
created_at: true,
updated_at: true,
user_created: true,
user_updated: true,
});
// Schema for updating a task
export const UpdateTaskSchema = CreateTaskSchema.partial();
// Directus field definitions for the tasks collection (Schema API format)
export const TaskFieldDefinitions = [
{
field: 'id',
type: 'uuid',
special: ['uuid'],
interface: 'input',
hidden: true,
readonly: true,
width: 'full',
schema: {
name: 'id',
table: 'tasks',
data_type: 'uuid',
is_primary_key: true,
has_auto_increment: false,
is_nullable: false,
is_unique: true,
is_generated: false,
},
},
{
field: 'title',
type: 'string',
interface: 'input',
display: 'raw',
readonly: false,
hidden: false,
width: 'full',
required: true,
options: {
placeholder: 'Enter task title...',
},
schema: {
name: 'title',
table: 'tasks',
data_type: 'varchar',
is_nullable: false,
max_length: 255,
is_unique: false,
is_primary_key: false,
is_generated: false,
has_auto_increment: false,
},
},
{
field: 'description',
type: 'text',
meta: {
interface: 'input-multiline',
display: 'raw',
readonly: false,
hidden: false,
width: 'full',
options: {
placeholder: 'Enter task description...',
},
},
schema: {
is_nullable: true,
},
},
{
field: 'status',
type: 'string',
meta: {
interface: 'select-dropdown',
display: 'labels',
readonly: false,
hidden: false,
width: 'half',
options: {
choices: [
{ text: 'To Do', value: 'todo' },
{ text: 'In Progress', value: 'in_progress' },
{ text: 'Completed', value: 'completed' },
],
},
display_options: {
choices: [
{ text: 'To Do', value: 'todo', foreground: '#6644FF', background: '#6644FF1A' },
{ text: 'In Progress', value: 'in_progress', foreground: '#FF6644', background: '#FF66441A' },
{ text: 'Completed', value: 'completed', foreground: '#44FF66', background: '#44FF661A' },
],
},
},
schema: {
is_nullable: false,
default_value: 'todo',
},
},
{
field: 'priority',
type: 'string',
meta: {
interface: 'select-dropdown',
display: 'labels',
readonly: false,
hidden: false,
width: 'half',
options: {
choices: [
{ text: 'Low', value: 'low' },
{ text: 'Medium', value: 'medium' },
{ text: 'High', value: 'high' },
],
},
display_options: {
choices: [
{ text: 'Low', value: 'low', foreground: '#44FF66', background: '#44FF661A' },
{ text: 'Medium', value: 'medium', foreground: '#FFAA44', background: '#FFAA441A' },
{ text: 'High', value: 'high', foreground: '#FF4444', background: '#FF44441A' },
],
},
},
schema: {
is_nullable: false,
default_value: 'medium',
},
},
{
field: 'due_date',
type: 'timestamp',
meta: {
interface: 'datetime',
display: 'datetime',
readonly: false,
hidden: false,
width: 'half',
options: {
includeSeconds: false,
},
},
schema: {
is_nullable: true,
},
},
{
field: 'created_at',
type: 'timestamp',
meta: {
interface: 'datetime',
display: 'datetime',
readonly: true,
hidden: true,
width: 'half',
special: ['date-created'],
},
schema: {
is_nullable: false,
},
},
{
field: 'updated_at',
type: 'timestamp',
meta: {
interface: 'datetime',
display: 'datetime',
readonly: true,
hidden: true,
width: 'half',
special: ['date-updated'],
},
schema: {
is_nullable: false,
},
},
{
field: 'user_created',
type: 'uuid',
meta: {
interface: 'select-dropdown-m2o',
display: 'user',
readonly: true,
hidden: true,
width: 'half',
special: ['user-created'],
},
schema: {
is_nullable: true,
},
},
{
field: 'user_updated',
type: 'uuid',
meta: {
interface: 'select-dropdown-m2o',
display: 'user',
readonly: true,
hidden: true,
width: 'half',
special: ['user-updated'],
},
schema: {
is_nullable: true,
},
},
];
export type CreateTaskInput = z.infer<typeof CreateTaskSchema>;
export type UpdateTaskInput = z.infer<typeof UpdateTaskSchema>;