You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
710 B
TypeScript
30 lines
710 B
TypeScript
import Router from "@koa/router";
|
|
import { Middlewares } from "sealious";
|
|
import { MainView } from "../common/main-view";
|
|
|
|
export const tasksRouter = (router: Router): void => {
|
|
router.post(
|
|
"/tasks",
|
|
Middlewares.extractContext(),
|
|
Middlewares.parseBody(),
|
|
async (ctx) => {
|
|
await ctx.$app.collections.tasks
|
|
.make({
|
|
title: ctx.$body.title as string,
|
|
done: false,
|
|
})
|
|
.save(ctx.$context);
|
|
ctx.body = MainView(ctx);
|
|
}
|
|
);
|
|
|
|
router.delete("/tasks/:task_id", Middlewares.extractContext(), async (ctx) => {
|
|
const task = await ctx.$app.collections.tasks.getByID(
|
|
ctx.$context,
|
|
ctx.params.task_id
|
|
);
|
|
await task.remove(ctx.$context);
|
|
ctx.body = MainView(ctx);
|
|
});
|
|
};
|