Skip to content

Commit

Permalink
feat(domains): add refused verification type
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Sep 30, 2024
1 parent c76ff19 commit bdc1aba
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 51 deletions.
17 changes: 2 additions & 15 deletions packages/~/app/urls/src/pattern.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@ 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 @@ -116,11 +103,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
4 changes: 3 additions & 1 deletion packages/~/infra/moncomptepro/lib/src/email_domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { z } from "zod";

export const EmailDomain_Type_Schema = z
.enum([
"authorized", // legacy ?
"blacklisted",
"external",
"official_contact",
"trackdechet_postal_mail",
"refused",
"trackdechets_postal_mail",
"verified",
])
.nullable();
Expand Down
36 changes: 18 additions & 18 deletions packages/~/organizations/api/src/:id/domains/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GoogleSearchButton } from "@~/app.ui/button/components/search";
import { menu_item } from "@~/app.ui/menu";
import { Horizontal_Menu } from "@~/app.ui/menu/components/Horizontal_Menu";
import { hx_urls } from "@~/app.urls";
import type { EmailDomain_Type } from "@~/moncomptepro.lib/email_domain";
import type { MCP_EmailDomain_Type } from "@~/moncomptepro.lib/moncomptepro.d";
import type { get_orginization_domains_dto } from "@~/organizations.repository/get_orginization_domains";
import { match } from "ts-pattern";
Expand Down Expand Up @@ -75,38 +76,43 @@ async function Add_Domain() {
);
}

function TypeToEmoji({ type }: { type: MCP_EmailDomain_Type }) {
function TypeToEmoji({ type }: { type: EmailDomain_Type }) {
return match(type)
.with("verified", () => (
<span role="img" aria-label="vérifié" title="vérifié">
</span>
))
.with("authorized", () => (
<span role="img" aria-label="autorisé" title="autorisé">
🔓
</span>
))
.with("external", () => (
<span role="img" aria-label="externe" title="externe">
</span>
))
.with("blacklisted", () => (
<span role="img" aria-label="blacklisté" title="blacklisté">
☠️
</span>
))
.with("external", () => (
<span role="img" aria-label="externe" title="externe">
</span>
))
.with("official_contact", () => (
<span role="img" aria-label="contact officiel" title="contact officiel">
</span>
))
.with("refused", () => (
<span role="img" aria-label="postal mail" title="postal mail">
🚫
</span>
))
.with("trackdechets_postal_mail", () => (
<span role="img" aria-label="postal mail" title="postal mail">
</span>
))
.with("verified", () => (
<span role="img" aria-label="vérifié" title="vérifié">
</span>
))
.otherwise(() => (
<span role="img" aria-label="inconnu" title="inconnu">
Expand Down Expand Up @@ -155,12 +161,6 @@ async function Row_Actions({
}) {
const { id, organization_id } = organization_domain;

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

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() },
Expand Down Expand Up @@ -192,7 +192,7 @@ async function Row_Actions({
</li>
<li>
<button
{...await hx_delete_domain_props}
{...await hx_change_type_props("refused")}
class={menu_item()}
hx-swap="none"
role="menuitem"
Expand Down
23 changes: 6 additions & 17 deletions packages/~/organizations/api/src/:id/domains/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Entity_Schema, Id_Schema } from "@~/app.core/schema";
import { EmailDomain_Type_Schema } from "@~/moncomptepro.lib/email_domain";
import { ORGANISATION_EVENTS } from "@~/organizations.lib/event";
import { add_authorized_domain } from "@~/organizations.repository/add_authorized_domain";
import { delete_domain_by_id } from "@~/organizations.repository/delete_domain_by_id";
import { get_orginization_domains } from "@~/organizations.repository/get_orginization_domains";
import { update_domain_by_id } from "@~/organizations.repository/update_domain_by_id";
import { Hono } from "hono";
Expand Down Expand Up @@ -61,33 +60,23 @@ 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");

await delete_domain_by_id(moncomptepro_pg, 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)),
zValidator(
"query",
z.object({ type: EmailDomain_Type_Schema.or(z.literal("null")) }),
z.object({
type: EmailDomain_Type_Schema.or(
z.literal("null").transform(() => null),
),
}),
),
async function PATCH({ text, req, var: { moncomptepro_pg } }) {
const { domain_id } = req.valid("param");
const { type: verification_type } = req.valid("query");

await update_domain_by_id(moncomptepro_pg, domain_id, {
verification_type:
verification_type === "null" ? null : verification_type,
verification_type: verification_type,
verified_at:
verification_type === "verified"
? new Date().toISOString()
Expand Down

0 comments on commit bdc1aba

Please sign in to comment.