init to pos domain
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { EntityState, EntityStore } from '@/core/state';
|
||||
import { computed, inject, Injectable } from '@angular/core';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
import { catchError, finalize, throwError } from 'rxjs';
|
||||
import { IPosInfoResponse } from './models/pos.io';
|
||||
import { PosService } from './modules/landing/services/main.service';
|
||||
|
||||
interface PosState extends EntityState<IPosInfoResponse> {
|
||||
posId: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class PosStore extends EntityStore<IPosInfoResponse, PosState> {
|
||||
private readonly service = inject(PosService);
|
||||
|
||||
constructor(private readonly cookieService: CookieService) {
|
||||
super({
|
||||
loading: false,
|
||||
error: null,
|
||||
entity: null,
|
||||
initialized: false,
|
||||
isRefreshing: false,
|
||||
posId: cookieService.get('posId'),
|
||||
});
|
||||
}
|
||||
|
||||
posId = computed(() => this._state().posId);
|
||||
|
||||
getData() {
|
||||
this.patchState({ loading: true });
|
||||
this.service
|
||||
.getInfo()
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
this.patchState({ loading: false });
|
||||
}),
|
||||
catchError(() => {
|
||||
this.patchState({
|
||||
error: '',
|
||||
});
|
||||
return throwError('');
|
||||
}),
|
||||
)
|
||||
.subscribe((entity) => {
|
||||
this.patchState({ entity });
|
||||
});
|
||||
}
|
||||
|
||||
override reset(): void {
|
||||
this.setState({
|
||||
loading: false,
|
||||
error: null,
|
||||
entity: null,
|
||||
initialized: false,
|
||||
isRefreshing: false,
|
||||
posId: this.cookieService.get('posId'),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user