60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
|
|
import { EntityState, EntityStore } from '@/core/state';
|
||
|
|
import { LayoutService } from '@/layout/service/layout.service';
|
||
|
|
import { inject, Injectable } from '@angular/core';
|
||
|
|
import { catchError, finalize, throwError } from 'rxjs';
|
||
|
|
import { IConsumerInfoResponse } from '../models';
|
||
|
|
import { ConsumerService } from '../services/main.service';
|
||
|
|
|
||
|
|
interface ConsumerState extends EntityState<IConsumerInfoResponse> {}
|
||
|
|
|
||
|
|
@Injectable({
|
||
|
|
providedIn: 'root',
|
||
|
|
})
|
||
|
|
export class ConsumerStore extends EntityStore<IConsumerInfoResponse, ConsumerState> {
|
||
|
|
private readonly service = inject(ConsumerService);
|
||
|
|
private readonly layoutService = inject(LayoutService);
|
||
|
|
|
||
|
|
constructor() {
|
||
|
|
super({
|
||
|
|
loading: false,
|
||
|
|
error: null,
|
||
|
|
entity: null,
|
||
|
|
initialized: false,
|
||
|
|
isRefreshing: false,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
getData() {
|
||
|
|
this.patchState({ loading: true });
|
||
|
|
this.service
|
||
|
|
.getInfo()
|
||
|
|
.pipe(
|
||
|
|
finalize(() => {
|
||
|
|
this.patchState({ loading: false });
|
||
|
|
}),
|
||
|
|
catchError(() => {
|
||
|
|
this.patchState({
|
||
|
|
error: '',
|
||
|
|
});
|
||
|
|
return throwError('');
|
||
|
|
}),
|
||
|
|
)
|
||
|
|
.subscribe((entity) => {
|
||
|
|
this.layoutService.setPanelInfo({
|
||
|
|
title: 'پنل مدیریت کسب و کار',
|
||
|
|
});
|
||
|
|
this.patchState({ entity });
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
override reset(): void {
|
||
|
|
this.setState({
|
||
|
|
loading: false,
|
||
|
|
error: null,
|
||
|
|
entity: null,
|
||
|
|
initialized: false,
|
||
|
|
isRefreshing: false,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|