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