backend returns done with boolean type instead of number
This commit is contained in:
@@ -8,6 +8,12 @@ const db = drizzle("file:local.db");
|
|||||||
const app = express();
|
const app = express();
|
||||||
const userId = "Detlef";
|
const userId = "Detlef";
|
||||||
|
|
||||||
|
type Prettify<T> = {
|
||||||
|
[K in keyof T]: T[K];
|
||||||
|
} & {};
|
||||||
|
|
||||||
|
type TaskResponse = Prettify<Omit<typeof task.$inferSelect, 'done'> & { done: boolean }>
|
||||||
|
|
||||||
app.use(cors())
|
app.use(cors())
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
@@ -15,13 +21,14 @@ app.get('/', (req, res) => {
|
|||||||
res.send('Hello World');
|
res.send('Hello World');
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/tasks', async(req, res) => {
|
app.get('/tasks', async (req, res) => {
|
||||||
const tasks = await db.select().from(task)
|
const tasks: typeof task.$inferSelect[] = await db.select().from(task)
|
||||||
console.log(tasks)
|
res.send(tasks.map<TaskResponse>(task => {
|
||||||
res.send(tasks);
|
return { ...task, done: task.done === 1 }
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/events', async(req, res) => {
|
app.get('/events', async (req, res) => {
|
||||||
res.send(await db.select().from(event))
|
res.send(await db.select().from(event))
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -29,21 +36,21 @@ app.get('/user/:id', (req, res) => {
|
|||||||
const id = req.params['id'];
|
const id = req.params['id'];
|
||||||
|
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
res.status(400).send({error: 'Needs an user id'});
|
res.status(400).send({ error: 'Needs an user id' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = {id: id, name: 'Cracker'} //TODO
|
const user = { id: id, name: 'Cracker' } //TODO
|
||||||
res.json(user);
|
res.json(user);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/task/:id', async(req, res) => {
|
app.get('/task/:id', async (req, res) => {
|
||||||
|
|
||||||
const id = parseInt(req.params['id']);
|
const id = parseInt(req.params['id']);
|
||||||
|
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
res.status(400).send({error: 'Needs an id'});
|
res.status(400).send({ error: 'Needs an id' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,15 +65,15 @@ app.get('/event/:id', (req, res) => {
|
|||||||
const id = req.params['id'];
|
const id = req.params['id'];
|
||||||
|
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
res.status(400).send({error: 'Needs an id'});
|
res.status(400).send({ error: 'Needs an id' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const event = {id: id, name: 'Pary'} //TODO
|
const event = { id: id, name: 'Pary' } //TODO
|
||||||
res.json(event);
|
res.json(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/task', async(req, res) => {
|
app.post('/task', async (req, res) => {
|
||||||
|
|
||||||
const newTask = req.body
|
const newTask = req.body
|
||||||
newTask.userid = userId
|
newTask.userid = userId
|
||||||
@@ -77,7 +84,7 @@ app.post('/task', async(req, res) => {
|
|||||||
res.status(201).json(returnedTask);
|
res.status(201).json(returnedTask);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/event', async(req, res) => {
|
app.post('/event', async (req, res) => {
|
||||||
|
|
||||||
const newEvent: typeof event.$inferInsert = req.body
|
const newEvent: typeof event.$inferInsert = req.body
|
||||||
newEvent.description = ""
|
newEvent.description = ""
|
||||||
@@ -110,14 +117,14 @@ app.put('/event', (req, res) => {
|
|||||||
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']);
|
||||||
|
|
||||||
const success = await db.delete(task).where(eq(task.id, id))
|
const success = await db.delete(task).where(eq(task.id, id))
|
||||||
res.send("Deleted");
|
res.send("Deleted");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.delete('/event/:id', async(req, res) => {
|
app.delete('/event/:id', async (req, res) => {
|
||||||
const id = parseInt(req.params['id']);
|
const id = parseInt(req.params['id']);
|
||||||
|
|
||||||
const success = await db.delete(event).where(eq(event.id, id))
|
const success = await db.delete(event).where(eq(event.id, id))
|
||||||
|
|||||||
Reference in New Issue
Block a user