Files
psp_panel/src/app/domains/pos/pos.store.ts
T

62 lines
1.5 KiB
TypeScript
Raw Normal View History

2026-03-18 13:35:57 +03:30
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'),
});
}
}