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

feat(organization): remove domain email #598

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 19 additions & 6 deletions packages/~/app/urls/src/pattern.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ declare const app: import("hono/hono-base").HonoBase<
};
};
"/organizations/:id/domains/:domain_id": {
$delete: {
input: {
param: {
id: string;
domain_id: string;
} & {
id: string;
};
};
output: "OK";
outputFormat: "text";
status: 200;
};
$patch: {
input: {
param: {
Expand Down Expand Up @@ -103,11 +116,11 @@ declare const app: import("hono/hono-base").HonoBase<
id: string;
};
form: {
is_external?:
verification_type?:
| import("hono/types").ParsedFormValue
| import("hono/types").ParsedFormValue[]
| undefined;
verification_type?:
is_external?:
| import("hono/types").ParsedFormValue
| import("hono/types").ParsedFormValue[]
| undefined;
Expand Down Expand Up @@ -197,10 +210,10 @@ declare const app: import("hono/hono-base").HonoBase<
$get: {
input: {
query: {
id?: string | string[] | undefined;
page?: string | string[] | undefined;
page_size?: string | string[] | undefined;
q?: string | string[] | undefined;
id?: string | string[] | undefined;
};
};
output: {};
Expand Down Expand Up @@ -333,9 +346,9 @@ declare const app: import("hono/hono-base").HonoBase<
id: string;
};
};
output: {};
outputFormat: string;
status: import("hono/utils/http-status").StatusCode;
output: "OK";
outputFormat: "text";
status: 200;
};
};
"/moderations/:id/$procedures/rejected": {
Expand Down
19 changes: 18 additions & 1 deletion packages/~/organizations/api/src/:id/domains/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,20 @@ async function Row_Actions({
}: {
organization_domain: get_orginization_domains_dto[number];
}) {
const { id, organization_id } = organization_domain;
const { domain, id, organization, organization_id } = organization_domain;

const hx_change_type_props = (type: MCP_EmailDomain_Type) =>
hx_urls.organizations[":id"].domains[":domain_id"].$patch({
param: { id: organization_id.toString(), domain_id: id.toString() },
query: { type },
});

const hx_delete_domain_props = await hx_urls.organizations[":id"].domains[
":domain_id"
].$delete({
param: { id: organization_id.toString(), domain_id: id.toString() },
});

return (
<Horizontal_Menu>
<ul class="list-none p-0">
Expand Down Expand Up @@ -200,6 +206,17 @@ async function Row_Actions({
🚫 Domaine refusé
</button>
</li>
<li>
<button
{...hx_delete_domain_props}
class={menu_item()}
hx-confirm={`Êtes-vous sûr de vouloir supprimer le domaine « ${domain} » de l'organisation « ${organization.cached_libelle} » ?`}
hx-swap="none"
role="menuitem"
>
🗑️ Supprimer
</button>
</li>
</ul>
</Horizontal_Menu>
);
Expand Down
17 changes: 17 additions & 0 deletions packages/~/organizations/api/src/:id/domains/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "@~/app.core/schema";
import { EmailDomain_Type_Schema } from "@~/moncomptepro.lib/email_domain";
import { ORGANISATION_EVENTS } from "@~/organizations.lib/event";
import { RemoveDomainEmailById } from "@~/organizations.lib/usecase";
import { add_authorized_domain } from "@~/organizations.repository/add_authorized_domain";
import { get_orginization_domains } from "@~/organizations.repository/get_orginization_domains";
import { update_domain_by_id } from "@~/organizations.repository/update_domain_by_id";
Expand Down Expand Up @@ -63,6 +64,22 @@ export default new Hono<ContextType>()
} as Htmx_Header);
},
)
.delete(
"/:domain_id",
zValidator("param", Entity_Schema.merge(DomainParams_Schema)),
async function DELETE({ text, req, var: { moncomptepro_pg } }) {
const { domain_id } = req.valid("param");

const remove_domain_email_by_id = RemoveDomainEmailById({
pg: moncomptepro_pg,
});
await remove_domain_email_by_id(domain_id);

return text("OK", 200, {
"HX-Trigger": ORGANISATION_EVENTS.Enum.DOMAIN_UPDATED,
} as Htmx_Header);
},
)
.patch(
"/:domain_id",
zValidator("param", Entity_Schema.merge(DomainParams_Schema)),
Expand Down
3 changes: 3 additions & 0 deletions packages/~/organizations/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
".": {
"default": "./src/index.ts"
},
"./usecase": {
"default": "./src/usecase/index.ts"
},
"./*": {
"default": "./src/*.ts"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//

import { schema } from "@~/moncomptepro.database";
import { create_unicorn_organization } from "@~/moncomptepro.database/seed/unicorn";
import { empty_database, migrate, pg } from "@~/moncomptepro.database/testing";
import { beforeAll, beforeEach, expect, test } from "bun:test";
import { RemoveDomainEmailById } from "./RemoveDomainEmailById";

//

beforeAll(migrate);
beforeEach(empty_database);

const remove_domain_email_by_id = RemoveDomainEmailById({ pg });

//

test("returns no membership", async () => {
const organization_id = await create_unicorn_organization(pg);
const [{ domain_id }] = await pg
.insert(schema.email_domains)
.values({
domain: "unicorn.xyz",
organization_id,
})
.returning({ domain_id: schema.email_domains.id });

await remove_domain_email_by_id(domain_id);

expect(
await pg.query.email_domains.findFirst({
columns: { id: true },
where: (table, { eq }) => eq(table.id, domain_id),
}),
).toBeUndefined();
});
21 changes: 21 additions & 0 deletions packages/~/organizations/lib/src/usecase/RemoveDomainEmailById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//

import {
schema,
type MonCompteProDatabaseCradle,
} from "@~/moncomptepro.database";
import { eq } from "drizzle-orm";

//

export function RemoveDomainEmailById({ pg }: MonCompteProDatabaseCradle) {
return async function remove_domain_email_by_id(id: number) {
return pg
.delete(schema.email_domains)
.where(eq(schema.email_domains.id, id));
};
}

export type RemoveDomainEmailByIdHandler = ReturnType<
typeof RemoveDomainEmailById
>;
3 changes: 3 additions & 0 deletions packages/~/organizations/lib/src/usecase/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//

export * from "./RemoveDomainEmailById";