1
1
//
2
2
3
3
import { zValidator } from "@hono/zod-validator" ;
4
- import { HTTPError } from "@~/app.core/error" ;
4
+ import { HTTPError , NotFoundError } from "@~/app.core/error" ;
5
5
import type { Htmx_Header } from "@~/app.core/htmx" ;
6
6
import { Entity_Schema } from "@~/app.core/schema" ;
7
7
import { z_email_domain } from "@~/app.core/schema/z_email_domain" ;
@@ -16,7 +16,7 @@ import { MODERATION_EVENTS } from "@~/moderations.lib/event";
16
16
import { validate_form_schema } from "@~/moderations.lib/schema/validate.form" ;
17
17
import { mark_moderation_as } from "@~/moderations.lib/usecase/mark_moderation_as" ;
18
18
import { MemberJoinOrganization } from "@~/moderations.lib/usecase/member_join_organization" ;
19
- import { GetModerationById } from "@~/moderations.repository" ;
19
+ import { GetModerationById , GetModerationWithUser } from "@~/moderations.repository" ;
20
20
import {
21
21
AddVerifiedDomain ,
22
22
GetFicheOrganizationById ,
@@ -47,18 +47,14 @@ export default new Hono<App_Context>().patch(
47
47
get_organization_by_id : GetFicheOrganizationById ( { pg : identite_pg } ) ,
48
48
mark_domain_as_verified : MarkDomainAsVerified ( identite_pg_client ) ,
49
49
} ) ;
50
- const moderation = await identite_pg . query . moderations . findFirst ( {
51
- columns : {
52
- comment : true ,
53
- id : true ,
54
- organization_id : true ,
55
- user_id : true ,
56
- } ,
57
- with : { user : { columns : { email : true } } } ,
58
- where : eq ( schema . moderations . id , id ) ,
59
- } ) ;
60
-
61
- if ( ! moderation ) return notFound ( ) ;
50
+ const get_moderation_with_user = GetModerationWithUser ( identite_pg ) ;
51
+
52
+ const [ moderation_error , moderation ] = await to ( get_moderation_with_user ( id ) ) ;
53
+
54
+ if ( moderation_error ) {
55
+ if ( moderation_error instanceof NotFoundError ) return notFound ( ) ;
56
+ throw moderation_error ;
57
+ }
62
58
63
59
const {
64
60
organization_id,
@@ -71,7 +67,7 @@ export default new Hono<App_Context>().patch(
71
67
72
68
//#region ✨ Add verified domain
73
69
if ( add_domain ) {
74
- const [ error ] = await to (
70
+ const [ domain_error ] = await to (
75
71
add_verified_domain ( {
76
72
organization_id,
77
73
domain,
@@ -80,16 +76,16 @@ export default new Hono<App_Context>().patch(
80
76
} ) ,
81
77
) ;
82
78
83
- match ( error )
79
+ match ( domain_error )
84
80
. with ( P . instanceOf ( HTTPError ) , ( ) => {
85
- consola . error ( error ) ;
86
- sentry . captureException ( error , {
81
+ consola . error ( domain_error ) ;
82
+ sentry . captureException ( domain_error , {
87
83
data : { domain, organization_id : id } ,
88
84
} ) ;
89
85
} )
90
86
. with ( P . instanceOf ( Error ) , ( ) => {
91
- consola . error ( error ) ;
92
- throw error ;
87
+ consola . error ( domain_error ) ;
88
+ throw domain_error ;
93
89
} ) ;
94
90
}
95
91
//#endregion
@@ -109,20 +105,20 @@ export default new Hono<App_Context>().patch(
109
105
} ) ,
110
106
get_moderation_by_id : GetModerationById ( { pg : identite_pg } ) ,
111
107
} ) ;
112
- const [ error ] = await to (
108
+ const [ join_error ] = await to (
113
109
member_join_organization ( { is_external, moderation_id : id } ) ,
114
110
) ;
115
111
116
- match ( error )
112
+ match ( join_error )
117
113
. with ( P . instanceOf ( HTTPError ) , ( ) => {
118
- consola . error ( error ) ;
119
- sentry . captureException ( error , {
114
+ consola . error ( join_error ) ;
115
+ sentry . captureException ( join_error , {
120
116
data : { domain, organization_id : id } ,
121
117
} ) ;
122
118
} )
123
119
. with ( P . instanceOf ( Error ) , ( ) => {
124
- consola . error ( error ) ;
125
- throw error ;
120
+ consola . error ( join_error ) ;
121
+ throw join_error ;
126
122
} ) ;
127
123
128
124
//#endregion
0 commit comments