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

Commit

Permalink
feat: added all tutorials route
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonHowe committed Jul 9, 2020
1 parent b5aff59 commit b044b91
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
7 changes: 7 additions & 0 deletions packages/api/src/modules/tutorials/actions/getAllTutorials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Tutorial } from "../types/Tutorial";
import knex from "../../../../db/knex";

export default async () => {
const tutorials = await knex<Tutorial>("texts").where({ tutorial: true });
return tutorials;
};

This file was deleted.

10 changes: 6 additions & 4 deletions packages/api/src/modules/tutorials/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { requireAuthenticated } from "../auth/middleware/requireAuthenticated";
import completeTutorial from "./actions/completeTutorial";
import { HttpError } from "../../common/error/classes/httpError";
import getTutorial from "./actions/getTutorial";
import getRandomTutorial from "./actions/getRandomTutorial";
import getAllTutorials from "./actions/getAllTutorials";

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

Expand All @@ -30,10 +30,12 @@ router.get("/:id", async (ctx, next) => {
await next();
});

router.get("/random", async (ctx, next) => {
const tutorial = getRandomTutorial();
router.get("/", async (ctx, next) => {
const tutorials = (await getAllTutorials()).sort(
(a, b) => a.difficulty - b.difficulty
);
ctx.status = 200;
ctx.body = tutorial;
ctx.body = tutorials;
await next();
});

Expand Down

0 comments on commit b044b91

Please sign in to comment.