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

Commit

Permalink
feat: deleting achievements
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonHowe committed Jul 11, 2020
1 parent 0dfe5ad commit 0fa4083
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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("achievements")
.delete()
.where({ id });
};
14 changes: 12 additions & 2 deletions packages/api/src/modules/achievements/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import Router from "../Router";
import addAchievement from "./actions/addAchievement";
import { HttpError } from "../../common/error/classes/httpError";
import editAchievement from "./actions/editAchievement";
import { requireAdmin } from "../auth/middleware/requireAdmin";
import deleteAchievement from "./actions/deleteAchievement";

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

router.post("/addAchievement", async (ctx, next) => {
router.post("/addAchievement", requireAdmin(), async (ctx, next) => {
const { name, description, difficulty, requirements } = ctx.request.body;

await addAchievement({ name, description, difficulty, requirements });
Expand All @@ -16,7 +18,7 @@ router.post("/addAchievement", async (ctx, next) => {
await next();
});

router.patch("/editAchievement", async (ctx, next) => {
router.patch("/editAchievement", requireAdmin(), async (ctx, next) => {
const { id, details } = ctx.request.body;
const resp = await editAchievement(id, details);
if (!resp) {
Expand All @@ -27,4 +29,12 @@ router.patch("/editAchievement", async (ctx, next) => {
await next();
});

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

export default router.routes();

0 comments on commit 0fa4083

Please sign in to comment.