init to pos domain
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export * from './menuItems.const';
|
||||
@@ -0,0 +1,16 @@
|
||||
import { MenuItem } from 'primeng/api';
|
||||
export const CONSUMER_MENU_ITEMS = [
|
||||
{
|
||||
items: [
|
||||
{
|
||||
label: 'فروش',
|
||||
icon: 'pi pi-fw pi-home',
|
||||
routerLink: ['/'],
|
||||
},
|
||||
{
|
||||
label: 'فاکتورها',
|
||||
icon: 'pi pi-fw pi-home',
|
||||
},
|
||||
],
|
||||
},
|
||||
] as MenuItem[];
|
||||
@@ -0,0 +1,5 @@
|
||||
@if (loading()) {
|
||||
<shared-page-loading />
|
||||
} @else {
|
||||
<router-outlet></router-outlet>
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
|
||||
import { Component, computed, inject } from '@angular/core';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
import { PosStore } from '../pos.store';
|
||||
|
||||
@Component({
|
||||
selector: 'pos-layout',
|
||||
templateUrl: './layout.component.html',
|
||||
imports: [PageLoadingComponent, RouterOutlet],
|
||||
})
|
||||
export class PosLayoutComponent {
|
||||
constructor() {}
|
||||
|
||||
private readonly store = inject(PosStore);
|
||||
|
||||
readonly loading = computed(() => this.store.loading());
|
||||
readonly posInfo = computed(() => this.store.entity());
|
||||
|
||||
getData() {
|
||||
this.store.getData();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.getData();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
export interface IPosInfoRawResponse {
|
||||
name: true;
|
||||
complex: {
|
||||
id: string;
|
||||
name: string;
|
||||
tax_id: string;
|
||||
};
|
||||
businessActivity: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
guild: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface IPosInfoResponse extends IPosInfoRawResponse {}
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = '/api/v1/pos';
|
||||
|
||||
export const POS_API_ROUTES = {
|
||||
info: () => `${baseUrl}`,
|
||||
goods: () => `${baseUrl}/goods`,
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export * from './apiRoutes';
|
||||
@@ -0,0 +1,13 @@
|
||||
import { TAccountType } from '@/core/constants/accountTypes.const';
|
||||
|
||||
export interface IAccountRawResponse {
|
||||
username: string;
|
||||
id: string;
|
||||
}
|
||||
export interface IAccountResponse extends IAccountRawResponse {}
|
||||
|
||||
export interface IAccountRequest {
|
||||
username: string;
|
||||
password?: string;
|
||||
type: TAccountType;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './accounts_io';
|
||||
export * from './io';
|
||||
@@ -0,0 +1,18 @@
|
||||
import { TRoles } from '@/core';
|
||||
|
||||
export interface IUserRawResponse {
|
||||
mobile_number: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
fullname: string;
|
||||
id: string;
|
||||
role: TRoles;
|
||||
}
|
||||
export interface IUserResponse extends IUserRawResponse {}
|
||||
|
||||
export interface IUserRequest {
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
mobile_number: string;
|
||||
role: TRoles;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { IPosInfoRawResponse, IPosInfoResponse } from '@/domains/pos/models/pos.io';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { POS_API_ROUTES } from '../constants';
|
||||
import { IUserRawResponse, IUserResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PosService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = POS_API_ROUTES;
|
||||
|
||||
getInfo(): Observable<IPosInfoResponse> {
|
||||
return this.http.get<IPosInfoRawResponse>(this.apiRoutes.info());
|
||||
}
|
||||
getGoods(): Observable<IUserResponse> {
|
||||
return this.http.get<IUserRawResponse>(this.apiRoutes.goods());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './root.component';
|
||||
@@ -0,0 +1 @@
|
||||
<span>صفحهی pos</span>
|
||||
@@ -0,0 +1,21 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { PosStore } from '@/domains/pos/pos.store';
|
||||
import { LayoutService } from '@/layout/service/layout.service';
|
||||
import { Component, computed, inject } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'pos-landing',
|
||||
templateUrl: './root.component.html',
|
||||
})
|
||||
export class PosLandingComponent {
|
||||
private readonly store = inject(PosStore);
|
||||
private readonly layoutService = inject(LayoutService);
|
||||
|
||||
private readonly posInfo = computed(() => this.store.entity());
|
||||
|
||||
ngOnInit() {
|
||||
this.layoutService.setPanelInfo({
|
||||
title: `فروشگاه ${this.posInfo()?.complex.name} - ${this.posInfo()?.name}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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'),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Route } from '@angular/router';
|
||||
|
||||
export const POS_ROUTES = {
|
||||
path: 'pos',
|
||||
loadComponent: () => import('./layouts/layout.component').then((m) => m.PosLayoutComponent),
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
loadComponent: () =>
|
||||
import('./modules/landing/views/root.component').then((m) => m.PosLandingComponent),
|
||||
},
|
||||
],
|
||||
} as Route;
|
||||
Reference in New Issue
Block a user