@@ -311,48 +311,39 @@ export const websitesRouter = {
311311
312312 listWithCharts : protectedProcedure
313313 . input ( z . object ( { organizationId : z . string ( ) . optional ( ) } ) . default ( { } ) )
314- . handler ( ( { context, input } ) => {
315- const chartsListCacheKey = `listWithCharts:${ context . user . id } :${ input . organizationId || "" } ` ;
316-
317- return websiteCache . withCache ( {
318- key : chartsListCacheKey ,
319- ttl : CACHE_DURATION ,
320- tables : [ "websites" ] ,
321- queryFn : async ( ) => {
322- if ( input . organizationId ) {
323- const { success } = await websitesApi . hasPermission ( {
324- headers : context . headers ,
325- body : { permissions : { website : [ "read" ] } } ,
326- } ) ;
327- if ( ! success ) {
328- throw new ORPCError ( "FORBIDDEN" , {
329- message : "Missing organization permissions." ,
330- } ) ;
331- }
332- }
333- const whereClause = buildWebsiteFilter (
334- context . user . id ,
335- input . organizationId
336- ) ;
337-
338- const websites = await context . db . query . websites . findMany ( {
339- where : whereClause ,
340- orderBy : ( table , { desc } ) => [ desc ( table . createdAt ) ] ,
314+ . handler ( async ( { context, input } ) => {
315+ if ( input . organizationId ) {
316+ const { success } = await websitesApi . hasPermission ( {
317+ headers : context . headers ,
318+ body : { permissions : { website : [ "read" ] } } ,
319+ } ) ;
320+ if ( ! success ) {
321+ throw new ORPCError ( "FORBIDDEN" , {
322+ message : "Missing organization permissions." ,
341323 } ) ;
324+ }
325+ }
326+ const whereClause = buildWebsiteFilter (
327+ context . user . id ,
328+ input . organizationId
329+ ) ;
342330
343- const websiteIds = websites . map ( ( site ) => site . id ) ;
344- const [ chartData , activeUsers ] = await Promise . all ( [
345- fetchChartData ( websiteIds ) ,
346- fetchActiveUsers ( websiteIds ) ,
347- ] ) ;
348-
349- return {
350- websites,
351- chartData,
352- activeUsers,
353- } ;
354- } ,
331+ const websites = await context . db . query . websites . findMany ( {
332+ where : whereClause ,
333+ orderBy : ( table , { desc } ) => [ desc ( table . createdAt ) ] ,
355334 } ) ;
335+
336+ const websiteIds = websites . map ( ( site ) => site . id ) ;
337+ const [ chartData , activeUsers ] = await Promise . all ( [
338+ fetchChartData ( websiteIds ) ,
339+ fetchActiveUsers ( websiteIds ) ,
340+ ] ) ;
341+
342+ return {
343+ websites,
344+ chartData,
345+ activeUsers,
346+ } ;
356347 } ) ,
357348
358349 getById : publicProcedure
0 commit comments