@@ -3,30 +3,28 @@ import type { PathsMap } from "../paths.js";
33import { paths } from "../paths.js" ;
44import { Scope } from "../../../../commons/utils/commonTypes.js" ;
55
6+ const findAnalytics = ( pathsMap : PathsMap , pathname : string ) =>
7+ Object . values ( pathsMap ) . find (
8+ ( path ) => path . path === pathname && path . analytics ,
9+ ) ?. analytics ;
10+
611export const setAnalyticsForPath = async (
712 request : FastifyRequest ,
813 reply : FastifyReply ,
914) => {
1015 const url = new URL ( request . url , "http://localhost" ) ;
11- const scopes = Object . values ( Scope ) ;
1216
13- for ( const scope of scopes ) {
14- const states = paths . journeys [ scope ] ;
17+ const analytics = findAnalytics ( paths . others , url . pathname ) ;
18+ if ( analytics ) {
19+ reply . analytics = analytics ;
20+ }
1521
16- for ( const state of Object . values ( states ) ) {
22+ for ( const scope of Object . values ( Scope ) ) {
23+ for ( const state of Object . values ( paths . journeys [ scope ] ) ) {
1724 // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
18- for ( const path of Object . values ( state as PathsMap ) ) {
19- if ( path . path === url . pathname && path . analytics ) {
20- reply . analytics = path . analytics ;
21- return ;
22- }
23- }
24- }
25-
26- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
27- for ( const path of Object . values ( paths . others as PathsMap ) ) {
28- if ( path . path === url . pathname && path . analytics ) {
29- reply . analytics = path . analytics ;
25+ const analytics = findAnalytics ( state as PathsMap , url . pathname ) ;
26+ if ( analytics ) {
27+ reply . analytics = analytics ;
3028 return ;
3129 }
3230 }
0 commit comments