Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

En tant qu'admin je peux supprimer une entreprise #425

Merged
merged 16 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions back/src/_testBuilders/EstablishmentEntityBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const validEstablishmentEntityV2: EstablishmentEntity = {
additionalInformation: "",
customizedName: undefined,
isCommited: undefined,
createdAt: new Date(),
sourceProvider: "immersion-facile",
voluntaryToImmersion: true,
position: {
Expand All @@ -40,102 +41,102 @@ export class EstablishmentEntityBuilder
private readonly entity: EstablishmentEntity = validEstablishmentEntityV2,
) {}

build() {
public build() {
return this.entity;
}

withAdditionalInformation(additionalInformation: string) {
public withAdditionalInformation(additionalInformation: string) {
return new EstablishmentEntityBuilder({
...this.entity,
additionalInformation,
});
}

withAddress(address: AddressDto) {
public withAddress(address: AddressDto) {
return new EstablishmentEntityBuilder({ ...this.entity, address });
}

withCustomizedName(customizedName: string) {
public withCustomizedName(customizedName: string) {
return new EstablishmentEntityBuilder({ ...this.entity, customizedName });
}

withFitForDisabledWorkers(fitForDisabledWorkers: boolean) {
public withFitForDisabledWorkers(fitForDisabledWorkers: boolean) {
return new EstablishmentEntityBuilder({
...this.entity,
fitForDisabledWorkers,
});
}

withIsCommited(isCommited: boolean) {
public withIsCommited(isCommited: boolean) {
return new EstablishmentEntityBuilder({
...this.entity,
isCommited,
});
}

withIsOpen(isOpen: boolean) {
public withIsOpen(isOpen: boolean) {
return new EstablishmentEntityBuilder({
...this.entity,
isOpen,
});
}

withIsSearchable(isSearchable: boolean) {
public withIsSearchable(isSearchable: boolean) {
return new EstablishmentEntityBuilder({
...this.entity,
isSearchable,
});
}

withLastInseeCheck(lastInseeCheck: Date | undefined) {
public withLastInseeCheck(lastInseeCheck: Date | undefined) {
return new EstablishmentEntityBuilder({
...this.entity,
lastInseeCheckDate: lastInseeCheck,
});
}

withMaxContactsPerWeek(maxContactsPerWeek: number) {
public withMaxContactsPerWeek(maxContactsPerWeek: number) {
return new EstablishmentEntityBuilder({
...this.entity,
maxContactsPerWeek,
});
}

withNafDto(nafDto: NafDto) {
public withNafDto(nafDto: NafDto) {
return new EstablishmentEntityBuilder({ ...this.entity, nafDto });
}

withName(name: string) {
public withName(name: string) {
return new EstablishmentEntityBuilder({ ...this.entity, name });
}

withNumberOfEmployeeRange(numberEmployeesRange: NumberEmployeesRange) {
public withNumberOfEmployeeRange(numberEmployeesRange: NumberEmployeesRange) {
return new EstablishmentEntityBuilder({
...this.entity,
numberEmployeesRange,
});
}

withPosition(position: GeoPositionDto) {
public withPosition(position: GeoPositionDto) {
return new EstablishmentEntityBuilder({ ...this.entity, position });
}

withSiret(siret: string) {
public withSiret(siret: string) {
return new EstablishmentEntityBuilder({ ...this.entity, siret });
}

withSourceProvider(sourceProvider: FormEstablishmentSource) {
public withSourceProvider(sourceProvider: FormEstablishmentSource) {
return new EstablishmentEntityBuilder({
...this.entity,
sourceProvider,
});
}

withUpdatedAt(updatedAt: Date) {
public withUpdatedAt(updatedAt: Date) {
return new EstablishmentEntityBuilder({ ...this.entity, updatedAt });
}

withWebsite(website: string) {
public withWebsite(website: string) {
return new EstablishmentEntityBuilder({ ...this.entity, website });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class EstablishmentAggregateBuilder
private readonly aggregate: EstablishmentAggregate = validEstablishmentAggregate,
) {}

build() {
public build() {
return this.aggregate;
}

Expand Down
35 changes: 5 additions & 30 deletions back/src/adapters/primary/authMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import {
backOfficeJwtPayloadSchema,
ConventionJwtPayload,
currentJwtVersions,
EstablishmentJwtPayload,
ExtractFromExisting,
InclusionConnectJwtPayload,
PayloadKey,
} from "shared";
import { JwtKind, makeVerifyJwtES256 } from "../../domain/auth/jwt";
Expand Down Expand Up @@ -202,35 +200,12 @@ export const makeMagicLinkAuthMiddleware = (
);
}

switch (payloadKey) {
case "convention": {
if (!("role" in payload)) {
req.payloads = { inclusion: payload as InclusionConnectJwtPayload };
break;
}

if (payload.role === "backOffice") {
req.payloads = {
req.payloads =
celineung marked this conversation as resolved.
Show resolved Hide resolved
"role" in payload && payload.role === "backOffice"
? {
backOffice: backOfficeJwtPayloadSchema.parse(payload),
};
} else {
req.payloads = {
convention: payload as ConventionJwtPayload,
};
}
break;
}
case "establishment":
req.payloads = { establishment: payload as EstablishmentJwtPayload };
break;
default:
// eslint-disable-next-line no-case-declarations
const unhandledPayloadKey: never = payloadKey;
throw new Error(
"Should not happen. Expected payoaldKey, received : " +
unhandledPayloadKey,
);
}
}
: { [payloadKey]: payload };

next();
} catch (err: any) {
Expand Down
6 changes: 6 additions & 0 deletions back/src/adapters/primary/config/createUseCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { SendNotification } from "../../../domain/generic/notifications/useCases
import { AddFormEstablishment } from "../../../domain/immersionOffer/useCases/AddFormEstablishment";
import { AddFormEstablishmentBatch } from "../../../domain/immersionOffer/useCases/AddFormEstablismentsBatch";
import { ContactEstablishment } from "../../../domain/immersionOffer/useCases/ContactEstablishment";
import { DeleteEstablishment } from "../../../domain/immersionOffer/useCases/DeleteEstablishment";
import { AddExchangeToDiscussionAndTransferEmail } from "../../../domain/immersionOffer/useCases/discussions/AddExchangeToDiscussionAndTransferEmail";
import { EditFormEstablishment } from "../../../domain/immersionOffer/useCases/EditFormEstablishment";
import { GetSearchImmersionResultBySiretAndRome } from "../../../domain/immersionOffer/useCases/GetImmersionOfferById";
Expand Down Expand Up @@ -281,6 +282,11 @@ export const createUseCases = (
gateways.timeGateway,
createNewEvent,
),
deleteEstablishment: new DeleteEstablishment(
uowPerformer,
gateways.timeGateway,
saveNotificationAndRelatedEvent,
),
contactEstablishment: new ContactEstablishment(
uowPerformer,
createNewEvent,
Expand Down
7 changes: 7 additions & 0 deletions back/src/adapters/primary/config/uowConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { InMemoryConventionPoleEmploiAdvisorRepository } from "../../secondary/I
import { InMemoryConventionQueries } from "../../secondary/InMemoryConventionQueries";
import { InMemoryConventionRepository } from "../../secondary/InMemoryConventionRepository";
import { InMemoryConventionsToSyncRepository } from "../../secondary/InMemoryConventionsToSyncRepository";
import { InMemoryDeletedEstablishmentRepository } from "../../secondary/InMemoryDeletedEstablishmentRepository";
import { InMemoryFeatureFlagRepository } from "../../secondary/InMemoryFeatureFlagRepository";
import { InMemoryFormEstablishmentRepository } from "../../secondary/InMemoryFormEstablishmentRepository";
import { InMemoryImmersionAssessmentRepository } from "../../secondary/InMemoryImmersionAssessmentRepository";
Expand All @@ -33,6 +34,7 @@ import { PgConventionPoleEmploiAdvisorRepository } from "../../secondary/pg/PgCo
import { PgConventionQueries } from "../../secondary/pg/PgConventionQueries";
import { PgConventionRepository } from "../../secondary/pg/PgConventionRepository";
import { PgConventionsToSyncRepository } from "../../secondary/pg/PgConventionsToSyncRepository";
import { PgDeletedEstablishmentRepository } from "../../secondary/pg/PgDeletedEstablishmentRepository";
import { PgDiscussionAggregateRepository } from "../../secondary/pg/PgDiscussionAggregateRepository";
import { PgErrorRepository } from "../../secondary/pg/PgErrorRepository";
import { PgEstablishmentAggregateRepository } from "../../secondary/pg/PgEstablishmentAggregateRepository";
Expand Down Expand Up @@ -91,6 +93,8 @@ export const createInMemoryUow = () => {
searchMadeRepository: new InMemorySearchMadeRepository(),
shortLinkQuery: shortLinkRepository,
shortLinkRepository,
deletedEstablishmentRepository:
new InMemoryDeletedEstablishmentRepository(),
} satisfies UnitOfWork;
};

Expand All @@ -105,6 +109,9 @@ export const createPgUow = (client: PoolClient): UnitOfWork => {
conventionPoleEmploiAdvisorRepository:
new PgConventionPoleEmploiAdvisorRepository(client),
conventionsToSyncRepository: new PgConventionsToSyncRepository(client),
deletedEstablishmentRepository: new PgDeletedEstablishmentRepository(
client,
),
discussionAggregateRepository: new PgDiscussionAggregateRepository(client),
establishmentAggregateRepository: new PgEstablishmentAggregateRepository(
client,
Expand Down
Loading