Skip to content

Commit

Permalink
feat(api): update api contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
harrytran998 committed Jul 2, 2024
1 parent 372b5fa commit 60709a3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { HonoEnv } from "@techmely/hono";
import {} from "@techmely/http";
import type { MiddlewareHandler } from "hono";
import { UserIsNotAdminException } from "../../../domain/user.exceptions";
import type { HonoEnv } from "#root/libs/hono/hono.types";

export const adminGuard = (): MiddlewareHandler<HonoEnv> => {
return async (c, next) => {
const config = c.get("config");
const firebaseUser = c.get("firebaseUser");
if (!config.admin.authIds.includes(firebaseUser.sub)) {
if (!firebaseUser || !config.admin.authIds.includes(firebaseUser.sub)) {
throw new UserIsNotAdminException();
}
await next();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vValidator } from "@techmely/hono";
import { vValidator } from "@starly/models";
import { Hono } from "hono";
import type { HonoEnv } from "#root/libs/hono/hono.types";
import { signInSchema, signUpSchema } from "../../../domain/user.schema";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { vValidator } from "@techmely/hono";
import type { BaseResponse } from "@techmely/models";
import { vValidator } from "@starly/models";
import type { BaseResponse } from "@starly/models";
import { Hono } from "hono";
import type { HonoEnv } from "#root/libs/hono/hono.types";
import { createUserSchema } from "../../../domain/user.schema";
Expand Down
10 changes: 8 additions & 2 deletions apps/api/contexts/identify-access/user/infras/user.injection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { pgDatabase } from "#root/libs/db/pg.db";

export const userMapper = new UserMapper();
const userRepo = new UserPgRepository(pgDatabase);
const createUserUseCases = new CreateUserInteractor(userRepo, userMapper);
const userService = new UserService(createUserUseCases);
const createUserUseCase = new CreateUserInteractor(userRepo, userMapper);
const findUserByAuthIdUseCase = new FindUserByAuthIdInteractor(userRepo, userMapper);
const findUserByKeyUseCase = new FindUserByKeyInteractor(userRepo, userMapper);
const userService = new UserService(
createUserUseCase,
findUserByAuthIdUseCase,
findUserByKeyUseCase,
);

export default userService;

0 comments on commit 60709a3

Please sign in to comment.