update task/event

This commit is contained in:
CoGomu
2025-06-16 09:41:11 +02:00
parent c180739e94
commit daa147c009
3 changed files with 19 additions and 12 deletions

1
backend/.gitignore vendored
View File

@@ -1,3 +1,4 @@
node_modules node_modules
local.db local.db
drizzle drizzle
bun.lockb

View File

@@ -17,12 +17,11 @@ app.get('/', (req, res) => {
app.get('/tasks', async(req, res) => { app.get('/tasks', async(req, res) => {
const tasks = await db.select().from(task) const tasks = await db.select().from(task)
console.log(tasks) res.status(200).send(tasks);
res.send(tasks);
}); });
app.get('/events', async(req, res) => { 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) => { app.get('/user/:id', (req, res) => {
@@ -91,24 +90,30 @@ app.post('/event', async(req, res) => {
app.put('/task', (req, res) => { app.put('/task', (req, res) => {
const updatedTask = req.body; const id = parseInt(req.params['id']);
const updatedTask: Partial<typeof task.$inferSelect> = req.body
//Validate (having id) if (id == null) {
res.status(400).send({error: 'Needs an id'});
//const updatedTaskWithId = db.updateTask(updatedTask) return;
}
db.update(task).set(updatedTask).where(eq(task.id, id))
res.status(200).json(updatedTask); res.status(200).json(updatedTask);
}); });
app.put('/event', (req, res) => { app.put('/event', (req, res) => {
const updatedEvent = req.body;
//Validate (having id) const id = parseInt(req.params['id']);
const updatedEvent: Partial<typeof event.$inferSelect> = 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) => { app.delete('/task/:id', async(req, res) => {
const id = parseInt(req.params['id']); const id = parseInt(req.params['id']);

1
web/.gitignore vendored
View File

@@ -25,3 +25,4 @@ logs
# bun # bun
package-lock.json package-lock.json
bun.lockb