27 lines
807 B
TypeScript
27 lines
807 B
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Resolve } from '@angular/router';
|
|
import { Observable } from 'rxjs';
|
|
import { first, map } from 'rxjs/operators';
|
|
import { AuthService } from '../services/auth.service';
|
|
import { CustomerService } from '../services/customer.service';
|
|
import { IMembership } from '@app/auth/models/user.model';
|
|
|
|
@Injectable()
|
|
export class MembershipResolver implements Resolve<IMembership> {
|
|
constructor(
|
|
private readonly custSvc: CustomerService,
|
|
private readonly authSvc: AuthService
|
|
) { }
|
|
|
|
resolve(): Observable<IMembership> {
|
|
return this.custSvc.getCustomer(this.authSvc.user._id).pipe(
|
|
map((cust) => {
|
|
const membership = cust?.membership;
|
|
if (membership) {
|
|
return membership;
|
|
}
|
|
}),
|
|
first())
|
|
}
|
|
}
|