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

Commit

Permalink
feat: editing achievements
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonHowe committed Jul 11, 2020
1 parent ca1d6f2 commit 0dfe5ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Achievement from "../types/Achievement";
import knex from "../../../../db/knex";

export default async (id: number, details: Partial<Achievement>) => {
const achievement = await knex<Achievement>("achievements").where({ id });
if (!achievement) return null;
await knex<Achievement>("achievements").update(details);
return true;
};
15 changes: 14 additions & 1 deletion packages/api/src/modules/achievements/router.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import Router from "../Router";
import addAchievement from "./actions/addAchievement";
import { HttpError } from "../../common/error/classes/httpError";
import editAchievement from "./actions/editAchievement";

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

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

await addAchievement({ name, description, difficulty, requirements });

Expand All @@ -14,4 +16,15 @@ router.post("/addAchievement", async (ctx, next) => {
await next();
});

router.patch("/editAchievement", async (ctx, next) => {
const { id, details } = ctx.request.body;
const resp = await editAchievement(id, details);
if (!resp) {
throw new HttpError(400, "No achievement with that ID exists");
}
ctx.status = 200;
ctx.body = "Successfully edited achievement";
await next();
});

export default router.routes();

0 comments on commit 0dfe5ad

Please sign in to comment.