@@ -22,6 +22,10 @@ export interface GlobalSettingGroup {
2222 updated_at : Date ;
2323}
2424
25+ export interface GlobalSettingGroupWithSettings extends GlobalSettingGroup {
26+ settings : GlobalSetting [ ] ;
27+ }
28+
2529export interface CreateGlobalSettingInput {
2630 key : string ;
2731 value : string ;
@@ -353,6 +357,42 @@ export class GlobalSettingsService {
353357 }
354358 }
355359
360+ /**
361+ * Get all groups with their metadata from the globalSettingGroups table.
362+ * Does not include the settings themselves.
363+ */
364+ static async getAllGroupMetadata ( ) : Promise < GlobalSettingGroup [ ] > {
365+ const db = getDb ( ) ;
366+ const schema = getSchema ( ) ;
367+ try {
368+ const results = await db
369+ . select ( )
370+ . from ( schema . globalSettingGroups )
371+ . orderBy ( schema . globalSettingGroups . sort_order , schema . globalSettingGroups . name ) ; // Sort by sort_order, then name
372+ return results as GlobalSettingGroup [ ] ;
373+ } catch ( error ) {
374+ throw new Error ( `Failed to get all group metadata: ${ error instanceof Error ? error . message : 'Unknown error' } ` ) ;
375+ }
376+ }
377+
378+ /**
379+ * Get all groups with their metadata and their associated settings.
380+ */
381+ static async getAllGroupsWithSettings ( ) : Promise < GlobalSettingGroupWithSettings [ ] > {
382+ const groupMetadatas = await this . getAllGroupMetadata ( ) ;
383+ const groupsWithSettings : GlobalSettingGroupWithSettings [ ] = [ ] ;
384+
385+ for ( const groupMetadata of groupMetadatas ) {
386+ const settings = await this . getByGroup ( groupMetadata . id ) ;
387+ groupsWithSettings . push ( {
388+ ...groupMetadata ,
389+ settings : settings ,
390+ } ) ;
391+ }
392+ // The groups are already sorted by getAllGroupMetadata
393+ return groupsWithSettings ;
394+ }
395+
356396 /**
357397 * Get a specific group by ID
358398 */
0 commit comments