Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
feat: deleting texts
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonHowe committed Jul 15, 2020
1 parent 4021a1c commit 28c6244
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/api/src/modules/texts/actions/deleteText.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import knex from "../../../../db/knex";

export default async (id: number) => {
await knex("texts")
.delete()
.where({ id });
};
9 changes: 9 additions & 0 deletions packages/api/src/modules/texts/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import getAllTexts from "./actions/getAllTexts";
import getRandomText from "./actions/getRandomText";
import { addTextBody } from "./schema/addTextBody";
import { validateSchema } from "../schema/middleware/validateSchema";
import deleteText from "./actions/deleteText";

const router = new Router({ prefix: "/texts" });

Expand All @@ -24,6 +25,14 @@ router.post(
}
);

router.delete("/deleteText", requireAdmin(), async (ctx, next) => {
const { id } = ctx.request.body;
await deleteText(id);
ctx.status = 200;
ctx.body = { message: "Successfully deleted text" };
await next();
});

router.get("/getAllTexts", async (ctx, next) => {
const texts = await getAllTexts();
ctx.status = 200;
Expand Down

0 comments on commit 28c6244

Please sign in to comment.