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

Commit

Permalink
feat: admin only all users route
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonHowe committed Jul 14, 2020
1 parent 4bd1c1b commit 305ead0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/api/src/modules/users/actions/getAllUsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import User from "../types/User";
import knex from "../../../../db/knex";

export default async () => {
const users = await knex<User>("users");
return users.map(l => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { password, ...data } = l;
return data;
});
};
8 changes: 8 additions & 0 deletions packages/api/src/modules/users/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@ import { registerBody } from "./schema/registerBody";
import { UpdateCountry } from "./schema/updateCountry";
import { RegisterBody } from "./types/RegisterBody";
import changePassword from "./actions/changePassword";
import { requireAdmin } from "../auth/middleware/requireAdmin";
import getAllUsers from "./actions/getAllUsers";

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

router.get("/", requireAdmin(), async (ctx, next) => {
ctx.status = 200;
ctx.body = await getAllUsers();
await next();
});

router.post(
"/createUser",
validateSchema(registerBody, "body"),
Expand Down

0 comments on commit 305ead0

Please sign in to comment.