init to pos domain

This commit is contained in:
2026-03-18 13:35:57 +03:30
parent f2766e2d7d
commit 1e2f94261e
42 changed files with 635 additions and 809 deletions
+61
View File
@@ -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'),
});
}
}