diff --git a/backend/.gitignore b/backend/.gitignore index 79962e2..46f8d64 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,3 +1,4 @@ node_modules local.db drizzle +bun.lockb diff --git a/backend/src/main.ts b/backend/src/main.ts index 3356dbe..5090dae 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -17,12 +17,11 @@ app.get('/', (req, res) => { app.get('/tasks', async(req, res) => { const tasks = await db.select().from(task) - console.log(tasks) - res.send(tasks); + res.status(200).send(tasks); }); app.get('/events', async(req, res) => { - res.send(await db.select().from(event)) + res.status(200).send(await db.select().from(event)) }); app.get('/user/:id', (req, res) => { @@ -80,7 +79,6 @@ app.post('/task', async(req, res) => { app.post('/event', async(req, res) => { const newEvent: typeof event.$inferInsert = req.body - newEvent.description = "" newEvent.userid = userId const returnedEvent = await db.insert(event).values(newEvent).returning() @@ -91,24 +89,30 @@ app.post('/event', async(req, res) => { app.put('/task', (req, res) => { - const updatedTask = req.body; + const id = parseInt(req.params['id']); + const updatedTask: Partial = req.body - //Validate (having id) - - //const updatedTaskWithId = db.updateTask(updatedTask) + if (id == null) { + res.status(400).send({error: 'Needs an id'}); + return; + } + db.update(task).set(updatedTask).where(eq(task.id, id)) res.status(200).json(updatedTask); }); app.put('/event', (req, res) => { - const updatedEvent = req.body; - //Validate (having id) + const id = parseInt(req.params['id']); + const updatedEvent: Partial = req.body - //const updatedEventWithId = db.updateEvent(updatedEvent) + if (id == null) { + res.status(400).send({error: 'Needs an id'}); + return; + } + db.update(event).set(updatedEvent).where(eq(event.id, id)) - res.status(200).json(updatedEvent); -}); + res.status(200).json(updatedEvent);}); app.delete('/task/:id', async(req, res) => { const id = parseInt(req.params['id']); diff --git a/web/.gitignore b/web/.gitignore index 7d4644f..bfbca18 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -25,3 +25,4 @@ logs # bun package-lock.json +bun.lockb