Skip to content

Commit

Permalink
declare createUserForAgency usecase + use it in route
Browse files Browse the repository at this point in the history
  • Loading branch information
celineung authored and clement-duport committed Sep 4, 2024
1 parent 90d3ebf commit e825420
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
13 changes: 6 additions & 7 deletions back/src/adapters/primary/routers/admin/createAdminRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Router } from "express";
import { GetDashboardParams, adminRoutes, agencyRoutes } from "shared";
import { GetDashboardParams, adminRoutes, agencyRoutes, errors } from "shared";
import { BadRequestError } from "shared";
import { createExpressSharedRouter } from "shared-routes/express";
import type { AppDependencies } from "../../../../config/bootstrap/createAppDependencies";
Expand Down Expand Up @@ -85,12 +85,11 @@ export const createAdminRouter = (deps: AppDependencies): Router => {
sharedAdminRouter.addUserForAgency(
deps.inclusionConnectAuthMiddleware,
(req, res) =>
sendHttpResponse(req, res.status(201), () =>
deps.useCases.updateUserForAgency.execute(
req.body,
req.payloads?.currentUser,
),
),
sendHttpResponse(req, res.status(201), async () => {
const currentUser = req.payloads?.currentUser;
if (!currentUser) throw errors.user.unauthorized();
await deps.useCases.createUserForAgency.execute(req.body, currentUser);
}),
);

sharedAdminRouter.rejectIcUserForAgency(
Expand Down
7 changes: 7 additions & 0 deletions back/src/config/bootstrap/createUseCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ import { SendExchangeToRecipient } from "../../domains/establishment/use-cases/d
import { NotifyConfirmationEstablishmentCreated } from "../../domains/establishment/use-cases/notifications/NotifyConfirmationEstablishmentCreated";
import { NotifyContactRequest } from "../../domains/establishment/use-cases/notifications/NotifyContactRequest";
import { NotifyPassEmploiOnNewEstablishmentAggregateInsertedFromForm } from "../../domains/establishment/use-cases/notifications/NotifyPassEmploiOnNewEstablishmentAggregateInsertedFromForm";
import { makeCreateUserForAgency } from "../../domains/inclusion-connected-users/use-cases/CreateUserForAgency";
import { GetInclusionConnectedUser } from "../../domains/inclusion-connected-users/use-cases/GetInclusionConnectedUser";
import { GetInclusionConnectedUsers } from "../../domains/inclusion-connected-users/use-cases/GetInclusionConnectedUsers";
import { LinkFranceTravailUsersToTheirAgencies } from "../../domains/inclusion-connected-users/use-cases/LinkFranceTravailUsersToTheirAgencies";
Expand Down Expand Up @@ -631,6 +632,12 @@ export const createUseCases = (
listActiveSubscriptions: makeListActiveSubscriptions({
uowPerformer,
}),
createUserForAgency: makeCreateUserForAgency({
uowPerformer,
deps: {
timeGateway: gateways.timeGateway,
},
}),
broadcastConventionAgain: makeBroadcastConventionAgain({
uowPerformer,
deps: { createNewEvent, timeGateway: gateways.timeGateway },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from "shared";
import { createTransactionalUseCase } from "../../core/UseCase";
import { TimeGateway } from "../../core/time-gateway/ports/TimeGateway";
import { UuidGenerator } from "../../core/uuid-generator/ports/UuidGenerator";
import { throwIfNotAdmin } from "../helpers/throwIfIcUserNotBackofficeAdmin";

export type CreateUserForAgency = ReturnType<typeof makeCreateUserForAgency>;
Expand All @@ -16,7 +15,7 @@ export const makeCreateUserForAgency = createTransactionalUseCase<
UserCreateParamsForAgency,
void,
InclusionConnectedUser,
{ timeGateway: TimeGateway; uuidGenerator: UuidGenerator }
{ timeGateway: TimeGateway }
>(
{
name: "CreateUserForAgency",
Expand Down
3 changes: 2 additions & 1 deletion shared/src/admin/admin.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { notificationsByKindSchema } from "../notifications/notifications.schema
import { expressEmptyResponseBody } from "../zodUtils";
import {
rejectIcUserRoleForAgencyParamsSchema,
userCreateParamsForAgencySchema,
userUpdateParamsForAgencySchema,
withUserFiltersSchema,
} from "./admin.schema";
Expand Down Expand Up @@ -63,7 +64,7 @@ export const adminRoutes = defineRoutes({
addUserForAgency: defineRoute({
method: "post",
url: "/admin/inclusion-connected/users",
requestBodySchema: userUpdateParamsForAgencySchema,
requestBodySchema: userCreateParamsForAgencySchema,
...withAuthorizationHeaders,
responses: {
201: expressEmptyResponseBody,
Expand Down

0 comments on commit e825420

Please sign in to comment.