Skip to content

Commit

Permalink
fix(router): premier batch de la migration des routes
Browse files Browse the repository at this point in the history
  • Loading branch information
FaXaq committed Nov 25, 2024
1 parent f05039c commit 15d6294
Show file tree
Hide file tree
Showing 59 changed files with 321 additions and 186 deletions.
10 changes: 5 additions & 5 deletions server/src/modules/changelog/getChangelog/getChangelog.route.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { createRoute } from "@http-wizard/core";
import { API_ROUTES } from "shared/routes/index";
import { ROUTES } from "shared/routes/routes";

import type { Server } from "@/server/server";

import { getChangelog } from "./getChangelog.usecase";

const route = API_ROUTES.GET["/changelog"];
export const ROUTE = ROUTES["[GET]/changelog"];

export const getChangelogRoute = (server: Server) => {
return createRoute(route.path, {
method: route.method,
schema: route.schema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Changelog, ChangelogEntry } from "shared/routes/schemas/get.changelog.schema";

import config from "@/config";
import { getDatabaseRows } from "@/modules/core/services/notion/notion";

import type { Changelog, ChangelogEntry } from "./getChangelog.schema";

/**
* AUTO GENERATED TYPES
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { createRoute } from "@http-wizard/core";
import { API_ROUTES } from "shared/routes";
import { activateUserSchema } from "shared/routes/auth/schemas/post.auth.activate";
import { ROUTES } from "shared/routes/routes";

import type { Server } from "@/server/server";

import { activateUser } from "./activateUser.usecase";

const route = API_ROUTES["POST"]["/auth/activate"];
const ROUTE = ROUTES["[POST]/auth/activate"];

export const activateUserRoute = (server: Server) => {
return createRoute(route.path, {
method: route.method,
schema: activateUserSchema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { createRoute } from "@http-wizard/core";
import { API_ROUTES } from "shared/routes";
import { ROUTES } from "shared/routes/routes";

import type { Server } from "@/server/server";

import { checkActivationToken } from "./checkActivationToken.usecase";

const route = API_ROUTES.GET["/auth/check-activation-token"];
const ROUTE = ROUTES["[GET]/auth/check-activation-token"];

export const checkActivationTokenRoute = (server: Server) => {
return createRoute(route.path, {
method: route.method,
schema: route.schema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { createRoute } from "@http-wizard/core";
import { ROUTES } from "shared/routes/routes";

import { hasPermissionHandler } from "@/modules/core/utils/hasPermission";
import type { Server } from "@/server/server";

import { createCampagneSchema } from "./createCampagne.schema";
import { createCampagne } from "./createCampagne.usecase";

const ROUTE = ROUTES["[POST]/campagnes/:campagneId"];

export const createCampagneRoute = (server: Server) => {
return createRoute("/campagnes/:campagneId", {
method: "POST",
schema: createCampagneSchema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Boom from "@hapi/boom";
// eslint-disable-next-line import/no-extraneous-dependencies, n/no-extraneous-import
import { inject } from "injecti";
import { CampagneStatutEnum } from "shared/enum/campagneStatutEnum";
import type { BodySchema } from "shared/routes/schemas/post.campagnes.campagneId.schema";

import { getCampagneEnCours } from "@/modules/core/queries/getCampagneEnCours";
import { getSimilarCampagne } from "@/modules/core/queries/getSimilarCampagne";

import { insertCampagne } from "./createCampagne.query";
import type { BodySchema } from "./createCampagne.schema";

export const [createCampagne, createCampagneFactory] = inject(
{
Expand Down
10 changes: 6 additions & 4 deletions server/src/modules/core/usecases/createUser/createUser.route.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { createRoute } from "@http-wizard/core";
import { ROUTES } from "shared/routes/routes";

import { hasPermissionHandler } from "@/modules/core/utils/hasPermission";
import type { Server } from "@/server/server";

import { createUserSchema } from "./createUser.schema";
import { createUser } from "./createUser.usecase";

const ROUTE = ROUTES["[POST]/users/:userId"];

export const createUserRoute = (server: Server) => {
return createRoute("/users/:userId", {
method: "POST",
schema: createUserSchema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import Boom from "@hapi/boom";
import { inject } from "injecti";
import jwt from "jsonwebtoken";
import { emailRegex } from "shared";
import type { BodySchema } from "shared/routes/schemas/post.users.userId.schema";

import config from "@/config";
import type { RequestUser } from "@/modules/core/model/User";
import { shootTemplate } from "@/modules/core/services/mailer/mailer";

import type { BodySchema } from "./createUser.schema";
import { findUserQuery } from "./findUserQuery.dep";
import { insertUserQuery } from "./insertUserQuery.dep";
import { canCreateRole } from "./utils/canCreateRole";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BodySchema } from "shared/routes/schemas/post.users.userId.schema";

import type { RequestUser } from "@/modules/core/model/User";
import type { BodySchema } from "@/modules/core/usecases/createUser/createUser.schema";
import { getScopeFilterForUser } from "@/modules/core/utils/getScopeFilterForUser";

export function canCreateUserInScope({ body, requestUser }: { body: BodySchema; requestUser: RequestUser }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { createRoute } from "@http-wizard/core";
import { ROUTES } from "shared/routes/routes";

import { hasPermissionHandler } from "@/modules/core/utils/hasPermission";
import type { Server } from "@/server/server";

import { editCampagneSchema } from "./editCampagne.schema";
import { editCampagneUsecase } from "./editCampagne.usecase";

const ROUTE = ROUTES["[PUT]/campagnes/:campagneId"];

export const editCampagneRoute = (server: Server) => {
return createRoute("/campagnes/:campagneId", {
method: "PUT",
schema: editCampagneSchema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import Boom from "@hapi/boom";
// eslint-disable-next-line import/no-extraneous-dependencies, n/no-extraneous-import
import { inject } from "injecti";
import { CampagneStatutEnum } from "shared/enum/campagneStatutEnum";
import type { BodySchema } from "shared/routes/schemas/put.campagnes.campagneId.schema";

import { getCampagneEnCours } from "@/modules/core/queries/getCampagneEnCours";

import { updateCampagneQuery } from "./editCampagne.query";
import type { BodySchema } from "./editCampagne.schema";

export const [editCampagneUsecase] = inject(
{ updateCampagneQuery, getCampagneEnCours },
Expand Down
10 changes: 6 additions & 4 deletions server/src/modules/core/usecases/editUser/editUser.route.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { createRoute } from "@http-wizard/core";
import { ROUTES } from "shared/routes/routes";

import { hasPermissionHandler } from "@/modules/core/utils/hasPermission";
import type { Server } from "@/server/server";

import { editUserSchema } from "./editUser.schema";
import { editUser } from "./editUser.usecase";

const ROUTE = ROUTES["[PUT]/users/:userId"];

export const editUserRoute = (server: Server) => {
return createRoute("/users/:userId", {
method: "PUT",
schema: editUserSchema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Boom from "@hapi/boom";
// eslint-disable-next-line import/no-extraneous-dependencies, n/no-extraneous-import
import { inject } from "injecti";
import type { BodySchema } from "shared/routes/schemas/put.users.userId.schema";

import type { RequestUser } from "@/modules/core/model/User";

import type { BodySchema } from "./editUser.schema";
import { updateUser } from "./updateUser.dep";
import { canEditRole } from "./utils/canEditRole";
import { canEditUserInScope } from "./utils/canEditUserInScope";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BodySchema } from "shared/routes/schemas/put.users.userId.schema";

import type { RequestUser } from "@/modules/core/model/User";
import type { BodySchema } from "@/modules/core/usecases/editUser/editUser.schema";
import { getScopeFilterForUser } from "@/modules/core/utils/getScopeFilterForUser";

export function canEditUserInScope({ body, requestUser }: { body: BodySchema; requestUser: RequestUser }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { createRoute } from "@http-wizard/core";
import { ROUTES } from "shared/routes/routes";

import type { Server } from "@/server/server";

import { getMetabaseDashboardUrlSchema } from "./generateMetabaseDashboardUrl.schema";
import { getMetabaseDashboardUrl } from "./generateMetabaseDashboardUrl.usecase";

const ROUTE = ROUTES["[POST]/generate-metabase-dashboard-url"];

export const generateMetabaseDashboardUrlRoute = (server: Server) => {
return createRoute("/generate-metabase-dashboard-url", {
method: "POST",
schema: getMetabaseDashboardUrlSchema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { createRoute } from "@http-wizard/core";
import { ROUTES } from "shared/routes/routes";

import { hasPermissionHandler } from "@/modules/core/utils/hasPermission";
import type { Server } from "@/server/server";

import { getCampagnes } from "./getCampagnes.query";
import { getCampagnesSchema } from "./getCampagnes.schema";

const ROUTE = ROUTES["[GET]/campagnes"];

export const getCampagnesRoute = (server: Server) => {
return createRoute("/campagnes", {
method: "GET",
schema: getCampagnesSchema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
10 changes: 6 additions & 4 deletions server/src/modules/core/usecases/getDneUrl/getDneUrl.route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { createRoute } from "@http-wizard/core";
import { ROUTES } from "shared/routes/routes";

import type { Server } from "@/server/server";

import { getDneUrlSchema } from "./getDneUrl.schema";
import { getDneUrl } from "./getDneUrl.usecase";

const ROUTE = ROUTES["[GET]/dne_url"];

export const getDneAuthorizationUrlRoute = (server: Server) => {
return createRoute("/dne_url", {
method: "GET",
schema: getDneUrlSchema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
10 changes: 6 additions & 4 deletions server/src/modules/core/usecases/getUsers/getUsers.route.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { createRoute } from "@http-wizard/core";
import { ROUTES } from "shared/routes/routes";

import { getScopeFilterForUser } from "@/modules/core/utils/getScopeFilterForUser";
import { hasPermissionHandler } from "@/modules/core/utils/hasPermission";
import type { Server } from "@/server/server";

import { getUsersSchema } from "./getUsers.schema";
import { getUsers } from "./getUsers.usecase";

const ROUTE = ROUTES["[GET]/users"];

export const getUsersRoute = (server: Server) => {
return createRoute("/users", {
method: "GET",
schema: getUsersSchema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
18 changes: 6 additions & 12 deletions server/src/modules/core/usecases/home/home.route.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { createRoute } from "@http-wizard/core";
import { z } from "zod";
import { ROUTES } from "shared/routes/routes";

import config from "@/config";
import type { Server } from "@/server/server";

const ROUTE = ROUTES["[GET]/healthcheck"];

export const homeRoute = (server: Server) => {
return createRoute("/healthcheck", {
method: "GET",
schema: {
response: {
200: z.object({
name: z.string(),
version: z.string(),
env: z.enum(["local", "recette", "recette1new", "recette2", "production", "preproduction", "test"]),
}),
},
},
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { createRoute } from "@http-wizard/core";
import { ROUTES } from "shared/routes/routes";

import type { Server } from "@/server/server";

import { isMaintenanceSchema } from "./isMaintenance.schema";
import { isMaintenanceUsecase } from "./isMaintenance.usecase";

const ROUTE = ROUTES["[GET]/maintenance"];

export const isMaintenanceRoute = (server: Server) => {
return createRoute("/maintenance", {
method: "GET",
schema: isMaintenanceSchema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
10 changes: 6 additions & 4 deletions server/src/modules/core/usecases/login/login.route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { createRoute } from "@http-wizard/core";
import { ROUTES } from "shared/routes/routes";

import type { Server } from "@/server/server";

import { loginSchema } from "./login.schema";
import { login } from "./login.usecase";

const ROUTE = ROUTES["[POST]/auth/login"];

export const loginRoute = (server: Server) => {
return createRoute("/auth/login", {
method: "POST",
schema: loginSchema,
return createRoute(ROUTE.url, {
method: ROUTE.method,
schema: ROUTE.schema,
}).handle((props) => {
server.route({
...props,
Expand Down
Loading

0 comments on commit 15d6294

Please sign in to comment.