From 522664d415c33342500defec309c2ff15bc94804 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Fri, 31 May 2024 18:10:11 -0400 Subject: [PATCH] feat(backend): allow services to provide user properties --- packages/backend/src/services/DetailProviderService.js | 9 ++++----- packages/backend/src/services/GetUserService.js | 8 ++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/services/DetailProviderService.js b/packages/backend/src/services/DetailProviderService.js index 2907fdc8..3d5d2074 100644 --- a/packages/backend/src/services/DetailProviderService.js +++ b/packages/backend/src/services/DetailProviderService.js @@ -14,15 +14,14 @@ class DetailProviderService extends BaseService { this.providers_.push(fn); } - async get_details (context) { - const details = {}; + async get_details (context, out) { + out = out || {}; for (const provider of this.providers_) { - const out = await provider(context); - Object.assign(details, out); + await provider(context, out); } - return details; + return out; } } diff --git a/packages/backend/src/services/GetUserService.js b/packages/backend/src/services/GetUserService.js index 9c3e695e..802573aa 100644 --- a/packages/backend/src/services/GetUserService.js +++ b/packages/backend/src/services/GetUserService.js @@ -26,6 +26,14 @@ class GetUserService extends BaseService { async _init () { } async get_user (options) { + const user = await this.get_user_(options); + if ( ! user ) return null; + + const svc_whoami = this.services.get('whoami'); + await svc_whoami.get_details({ user }, user); + return user; + } + async get_user_ (options) { const services = this.services; /** @type BaseDatabaseAccessService */