tasks can be added to db
This commit is contained in:
@@ -10,3 +10,15 @@ export const event = sqliteTable('event', {
|
||||
created_at: text().notNull().default(new Date().toISOString()),
|
||||
updated_at: text().notNull().default(new Date().toISOString())
|
||||
})
|
||||
|
||||
export const task = sqliteTable('task', {
|
||||
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(),
|
||||
created_at: text().notNull().default(new Date().toISOString()),
|
||||
updated_at: text().notNull().default(new Date().toISOString())
|
||||
})
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import express from 'express'
|
||||
import cors from 'cors'
|
||||
import { drizzle } from 'drizzle-orm/libsql';
|
||||
import { event } from './db/schema';
|
||||
import { event, task } from './db/schema';
|
||||
import { eq, ne, gt, gte } from 'drizzle-orm';
|
||||
|
||||
const db = drizzle("file:local.db");
|
||||
const app = express();
|
||||
@@ -14,10 +15,10 @@ app.get('/', (req, res) => {
|
||||
res.send('Hello World');
|
||||
});
|
||||
|
||||
app.get('/tasks', (req, res) => {
|
||||
res.send(
|
||||
["Homework", "cleaning", "learn Arrow-functions"]
|
||||
);
|
||||
app.get('/tasks', async(req, res) => {
|
||||
const tasks = await db.select({ title: task.title }).from(task)
|
||||
const titles = tasks.map(t => t.title)
|
||||
res.send(titles);
|
||||
});
|
||||
|
||||
app.get('/events', async(req, res) => {
|
||||
@@ -63,15 +64,15 @@ app.get('/event/:id', (req, res) => {
|
||||
res.json(event);
|
||||
});
|
||||
|
||||
app.post('/task', (req, res) => {
|
||||
app.post('/task', async(req, res) => {
|
||||
|
||||
const newTask = req.body;
|
||||
const newTask = req.body
|
||||
newTask.userid = userId
|
||||
|
||||
//Validate
|
||||
const returnedTask = await db.insert(task).values(newTask).returning()
|
||||
console.log(returnedTask)
|
||||
|
||||
//const newTaskWithId = db.createEvent(newTask)
|
||||
|
||||
res.status(200).json(newTask);
|
||||
res.status(201).json(returnedTask);
|
||||
});
|
||||
|
||||
app.post('/event', async(req, res) => {
|
||||
@@ -83,11 +84,7 @@ app.post('/event', async(req, res) => {
|
||||
const returnedEvent = await db.insert(event).values(newEvent).returning()
|
||||
console.log(returnedEvent)
|
||||
|
||||
//Validate
|
||||
|
||||
//const newEventWithId = db.createEvent(newEvent)
|
||||
|
||||
res.status(201).json(newEvent);
|
||||
res.status(201).json(returnedEvent);
|
||||
});
|
||||
|
||||
app.put('/task', (req, res) => {
|
||||
@@ -111,17 +108,17 @@ app.put('/event', (req, res) => {
|
||||
res.status(200).json(updatedEvent);
|
||||
});
|
||||
|
||||
app.delete('/task/:id', (req, res) => {
|
||||
const id = req.params['id'];
|
||||
app.delete('/task/:id', async(req, res) => {
|
||||
const id = parseInt(req.params['id']);
|
||||
|
||||
//const success = db.deleteTask(id)
|
||||
const success = await db.delete(task).where(eq(task.id, id))
|
||||
res.send("Deleted");
|
||||
});
|
||||
|
||||
app.delete('/event', (req, res) => {
|
||||
const id = req.params['id'];
|
||||
app.delete('/event/:id', async(req, res) => {
|
||||
const id = parseInt(req.params['id']);
|
||||
|
||||
//const success = db.deleteEvent(id)
|
||||
const success = await db.delete(event).where(eq(event.id, id))
|
||||
res.send("Deleted");
|
||||
});
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@ watch(currentTheme, () => {
|
||||
colorMode.preference = currentTheme.value;
|
||||
})
|
||||
|
||||
const emits = defineEmits<{
|
||||
(e: 'createTask', name: string): void
|
||||
}>()
|
||||
|
||||
const dropDownItems = computed<DropdownMenuItem[][]>(() => [
|
||||
[
|
||||
{ label: "Profile", icon: "i-lucide-user" },
|
||||
@@ -73,6 +77,14 @@ defineProps<{
|
||||
todos: string[]
|
||||
}>()
|
||||
|
||||
function addTodo(){
|
||||
const name = prompt("Todo name:")
|
||||
console.log(name)
|
||||
if (name !== null) {
|
||||
emits('createTask', name)
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -90,7 +102,7 @@ defineProps<{
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<UButton size="xl" class="w-full flex justify-center">
|
||||
<UButton size="xl" class="w-full flex justify-center" @click="addTodo">
|
||||
+
|
||||
</UButton>
|
||||
</div>
|
||||
|
||||
@@ -30,15 +30,26 @@ const { data: tasks } = await useAsyncData<string[]>(
|
||||
)
|
||||
|
||||
async function postEvent(event: Event) {
|
||||
console.log('posting')
|
||||
console.log('posting Event')
|
||||
await axios.post('/event', event.toSerializable())
|
||||
}
|
||||
|
||||
async function postTask(name: string) {
|
||||
console.log('posting Task')
|
||||
await axios.post('/task', {
|
||||
title: name,
|
||||
description: "",
|
||||
done: false,
|
||||
estimated_time: (new Date()).toISOString(), //TODO
|
||||
due_date: (new Date()).toISOString(),
|
||||
})
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="h-screen w-screen p-4 flex flex-row gap-5">
|
||||
<Sidebar v-if="tasks !== null" :todos="tasks" v-model:date="date" />
|
||||
<Sidebar v-if="tasks !== null" :todos="tasks" v-model:date="date" @create-task="postTask"/>
|
||||
<MainContent v-if="events !== null" v-model:events="events" v-model:date="date" @create-event="postEvent"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user