diff --git a/backend/src/db/schema.ts b/backend/src/db/schema.ts index 9893c07..6d577b0 100644 --- a/backend/src/db/schema.ts +++ b/backend/src/db/schema.ts @@ -2,7 +2,7 @@ import { sqliteTable, int, text } from 'drizzle-orm/sqlite-core' export const event = sqliteTable('event', { id: int().primaryKey({ autoIncrement: true }), - userid: text().notNull(), + userid: text().notNull(), title: text().notNull(), description: text().notNull(), from: text().notNull(), @@ -12,13 +12,13 @@ export const event = sqliteTable('event', { }) export const task = sqliteTable('task', { - id: int().primaryKey({ autoIncrement: true }), - userid: text().notNull(), + id: int().primaryKey({ autoIncrement: true }), + userid: text().notNull(), title: text().notNull(), description: text().notNull(), - done: int().notNull(), - estimated_time: int().notNull(), - due_date: text().notNull(), + done: int().notNull(), + estimated_time: int().notNull(), + due_date: text(), created_at: text().notNull().default(new Date().toISOString()), updated_at: text().notNull().default(new Date().toISOString()) }) diff --git a/backend/src/main.ts b/backend/src/main.ts index 5ca06e2..e14c445 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -23,6 +23,7 @@ app.get('/', (req, res) => { app.get('/tasks', async (req, res) => { const tasks: typeof task.$inferSelect[] = await db.select().from(task) + console.log(tasks) res.status(200).send(tasks.map(task => { return { ...task, done: task.done === 1 } })); @@ -78,6 +79,7 @@ app.post('/task', async(req, res) => { const newTask = req.body newTask.userid = userId + console.log(newTask) const returnedTask = await db.insert(task).values(newTask).returning() console.log(returnedTask) diff --git a/web/components/ui/Sidebar.vue b/web/components/ui/Sidebar.vue index dd3a118..f8f17fa 100644 --- a/web/components/ui/Sidebar.vue +++ b/web/components/ui/Sidebar.vue @@ -4,11 +4,13 @@ import ListItem from './ListItem.vue'; import Title1 from './Title1.vue'; import type { DropdownMenuItem } from '@nuxt/ui'; import { DateTime } from 'luxon'; -import type { USeparator } from '#components'; const colorMode = useColorMode(); +const toast = useToast() const currentTheme = ref<'dark' | 'system' | 'light'>(colorMode.preference as 'dark' | 'system' | 'light'); +const showTaskFormModal = ref(false); +const taskFormModalInput = ref>({}); const date = defineModel('date', { required: true }) const tasks = defineModel('tasks', { required: true }) @@ -76,19 +78,6 @@ const selectedDate = computed({ } }) -type Task = { - id: number - userid: string - title: string - description: string - done: boolean - estimated_time: string - due_date: string - created_at: string - updated_at: string -} - - function addTask() { const name = prompt("Todo name:") console.log(name) @@ -97,16 +86,30 @@ function addTask() { } } function deleteTask(todo: Task) { + if (todo.id === undefined) { + toast.add({ + title: "Task does not exist anymore" + }) + return + } + emits('deleteTask', todo.id) } function editTask(task: Task) { emits('editTask', task) } +function openTaskFormModal(task: Partial) { + taskFormModalInput.value = task + showTaskFormModal.value = true +} +