11import { Component , inject , OnInit , signal } from '@angular/core' ;
22import { ActivatedRoute , Router , RouterModule } from '@angular/router' ;
3- import { setToken , showMetadata } from '@placeos/ts-client' ;
4- import { lastValueFrom , of } from 'rxjs' ;
3+ import {
4+ listChildMetadata ,
5+ PlaceZoneMetadata ,
6+ setToken ,
7+ } from '@placeos/ts-client' ;
8+ import { BehaviorSubject , lastValueFrom , of } from 'rxjs' ;
59import {
610 catchError ,
711 filter ,
@@ -31,6 +35,7 @@ import {
3135 notifyError ,
3236 notifySuccess ,
3337 OrganisationService ,
38+ parseJWT ,
3439 SettingsService ,
3540} from '@placeos/common' ;
3641import { IconComponent , TranslatePipe } from '@placeos/components' ;
@@ -145,13 +150,28 @@ export class CheckinPreferencesComponent
145150 public type = signal < 'save' | 'menu' > ( 'menu' ) ;
146151 public beverage : CateringItem ;
147152 public readonly event = this . _checkin . event ;
153+ public readonly bld_id = new BehaviorSubject ( '' ) ;
148154
149- public readonly menu = this . _org . active_building . pipe (
155+ public readonly menu = this . bld_id . pipe (
150156 filter ( ( _ ) => ! ! _ ) ,
151157 switchMap ( ( bld ) =>
152- showMetadata ( bld . id , 'catering' ) . pipe (
153- catchError ( ( ) => of ( { details : [ ] } ) ) ,
154- map ( ( { details } ) => ( details instanceof Array ? details : [ ] ) ) ,
158+ listChildMetadata ( bld , {
159+ name : 'catering' ,
160+ include_parent : true ,
161+ } ) . pipe (
162+ catchError ( ( ) => of ( [ ] as PlaceZoneMetadata [ ] ) ) ,
163+ map ( ( list ) => {
164+ const details = [ ] ;
165+ for ( const zone of list ) {
166+ if ( zone . keys . includes ( 'catering' ) ) {
167+ const catering = zone . metadata . catering ;
168+ if ( catering . details instanceof Array ) {
169+ details . push ( ...catering . details ) ;
170+ }
171+ }
172+ }
173+ return details ;
174+ } ) ,
155175 map ( ( menu ) => menu . map ( ( i ) => new CateringItem ( i ) ) ) ,
156176 ) ,
157177 ) ,
@@ -171,23 +191,34 @@ export class CheckinPreferencesComponent
171191
172192 public ngOnInit ( ) : void {
173193 this . loading . set ( true ) ;
174- this . _org . limit_init = true ;
194+ this . subscription (
195+ 'bld' ,
196+ this . _org . active_building . subscribe ( ( v ) =>
197+ v ? this . bld_id . next ( v . id ) : '' ,
198+ ) ,
199+ ) ;
175200 this . subscription (
176201 '' ,
177202 this . _route . queryParamMap . subscribe ( async ( params ) => {
178- if ( params . has ( 'jwt' ) ) setToken ( params . get ( 'jwt' ) ) ;
179- if ( params . has ( 'email' ) ) {
180- await this . _checkin
181- . loadGuestAndEvent (
182- params . get ( 'email' ) ,
183- params . get ( 'event_id' ) ,
184- )
185- . catch ( ( err ) => {
186- this . handleError (
187- 'Unable to find visitor or a meeting associated with the given email address.' ,
188- ) ;
189- throw err ;
190- } ) ;
203+ const jwt = params . get ( 'jwt' ) ;
204+ if ( jwt ) {
205+ setToken ( jwt ) ;
206+ const data = parseJWT ( jwt ) ;
207+ const user = data . u ;
208+ if ( user ) {
209+ const email = user . e ;
210+ const [ event_id , , bld_zone ] = user . r || [ ] ;
211+ this . bld_id . next ( bld_zone ) ;
212+
213+ await this . _checkin
214+ . loadGuestAndEvent ( email , event_id )
215+ . catch ( ( err ) => {
216+ this . handleError (
217+ 'Unable to find visitor or a meeting associated with the given email address.' ,
218+ ) ;
219+ throw err ;
220+ } ) ;
221+ }
191222 }
192223 } ) ,
193224 ) ;
0 commit comments