11import { logger } from '@altinn/dialogporten-node-logger' ;
2- import { booleanArg , extendType , list , objectType , stringArg } from 'nexus' ;
2+ import { extendType , list , objectType , stringArg } from 'nexus' ;
33import config from '../../../config.js' ;
44import type { LocalizedText , Resource } from './resourceRegistry.ts' ;
55import { getEnvironmentConfig } from './serviceResourcesConfig.js' ;
@@ -9,10 +9,10 @@ interface TransformedServiceResource {
99 title : LocalizedText ;
1010 org : string ;
1111 resourceType : string ;
12- selfIdentifiedUserEnabled : boolean ;
12+ delegable : boolean ;
1313}
1414
15- const serviceResourcesRedisKey = 'arbeidsflate-service-resources:v3 ' ;
15+ const serviceResourcesRedisKey = 'arbeidsflate-service-resources:v4 ' ;
1616let refreshTimer : NodeJS . Timeout | null = null ;
1717
1818async function fetchServiceResources ( ) : Promise < Resource [ ] > {
@@ -48,8 +48,6 @@ export interface ResourceFilters {
4848 excludeOrgCodes ?: string [ ] ;
4949 /** Filter by resource IDs - exclude these specific resource IDs */
5050 excludeIds ?: string [ ] ;
51- /** Only include resources that are enabled for self-identified users */
52- onlySelfIdentifiedUserEnabled ?: boolean ;
5351 /** Only include resources that are visible */
5452 onlyVisible ?: boolean ;
5553 /** Only include resources that are delegable */
@@ -103,13 +101,6 @@ export async function storeServiceResourcesInRedis(filters?: ResourceFilters): P
103101 }
104102 }
105103
106- // Filter by self-identified user enabled
107- if ( filters . onlySelfIdentifiedUserEnabled === true ) {
108- if ( ! resource . selfIdentifiedUserEnabled ) {
109- return false ;
110- }
111- }
112-
113104 // Filter by visible resources only
114105 if ( filters . onlyVisible === true ) {
115106 if ( ! resource . visible ) {
@@ -165,7 +156,7 @@ export async function storeServiceResourcesInRedis(filters?: ResourceFilters): P
165156 ''
166157 ) . toLowerCase ( ) ,
167158 resourceType : resource . resourceType ,
168- selfIdentifiedUserEnabled : resource . selfIdentifiedUserEnabled || false ,
159+ delegable : resource . delegable ,
169160 } ) ) ;
170161
171162 await redisClient . set ( serviceResourcesRedisKey , JSON . stringify ( transformedResources ) , 'EX' , 60 * 60 * 24 ) ; // Store for 24 hours
@@ -182,7 +173,6 @@ export async function getServiceResourcesFromRedis(filters?: {
182173 resourceType ?: string [ ] ;
183174 ids ?: string [ ] ;
184175 org ?: string [ ] ;
185- onlySelfIdentifiedUserEnabled ?: boolean ;
186176} ) : Promise < TransformedServiceResource [ ] > {
187177 try {
188178 const { default : redisClient } = await import ( '../../../redisClient.ts' ) ;
@@ -210,9 +200,6 @@ export async function getServiceResourcesFromRedis(filters?: {
210200 filters . org ! . some ( ( org ) => org . toLowerCase ( ) === resource . org . toLowerCase ( ) ) ,
211201 ) ;
212202 }
213- if ( filters . onlySelfIdentifiedUserEnabled === true ) {
214- resources = resources . filter ( ( resource ) => resource . selfIdentifiedUserEnabled ) ;
215- }
216203 }
217204
218205 return resources ;
@@ -307,6 +294,13 @@ export const ServiceResource = objectType({
307294 return resource . title ;
308295 } ,
309296 } ) ;
297+ t . field ( 'delegable' , {
298+ type : 'Boolean' ,
299+ description : 'Whether the service resource is delegable' ,
300+ resolve : ( resource ) => {
301+ return resource . delegable ;
302+ } ,
303+ } ) ;
310304 t . string ( 'org' , {
311305 description : 'Organization (=service owner) code for the service resource' ,
312306 resolve : ( resource ) => {
@@ -344,17 +338,12 @@ export const ServiceResourceQuery = extendType({
344338 description : 'Filter by organization codes' ,
345339 } ) ,
346340 ) ,
347- onlySelfIdentifiedUserEnabled : booleanArg ( {
348- description : 'Show only resources enabled for self-identified users' ,
349- default : false ,
350- } ) ,
351341 } ,
352342 resolve : async ( _ , args ) => {
353343 const filters : {
354344 resourceType ?: string [ ] ;
355345 ids ?: string [ ] ;
356346 org ?: string [ ] ;
357- onlySelfIdentifiedUserEnabled ?: boolean ;
358347 } = { } ;
359348
360349 if ( args . resourceType ) {
@@ -375,10 +364,6 @@ export const ServiceResourceQuery = extendType({
375364 ) ;
376365 }
377366
378- if ( args . onlySelfIdentifiedUserEnabled ) {
379- filters . onlySelfIdentifiedUserEnabled = true ;
380- }
381-
382367 return await getServiceResourcesFromRedis ( Object . keys ( filters ) . length > 0 ? filters : undefined ) ;
383368 } ,
384369 } ) ;
0 commit comments