import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable, ReplaySubject, tap } from 'rxjs'; import { FaqCategory, Guide, GuideCategory } from 'app/modules/admin/apps/help-center/help-center.type'; @Injectable({ providedIn: 'root' }) export class HelpCenterService { private _faqs: ReplaySubject = new ReplaySubject(1); private _guides: ReplaySubject = new ReplaySubject(1); private _guide: ReplaySubject = new ReplaySubject(1); /** * Constructor */ constructor(private _httpClient: HttpClient) { } // ----------------------------------------------------------------------------------------------------- // @ Accessors // ----------------------------------------------------------------------------------------------------- /** * Getter for FAQs */ get faqs$(): Observable { return this._faqs.asObservable(); } /** * Getter for guides */ get guides$(): Observable { return this._guides.asObservable(); } /** * Getter for guide */ get guide$(): Observable { return this._guide.asObservable(); } // ----------------------------------------------------------------------------------------------------- // @ Public methods // ----------------------------------------------------------------------------------------------------- /** * Get all FAQs */ getAllFaqs(): Observable { return this._httpClient.get('api/apps/help-center/faqs').pipe( tap((response: any) => { this._faqs.next(response); }) ); } /** * Get FAQs by category using category slug * * @param slug */ getFaqsByCategory(slug: string): Observable { return this._httpClient.get('api/apps/help-center/faqs', { params: {slug} }).pipe( tap((response: any) => { this._faqs.next(response); }) ); } /** * Get all guides limited per category by the given number * * @param limit */ getAllGuides(limit = '4'): Observable { return this._httpClient.get('api/apps/help-center/guides', { params: {limit} }).pipe( tap((response: any) => { this._guides.next(response); }) ); } /** * Get guides by category using category slug * * @param slug */ getGuidesByCategory(slug: string): Observable { return this._httpClient.get('api/apps/help-center/guides', { params: {slug} }).pipe( tap((response: any) => { this._guides.next(response); }) ); } /** * Get guide by category and guide slug * * @param categorySlug * @param guideSlug */ getGuide(categorySlug: string, guideSlug: string): Observable { return this._httpClient.get('api/apps/help-center/guide', { params: { categorySlug, guideSlug } }).pipe( tap((response: any) => { this._guide.next(response); }) ); } }