Skip to content

Commit

Permalink
refacto: rename variables and types
Browse files Browse the repository at this point in the history
  • Loading branch information
celineung committed Sep 17, 2024
1 parent 2ac352b commit 047a5a1
Show file tree
Hide file tree
Showing 37 changed files with 1,133 additions and 1,071 deletions.
4 changes: 2 additions & 2 deletions back/src/config/bootstrap/inclusionConnectAuthMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextFunction, Request, Response } from "express";
import { errors, inclusionConnectTokenExpiredMessage } from "shared";
import { oAuthModeByFeatureFlags } from "../../domains/core/authentication/inclusion-connect/port/OAuthGateway";
import { oAuthProviderByFeatureFlags } from "../../domains/core/authentication/inclusion-connect/port/OAuthGateway";
import { makeVerifyJwtES256 } from "../../domains/core/jwt";
import { UnitOfWorkPerformer } from "../../domains/core/unit-of-work/ports/UnitOfWorkPerformer";

Expand All @@ -25,7 +25,7 @@ export const makeInclusionConnectAuthMiddleware = (
const currentIcUser = await uowPerformer.perform(async (uow) =>
uow.userRepository.getById(
payload.userId,
oAuthModeByFeatureFlags(await uow.featureFlagRepository.getAll()),
oAuthProviderByFeatureFlags(await uow.featureFlagRepository.getAll()),
),
);
if (!currentIcUser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
errors,
} from "shared";
import { TransactionalUseCase } from "../../core/UseCase";
import { oAuthModeByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { oAuthProviderByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { CreateNewEvent } from "../../core/events/ports/EventBus";
import { UnitOfWork } from "../../core/unit-of-work/ports/UnitOfWork";
import { UnitOfWorkPerformer } from "../../core/unit-of-work/ports/UnitOfWorkPerformer";
Expand Down Expand Up @@ -36,7 +36,7 @@ export class RegisterAgencyToInclusionConnectUser extends TransactionalUseCase<

const user = await uow.userRepository.getById(
inclusionConnectedPayload.userId,
oAuthModeByFeatureFlags(await uow.featureFlagRepository.getAll()),
oAuthProviderByFeatureFlags(await uow.featureFlagRepository.getAll()),
);

if (!user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
withConventionIdSchema,
} from "shared";
import { createTransactionalUseCase } from "../../core/UseCase";
import { oAuthModeByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { oAuthProviderByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";

export type GetApiConsumersByConvention = ReturnType<
typeof makeGetApiConsumersByConvention
Expand All @@ -33,7 +33,7 @@ export const makeGetApiConsumersByConvention = createTransactionalUseCase<

const user = await uow.userRepository.getById(
currentUser.id,
oAuthModeByFeatureFlags(await uow.featureFlagRepository.getAll()),
oAuthProviderByFeatureFlags(await uow.featureFlagRepository.getAll()),
);

if (!user)
Expand Down
22 changes: 11 additions & 11 deletions back/src/domains/convention/use-cases/GetConvention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ConventionReadDto,
ConventionRelatedJwtPayload,
InclusionConnectJwtPayload,
OAuthProvider,
OAuthGatewayProvider,
WithConventionId,
getIcUserRoleForAccessingConvention,
stringToMd5,
Expand All @@ -15,7 +15,7 @@ import {
import { ForbiddenError, NotFoundError } from "shared";
import { conventionEmailsByRole } from "../../../utils/convention";
import { TransactionalUseCase } from "../../core/UseCase";
import { oAuthModeByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { oAuthProviderByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { UserRepository } from "../../core/authentication/inclusion-connect/port/UserRepository";
import { UnitOfWork } from "../../core/unit-of-work/ports/UnitOfWork";

Expand Down Expand Up @@ -46,7 +46,7 @@ export class GetConvention extends TransactionalUseCase<
conventionId,
);

const mode = oAuthModeByFeatureFlags(
const provider = oAuthProviderByFeatureFlags(
await uow.featureFlagRepository.getAll(),
);

Expand All @@ -55,7 +55,7 @@ export class GetConvention extends TransactionalUseCase<
authPayload,
uow,
convention,
provider: mode,
provider: provider,
});
}

Expand All @@ -64,7 +64,7 @@ export class GetConvention extends TransactionalUseCase<
authPayload,
uow,
convention,
mode,
provider: provider,
});
}

Expand All @@ -80,7 +80,7 @@ export class GetConvention extends TransactionalUseCase<
authPayload: ConventionDomainPayload;
convention: ConventionReadDto;
uow: UnitOfWork;
provider: OAuthProvider;
provider: OAuthGatewayProvider;
}): Promise<ConventionReadDto> {
const agency = await uow.agencyRepository.getById(convention.agencyId);
if (!agency) {
Expand All @@ -106,14 +106,14 @@ export class GetConvention extends TransactionalUseCase<
authPayload,
convention,
uow,
mode,
provider,
}: {
authPayload: InclusionConnectJwtPayload;
convention: ConventionReadDto;
uow: UnitOfWork;
mode: OAuthProvider;
provider: OAuthGatewayProvider;
}): Promise<ConventionReadDto> {
const user = await uow.userRepository.getById(authPayload.userId, mode);
const user = await uow.userRepository.getById(authPayload.userId, provider);
if (!user)
throw new NotFoundError(`No user found with id '${authPayload.userId}'`);

Expand Down Expand Up @@ -150,7 +150,7 @@ export class GetConvention extends TransactionalUseCase<
convention: ConventionReadDto;
agency: AgencyDto;
userRepository: UserRepository;
provider: OAuthProvider;
provider: OAuthGatewayProvider;
}): Promise<boolean> {
const emailsByRole = conventionEmailsByRole(convention, agency)[
authPayload.role
Expand Down Expand Up @@ -188,7 +188,7 @@ export class GetConvention extends TransactionalUseCase<
authPayload: ConventionDomainPayload;
userRepository: UserRepository;
agencyId: AgencyId;
provider: OAuthProvider;
provider: OAuthGatewayProvider;
}) {
if (authPayload.role !== "counsellor" && authPayload.role !== "validator")
return false;
Expand Down
4 changes: 2 additions & 2 deletions back/src/domains/convention/use-cases/RenewConvention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "shared";
import { BadRequestError, ForbiddenError, NotFoundError } from "shared";
import { TransactionalUseCase } from "../../core/UseCase";
import { oAuthModeByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { oAuthProviderByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { UnitOfWork } from "../../core/unit-of-work/ports/UnitOfWork";
import { UnitOfWorkPerformer } from "../../core/unit-of-work/ports/UnitOfWorkPerformer";
import { AddConvention } from "./AddConvention";
Expand Down Expand Up @@ -95,7 +95,7 @@ export class RenewConvention extends TransactionalUseCase<

const inclusionConnectedUser = await uow.userRepository.getById(
jwtPayload.userId,
oAuthModeByFeatureFlags(await uow.featureFlagRepository.getAll()),
oAuthProviderByFeatureFlags(await uow.featureFlagRepository.getAll()),
);
if (!inclusionConnectedUser)
throw new NotFoundError(
Expand Down
4 changes: 2 additions & 2 deletions back/src/domains/convention/use-cases/SignConvention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "shared";
import { ForbiddenError, NotFoundError } from "shared";
import { TransactionalUseCase } from "../../core/UseCase";
import { oAuthModeByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { oAuthProviderByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { DomainTopic } from "../../core/events/events";
import { CreateNewEvent } from "../../core/events/ports/EventBus";
import { TimeGateway } from "../../core/time-gateway/ports/TimeGateway";
Expand Down Expand Up @@ -113,7 +113,7 @@ export class SignConvention extends TransactionalUseCase<
return { role: jwtPayload.role, icUser: undefined };
const icUser = await uow.userRepository.getById(
jwtPayload.userId,
oAuthModeByFeatureFlags(await uow.featureFlagRepository.getAll()),
oAuthProviderByFeatureFlags(await uow.featureFlagRepository.getAll()),
);
if (!icUser)
throw new NotFoundError(`No user found with id '${jwtPayload.userId}'`);
Expand Down
22 changes: 11 additions & 11 deletions back/src/domains/convention/use-cases/UpdateConventionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ConventionStatus,
Email,
InclusionConnectedUser,
OAuthProvider,
OAuthGatewayProvider,
Role,
UpdateConventionStatusRequestDto,
UserId,
Expand All @@ -20,7 +20,7 @@ import {
validatedConventionStatuses,
} from "shared";
import { TransactionalUseCase } from "../../core/UseCase";
import { oAuthModeByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { oAuthProviderByFeatureFlags } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { ConventionRequiresModificationPayload } from "../../core/events/eventPayload.dto";
import {
DomainTopic,
Expand Down Expand Up @@ -85,14 +85,14 @@ export class UpdateConventionStatus extends TransactionalUseCase<
agencyId: conventionRead.agencyId,
});

const mode = oAuthModeByFeatureFlags(
const provider = oAuthProviderByFeatureFlags(
await uow.featureFlagRepository.getAll(),
);

const { user, roleInPayload } = await this.#getRoleInPayloadOrUser(
uow,
payload,
mode,
provider,
);

const roles = roleInPayload
Expand Down Expand Up @@ -184,7 +184,7 @@ export class UpdateConventionStatus extends TransactionalUseCase<
uow,
payload,
conventionRead,
mode,
provider,
),
triggeredBy,
}
Expand All @@ -210,15 +210,15 @@ export class UpdateConventionStatus extends TransactionalUseCase<
async #getRoleInPayloadOrUser(
uow: UnitOfWork,
payload: UpdateConventionStatusSupportedJwtPayload,
mode: OAuthProvider,
provider: OAuthGatewayProvider,
): Promise<
| { user: InclusionConnectedUser; roleInPayload: undefined }
| { user: undefined; roleInPayload: Role }
> {
if ("role" in payload)
return { roleInPayload: payload.role, user: undefined };

const user = await uow.userRepository.getById(payload.userId, mode);
const user = await uow.userRepository.getById(payload.userId, provider);
if (!user)
throw errors.user.notFound({
userId: payload.userId,
Expand Down Expand Up @@ -260,9 +260,9 @@ export class UpdateConventionStatus extends TransactionalUseCase<
uow: UnitOfWork,
userId: UserId,
agencyId: AgencyId,
mode: OAuthProvider,
provider: OAuthGatewayProvider,
): Promise<string> {
const user = await uow.userRepository.getById(userId, mode);
const user = await uow.userRepository.getById(userId, provider);
if (!user) throw errors.user.notFound({ userId });
const userAgencyRights = user.agencyRights.find(
(agencyRight) => agencyRight.agency.id === agencyId,
Expand Down Expand Up @@ -300,7 +300,7 @@ export class UpdateConventionStatus extends TransactionalUseCase<
uow: UnitOfWork,
payload: UpdateConventionStatusSupportedJwtPayload,
originalConvention: ConventionDto,
mode: OAuthProvider,
provider: OAuthGatewayProvider,
): Promise<string> => {
const getEmailFromEmailHash = async (
agencyId: AgencyId,
Expand Down Expand Up @@ -329,7 +329,7 @@ export class UpdateConventionStatus extends TransactionalUseCase<
uow,
payload.userId,
originalConvention.agencyId,
mode,
provider,
);
return agencyIcUserEmail;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UserParamsForAgency, errors, userParamsForAgencySchema } from "shared";
import { TransactionalUseCase } from "../../../core/UseCase";
import { oAuthModeByFeatureFlags } from "../../../core/authentication/inclusion-connect/port/OAuthGateway";
import { oAuthProviderByFeatureFlags } from "../../../core/authentication/inclusion-connect/port/OAuthGateway";
import { SaveNotificationAndRelatedEvent } from "../../../core/notifications/helpers/Notification";
import { UnitOfWork } from "../../../core/unit-of-work/ports/UnitOfWork";
import { UnitOfWorkPerformer } from "../../../core/unit-of-work/ports/UnitOfWorkPerformer";
Expand Down Expand Up @@ -30,7 +30,7 @@ export class NotifyIcUserAgencyRightChanged extends TransactionalUseCase<

const user = await uow.userRepository.getById(
params.userId,
oAuthModeByFeatureFlags(await uow.featureFlagRepository.getAll()),
oAuthProviderByFeatureFlags(await uow.featureFlagRepository.getAll()),
);
if (!user) throw errors.user.notFound({ userId: params.userId });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
rejectIcUserRoleForAgencyParamsSchema,
} from "shared";
import { TransactionalUseCase } from "../../../core/UseCase";
import { oAuthModeByFeatureFlags } from "../../../core/authentication/inclusion-connect/port/OAuthGateway";
import { oAuthProviderByFeatureFlags } from "../../../core/authentication/inclusion-connect/port/OAuthGateway";
import { SaveNotificationAndRelatedEvent } from "../../../core/notifications/helpers/Notification";
import { UnitOfWork } from "../../../core/unit-of-work/ports/UnitOfWork";
import { UnitOfWorkPerformer } from "../../../core/unit-of-work/ports/UnitOfWorkPerformer";
Expand Down Expand Up @@ -35,7 +35,7 @@ export class NotifyIcUserAgencyRightRejected extends TransactionalUseCase<

const user = await uow.userRepository.getById(
params.userId,
oAuthModeByFeatureFlags(await uow.featureFlagRepository.getAll()),
oAuthProviderByFeatureFlags(await uow.featureFlagRepository.getAll()),
);

if (!user) throw errors.user.notFound({ userId: params.userId });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
markPartnersErroredConventionAsHandledRequestSchema,
} from "shared";
import { TransactionalUseCase } from "../../../core/UseCase";
import { oAuthModeByFeatureFlags } from "../../../core/authentication/inclusion-connect/port/OAuthGateway";
import { oAuthProviderByFeatureFlags } from "../../../core/authentication/inclusion-connect/port/OAuthGateway";
import { CreateNewEvent } from "../../../core/events/ports/EventBus";
import { TimeGateway } from "../../../core/time-gateway/ports/TimeGateway";
import { UnitOfWork } from "../../../core/unit-of-work/ports/UnitOfWork";
Expand Down Expand Up @@ -45,7 +45,7 @@ export class MarkPartnersErroredConventionAsHandled extends TransactionalUseCase

const currentUser = await uow.userRepository.getById(
userId,
oAuthModeByFeatureFlags(await uow.featureFlagRepository.getAll()),
oAuthProviderByFeatureFlags(await uow.featureFlagRepository.getAll()),
);
if (!currentUser) throw errors.user.notFound({ userId });
const userAgencyRights = currentUser.agencyRights.find(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Pool } from "pg";
import { IdentityProvider, User, expectToEqual, oAuthProviders } from "shared";
import {
IdentityProvider,
User,
expectToEqual,
oAuthGatewayProviders,
} from "shared";
import {
KyselyDb,
makeKyselyDb,
Expand Down Expand Up @@ -31,7 +36,7 @@ describe("PgOngoingOAuthRepository", () => {
await pool.end();
});

describe.each(oAuthProviders)("with mode '%s'", (mode) => {
describe.each(oAuthGatewayProviders)("with mode '%s'", (mode) => {
it("saves an ongoing OAuth, then gets it from its states, then updates it", async () => {
const state = "11111111-1111-1111-1111-111111111111";

Expand Down
Loading

0 comments on commit 047a5a1

Please sign in to comment.