init
This commit is contained in:
+1
-1
@@ -90,7 +90,7 @@
|
|||||||
},
|
},
|
||||||
"defaultConfiguration": "development",
|
"defaultConfiguration": "development",
|
||||||
"options": {
|
"options": {
|
||||||
"port": 3001,
|
"port": 5000,
|
||||||
"proxyConfig": "src/proxy.conf.js"
|
"proxyConfig": "src/proxy.conf.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "صندوق فروشگاهی",
|
"name": "مدیریت کسبوکار",
|
||||||
"short_name": "صندوق فروشگاهی",
|
"short_name": "مدیریت کسبوکار",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "/web-app-manifest-192x192.png",
|
"src": "/web-app-manifest-192x192.png",
|
||||||
|
|||||||
+6
-27
@@ -1,16 +1,5 @@
|
|||||||
|
import { SUPER_ADMIN_ROUTES } from '@/domains/superAdmin/routes';
|
||||||
import { AuthComponent } from '@/modules/auth/pages/auth.component';
|
import { AuthComponent } from '@/modules/auth/pages/auth.component';
|
||||||
import { BANK_ACCOUNTS_ROUTES } from '@/modules/bankAccounts/constants';
|
|
||||||
import { BANK_BRANCHES_ROUTES } from '@/modules/bankBranches/constants';
|
|
||||||
import { CARDEX_ROUTES } from '@/modules/cardex/constants';
|
|
||||||
import { CUSTOMERS_ROUTES } from '@/modules/customers/constants';
|
|
||||||
import { DASHBOARD_ROUTES } from '@/modules/dashboard/constants';
|
|
||||||
import { INVENTORIES_ROUTES } from '@/modules/inventories/constants';
|
|
||||||
import { POSComponent } from '@/modules/pos/views/pos.component';
|
|
||||||
import { PRODUCT_BRANDS_ROUTES } from '@/modules/productBrands/constants';
|
|
||||||
import { PRODUCT_CATEGORIES_ROUTES } from '@/modules/productCategories/constants';
|
|
||||||
import { PRODUCTS_ROUTES } from '@/modules/products/constants';
|
|
||||||
import { SUPPLIERS_ROUTES } from '@/modules/suppliers/constants';
|
|
||||||
import { USERS_ROUTES } from '@/modules/users/constants';
|
|
||||||
import { Routes } from '@angular/router';
|
import { Routes } from '@angular/router';
|
||||||
import { AppLayout } from './app/layout/component/app.layout.component';
|
import { AppLayout } from './app/layout/component/app.layout.component';
|
||||||
import { Dashboard } from './app/pages/dashboard/dashboard';
|
import { Dashboard } from './app/pages/dashboard/dashboard';
|
||||||
@@ -22,27 +11,17 @@ export const appRoutes: Routes = [
|
|||||||
path: '',
|
path: '',
|
||||||
component: AppLayout,
|
component: AppLayout,
|
||||||
children: [
|
children: [
|
||||||
|
SUPER_ADMIN_ROUTES,
|
||||||
{ path: 'ng', component: Dashboard },
|
{ path: 'ng', component: Dashboard },
|
||||||
...DASHBOARD_ROUTES,
|
|
||||||
...USERS_ROUTES,
|
|
||||||
...SUPPLIERS_ROUTES,
|
|
||||||
...PRODUCT_BRANDS_ROUTES,
|
|
||||||
...PRODUCT_CATEGORIES_ROUTES,
|
|
||||||
...CUSTOMERS_ROUTES,
|
|
||||||
...INVENTORIES_ROUTES,
|
|
||||||
...PRODUCTS_ROUTES,
|
|
||||||
...CARDEX_ROUTES,
|
|
||||||
...BANK_BRANCHES_ROUTES,
|
|
||||||
...BANK_ACCOUNTS_ROUTES,
|
|
||||||
{ path: 'uikit', loadChildren: () => import('./app/pages/uikit/uikit.routes') },
|
{ path: 'uikit', loadChildren: () => import('./app/pages/uikit/uikit.routes') },
|
||||||
{ path: 'documentation', component: Documentation },
|
{ path: 'documentation', component: Documentation },
|
||||||
{ path: 'pages', loadChildren: () => import('./app/pages/pages.routes') },
|
{ path: 'pages', loadChildren: () => import('./app/pages/pages.routes') },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
path: 'pos/:posId',
|
// path: 'pos/:posId',
|
||||||
component: POSComponent,
|
// component: POSComponent,
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
path: 'auth',
|
path: 'auth',
|
||||||
component: AuthComponent,
|
component: AuthComponent,
|
||||||
|
|||||||
@@ -9,67 +9,82 @@ export const MENU_ITEMS = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
label: 'انبارها',
|
// label: 'انبارها',
|
||||||
icon: 'pi pi-fw pi-box',
|
// icon: 'pi pi-fw pi-box',
|
||||||
items: [
|
// items: [
|
||||||
{
|
// {
|
||||||
label: 'لیست انبارها',
|
// label: 'لیست انبارها',
|
||||||
icon: 'pi pi-fw pi-list',
|
// icon: 'pi pi-fw pi-list',
|
||||||
routerLink: ['/inventories'],
|
// routerLink: ['/inventories'],
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
label: 'کالاها',
|
// label: 'کالاها',
|
||||||
icon: 'pi pi-fw pi-tags',
|
// icon: 'pi pi-fw pi-tags',
|
||||||
items: [
|
// items: [
|
||||||
{
|
// {
|
||||||
label: 'لیست کالاها',
|
// label: 'لیست کالاها',
|
||||||
icon: 'pi pi-fw pi-list',
|
// icon: 'pi pi-fw pi-list',
|
||||||
routerLink: ['/products'],
|
// routerLink: ['/products'],
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
label: 'برندهای کالا',
|
// label: 'برندهای کالا',
|
||||||
icon: 'pi pi-fw pi-tags',
|
// icon: 'pi pi-fw pi-tags',
|
||||||
routerLink: ['/product-brands'],
|
// routerLink: ['/product-brands'],
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
label: 'دستهبندیهای کالا',
|
// label: 'دستهبندیهای کالا',
|
||||||
icon: 'pi pi-fw pi-list',
|
// icon: 'pi pi-fw pi-list',
|
||||||
routerLink: ['/product-categories'],
|
// routerLink: ['/product-categories'],
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
label: 'تامینکنندگان',
|
// label: 'تامینکنندگان',
|
||||||
icon: 'pi pi-fw pi-users',
|
// icon: 'pi pi-fw pi-users',
|
||||||
items: [
|
// items: [
|
||||||
{
|
// {
|
||||||
label: 'لیست تامینکنندگان',
|
// label: 'لیست تامینکنندگان',
|
||||||
icon: 'pi pi-fw pi-list',
|
// icon: 'pi pi-fw pi-list',
|
||||||
routerLink: ['/suppliers'],
|
// routerLink: ['/suppliers'],
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
label: 'مدیریت سیستم',
|
label: 'مدیریت سیستم',
|
||||||
icon: 'pi pi-fw pi-cog',
|
icon: 'pi pi-fw pi-cog',
|
||||||
items: [
|
items: [
|
||||||
{
|
// {
|
||||||
label: 'شعب بانکها',
|
// label: 'حسابهای بانکی',
|
||||||
icon: 'pi pi-fw pi-building',
|
// icon: 'pi pi-fw pi-credit-card',
|
||||||
routerLink: ['/bankBranches'],
|
// routerLink: ['/bankAccounts'],
|
||||||
},
|
// },
|
||||||
{
|
|
||||||
label: 'حسابهای بانکی',
|
|
||||||
icon: 'pi pi-fw pi-credit-card',
|
|
||||||
routerLink: ['/bankAccounts'],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: 'کاربران',
|
label: 'کاربران',
|
||||||
icon: 'pi pi-fw pi-user',
|
icon: 'pi pi-fw pi-user',
|
||||||
routerLink: ['/users'],
|
routerLink: ['/super_admin/users'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'اصناف',
|
||||||
|
icon: 'pi pi-fw pi-building',
|
||||||
|
routerLink: ['/super_admin/guilds'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'شرکای تجاری',
|
||||||
|
icon: 'pi pi-fw pi-credit-card',
|
||||||
|
routerLink: ['/super_admin/partners'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'ارایهدهندگان',
|
||||||
|
icon: 'pi pi-fw pi-credit-card',
|
||||||
|
routerLink: ['/super_admin/providers'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'لایسنسها',
|
||||||
|
icon: 'pi pi-fw pi-credit-card',
|
||||||
|
routerLink: ['/super_admin/licenses'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,115 +0,0 @@
|
|||||||
import { HttpInterceptorFn } from '@angular/common/http';
|
|
||||||
import { inject } from '@angular/core';
|
|
||||||
import { BehaviorSubject, Observable, throwError } from 'rxjs';
|
|
||||||
import { catchError, filter, switchMap, take } from 'rxjs/operators';
|
|
||||||
import { AuthService } from '../services/auth.service';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HTTP Interceptor for token management
|
|
||||||
* - Adds Authorization header with Bearer token to requests
|
|
||||||
* - Handles token refresh on 401 responses
|
|
||||||
* - Prevents duplicate refresh token requests
|
|
||||||
*/
|
|
||||||
export const authInterceptor: HttpInterceptorFn = (req, next) => {
|
|
||||||
const authService = inject(AuthService);
|
|
||||||
|
|
||||||
// Skip auth for certain endpoints
|
|
||||||
if (shouldSkipAuth(req.url)) {
|
|
||||||
return next(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
const token = authService.getToken();
|
|
||||||
|
|
||||||
// Add token to request if available
|
|
||||||
const authReq = token
|
|
||||||
? req.clone({
|
|
||||||
headers: req.headers.set('Authorization', `Bearer ${token}`),
|
|
||||||
})
|
|
||||||
: req;
|
|
||||||
|
|
||||||
return next(authReq).pipe(
|
|
||||||
catchError((error) => {
|
|
||||||
// Handle 401 Unauthorized - token might be expired
|
|
||||||
if (error.status === 401 && !isRefreshTokenRequest(req.url)) {
|
|
||||||
return handleTokenRefresh(authService, req, next);
|
|
||||||
}
|
|
||||||
|
|
||||||
return throwError(() => error);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Subject to track if refresh is in progress
|
|
||||||
const isRefreshing = new BehaviorSubject<boolean>(false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle token refresh logic
|
|
||||||
*/
|
|
||||||
function handleTokenRefresh(authService: AuthService, req: any, next: any): Observable<any> {
|
|
||||||
if (!isRefreshing.value) {
|
|
||||||
isRefreshing.next(true);
|
|
||||||
|
|
||||||
const refreshToken = authService.getRefreshToken();
|
|
||||||
if (!refreshToken) {
|
|
||||||
isRefreshing.next(false);
|
|
||||||
authService.logout();
|
|
||||||
return throwError(() => new Error('توکنی یافت نشد'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return authService.refreshToken().pipe(
|
|
||||||
switchMap((response) => {
|
|
||||||
isRefreshing.next(false);
|
|
||||||
|
|
||||||
// Retry original request with new token
|
|
||||||
const newAuthReq = req.clone({
|
|
||||||
headers: req.headers.set('Authorization', `Bearer ${response.token}`),
|
|
||||||
});
|
|
||||||
|
|
||||||
return next(newAuthReq);
|
|
||||||
}),
|
|
||||||
catchError((refreshError) => {
|
|
||||||
isRefreshing.next(false);
|
|
||||||
authService.logout();
|
|
||||||
return throwError(() => refreshError);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// Wait for refresh to complete, then retry request
|
|
||||||
return isRefreshing.pipe(
|
|
||||||
filter((refreshing) => !refreshing),
|
|
||||||
take(1),
|
|
||||||
switchMap(() => {
|
|
||||||
const token = authService.getToken();
|
|
||||||
const newAuthReq = token
|
|
||||||
? req.clone({
|
|
||||||
headers: req.headers.set('Authorization', `Bearer ${token}`),
|
|
||||||
})
|
|
||||||
: req;
|
|
||||||
|
|
||||||
return next(newAuthReq);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the request should skip authentication
|
|
||||||
*/
|
|
||||||
function shouldSkipAuth(url: string): boolean {
|
|
||||||
const skipAuthUrls = [
|
|
||||||
'/api/auth/login',
|
|
||||||
'/api/auth/register',
|
|
||||||
'/api/auth/forgot-password',
|
|
||||||
'/api/auth/verify-email',
|
|
||||||
'/api/public/',
|
|
||||||
];
|
|
||||||
|
|
||||||
return skipAuthUrls.some((skipUrl) => url.includes(skipUrl));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if this is a refresh token request
|
|
||||||
*/
|
|
||||||
function isRefreshTokenRequest(url: string): boolean {
|
|
||||||
return url.includes('/api/auth/refresh');
|
|
||||||
}
|
|
||||||
@@ -56,12 +56,12 @@ function handleTokenRefresh(authService: AuthService, req: any, next: any): Obse
|
|||||||
return throwError(() => new Error('توکنی یافت نشد'));
|
return throwError(() => new Error('توکنی یافت نشد'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return authService.refreshToken().pipe(
|
return authService.doRefreshToken().pipe(
|
||||||
switchMap((response) => {
|
switchMap((response) => {
|
||||||
isRefreshing.next(false);
|
isRefreshing.next(false);
|
||||||
|
|
||||||
const newAuthReq = req.clone({
|
const newAuthReq = req.clone({
|
||||||
headers: req.headers.set('Authorization', `Bearer ${response.token}`),
|
headers: req.headers.set('Authorization', `Bearer ${response.accessToken}`),
|
||||||
});
|
});
|
||||||
|
|
||||||
return next(newAuthReq);
|
return next(newAuthReq);
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
export interface StockBalance {}
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
export enum UserRole {
|
export enum UserRole {
|
||||||
ADMIN = 'admin',
|
ADMIN = 'admin',
|
||||||
SCHOOL = 'school',
|
PARTNER = 'partner',
|
||||||
TEACHER = 'teacher',
|
POS = 'pos',
|
||||||
STUDENTS = 'students',
|
PROVIDER = 'provider',
|
||||||
GRADER = 'grader',
|
|
||||||
SUPERADMIN = 'superadmin',
|
SUPERADMIN = 'superadmin',
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,12 +31,31 @@ export interface Permission {
|
|||||||
|
|
||||||
export interface IAuthResponse {
|
export interface IAuthResponse {
|
||||||
// user: User;
|
// user: User;
|
||||||
token: string;
|
accessToken: string;
|
||||||
fullName: string;
|
|
||||||
mustChangePassword: boolean;
|
|
||||||
role: string;
|
|
||||||
refreshToken: string;
|
refreshToken: string;
|
||||||
expiresIn: number;
|
account: IAuthAccountResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IAuthAccountResponse {
|
||||||
|
id: string;
|
||||||
|
username: string;
|
||||||
|
type: TRoles;
|
||||||
|
status: string;
|
||||||
|
created_at: string;
|
||||||
|
user_id: string;
|
||||||
|
partner_id?: string;
|
||||||
|
business_id?: string;
|
||||||
|
provider_id?: string;
|
||||||
|
pos_id?: string;
|
||||||
|
user: IAuthAccountUser;
|
||||||
|
}
|
||||||
|
interface IAuthAccountUser {
|
||||||
|
id: string;
|
||||||
|
created_at: string;
|
||||||
|
mobile_number: string;
|
||||||
|
national_code: string;
|
||||||
|
first_name: string;
|
||||||
|
last_name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoginCredentials {
|
export interface LoginCredentials {
|
||||||
|
|||||||
@@ -9,336 +9,301 @@ import { BehaviorSubject, Observable, throwError } from 'rxjs';
|
|||||||
import { catchError, finalize, tap } from 'rxjs/operators';
|
import { catchError, finalize, tap } from 'rxjs/operators';
|
||||||
import { LOCAL_STORAGE_KEYS } from '../../../assets/constants';
|
import { LOCAL_STORAGE_KEYS } from '../../../assets/constants';
|
||||||
import {
|
import {
|
||||||
IAuthResponse,
|
IAuthAccountResponse,
|
||||||
ISignupRequestPayload,
|
IAuthResponse,
|
||||||
IUserLoginInfo,
|
ISignupRequestPayload,
|
||||||
LoginCredentials,
|
IUserLoginInfo,
|
||||||
Maybe,
|
LoginCredentials,
|
||||||
TRoles,
|
Maybe,
|
||||||
User,
|
TRoles,
|
||||||
} from '../models';
|
} from '../models';
|
||||||
import { CaptchaService } from './captcha.service';
|
import { CaptchaService } from './captcha.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.initializeAuth();
|
this.initializeAuth();
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly modulesLoginRoutes = {
|
||||||
|
// ADMIN: ADMIN_API_ROUTES.login(),
|
||||||
|
// SCHOOL: SCHOOLS_API_ROUTES.login(),
|
||||||
|
// TEACHER: TEACHERS_API_ROUTES.login(),
|
||||||
|
} as Record<TRoles, string>;
|
||||||
|
|
||||||
|
readonly modulesSignupRoutes = {
|
||||||
|
// TEACHER: TEACHERS_API_ROUTES.signup(),
|
||||||
|
} as Record<TRoles, string>;
|
||||||
|
|
||||||
|
readonly modulesGetInfoRoutes = {
|
||||||
|
// SCHOOL: SCHOOLS_API_ROUTES.me(),
|
||||||
|
} as Record<TRoles, string>;
|
||||||
|
|
||||||
|
readonly modulesChangeInfoRoutes = {
|
||||||
|
// SCHOOL: SCHOOLS_API_ROUTES.editLoginInfo(),
|
||||||
|
} as Record<TRoles, string>;
|
||||||
|
|
||||||
|
private readonly http = inject(HttpClient);
|
||||||
|
private readonly router = inject(Router);
|
||||||
|
private captchaService = inject(CaptchaService);
|
||||||
|
|
||||||
|
private readonly currentAccountSubject = new BehaviorSubject<Maybe<IAuthAccountResponse>>(null);
|
||||||
|
private readonly isLoadingSubject = new BehaviorSubject<boolean>(false);
|
||||||
|
|
||||||
|
readonly currentUser$ = this.currentAccountSubject.asObservable();
|
||||||
|
readonly isLoading$ = this.isLoadingSubject.asObservable();
|
||||||
|
|
||||||
|
// Signals for reactive state management
|
||||||
|
// readonly currentUser = signal<Maybe<User>>(null);
|
||||||
|
readonly currentAccount = signal<Maybe<IAuthAccountResponse>>(null);
|
||||||
|
readonly isLoading = signal<boolean>(false);
|
||||||
|
readonly token = signal<Maybe<string>>(null);
|
||||||
|
readonly refreshToken = signal<Maybe<string>>(null);
|
||||||
|
readonly isAuthenticated = computed(() => {
|
||||||
|
return Boolean(this.token());
|
||||||
|
});
|
||||||
|
readonly userRole = computed(() => this.currentAccount()?.type);
|
||||||
|
|
||||||
|
private initializeAuth(): void {
|
||||||
|
const token = localStorage.getItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN);
|
||||||
|
|
||||||
|
const accountData = localStorage.getItem(LOCAL_STORAGE_KEYS.USER_DATA);
|
||||||
|
|
||||||
|
if (token && accountData) {
|
||||||
|
try {
|
||||||
|
this.token.set(token);
|
||||||
|
const account = JSON.parse(accountData) as IAuthAccountResponse;
|
||||||
|
this.setCurrentUser(account);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error parsing stored user data:', error);
|
||||||
|
this.logout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
login(credentials: LoginCredentials): Observable<IAuthResponse> {
|
||||||
|
const { username, password, captcha } = credentials;
|
||||||
|
this.isLoading.set(true);
|
||||||
|
this.isLoadingSubject.next(true);
|
||||||
|
const baseHeaders = this.captchaService.buildCaptchaHeaders({}, captcha);
|
||||||
|
|
||||||
|
return this.http
|
||||||
|
.post<IAuthResponse>(
|
||||||
|
'/api/v1/auth/login',
|
||||||
|
{ username, password },
|
||||||
|
{
|
||||||
|
headers: baseHeaders,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.pipe(
|
||||||
|
tap((response) => {
|
||||||
|
this.handleAuthSuccess(response);
|
||||||
|
return response;
|
||||||
|
}),
|
||||||
|
catchError((error) => {
|
||||||
|
console.error('Login error:', error);
|
||||||
|
this.isLoadingSubject.next(false);
|
||||||
|
throw error;
|
||||||
|
}),
|
||||||
|
finalize(() => {
|
||||||
|
this.isLoading.set(false);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
signup(credentials: ISignupRequestPayload, role: TRoles): Observable<IAuthResponse> {
|
||||||
|
this.isLoading.set(true);
|
||||||
|
this.isLoadingSubject.next(true);
|
||||||
|
// const baseHeaders = this.captchaService.buildCaptchaHeaders({}, captcha);
|
||||||
|
|
||||||
|
return this.http
|
||||||
|
.post<IAuthResponse>(
|
||||||
|
this.modulesSignupRoutes[role],
|
||||||
|
credentials,
|
||||||
|
// {
|
||||||
|
// headers: baseHeaders,
|
||||||
|
// },
|
||||||
|
)
|
||||||
|
.pipe(
|
||||||
|
tap((response) => {
|
||||||
|
this.handleAuthSuccess(response);
|
||||||
|
return response;
|
||||||
|
}),
|
||||||
|
catchError((error) => {
|
||||||
|
console.error('Signup error:', error);
|
||||||
|
this.isLoadingSubject.next(false);
|
||||||
|
throw error;
|
||||||
|
}),
|
||||||
|
finalize(() => {
|
||||||
|
this.isLoading.set(false);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
logout(): void {
|
||||||
|
localStorage.removeItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN);
|
||||||
|
localStorage.removeItem(LOCAL_STORAGE_KEYS.USER_DATA);
|
||||||
|
localStorage.removeItem(LOCAL_STORAGE_KEYS.REFRESH_TOKEN);
|
||||||
|
|
||||||
|
this.setCurrentUser(null);
|
||||||
|
this.router.navigate(['/auth']);
|
||||||
|
}
|
||||||
|
|
||||||
|
doRefreshToken(): Observable<IAuthResponse> {
|
||||||
|
const refreshToken = this.getRefreshToken();
|
||||||
|
if (!refreshToken) {
|
||||||
|
this.logout();
|
||||||
|
return throwError(() => new Error('No refresh token available'));
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly modulesLoginRoutes = {
|
return this.http.post<IAuthResponse>('/api/auth/refresh', { refreshToken }).pipe(
|
||||||
// ADMIN: ADMIN_API_ROUTES.login(),
|
tap((response) => {
|
||||||
// SCHOOL: SCHOOLS_API_ROUTES.login(),
|
this.handleAuthSuccess(response);
|
||||||
// TEACHER: TEACHERS_API_ROUTES.login(),
|
}),
|
||||||
} as Record<TRoles, string>;
|
catchError((error) => {
|
||||||
|
console.error('Token refresh error:', error);
|
||||||
readonly modulesSignupRoutes = {
|
this.logout();
|
||||||
// TEACHER: TEACHERS_API_ROUTES.signup(),
|
return throwError(() => error);
|
||||||
} as Record<TRoles, string>;
|
}),
|
||||||
|
|
||||||
readonly modulesGetInfoRoutes = {
|
|
||||||
// SCHOOL: SCHOOLS_API_ROUTES.me(),
|
|
||||||
} as Record<TRoles, string>;
|
|
||||||
|
|
||||||
readonly modulesChangeInfoRoutes = {
|
|
||||||
// SCHOOL: SCHOOLS_API_ROUTES.editLoginInfo(),
|
|
||||||
} as Record<TRoles, string>;
|
|
||||||
|
|
||||||
private readonly http = inject(HttpClient);
|
|
||||||
private readonly router = inject(Router);
|
|
||||||
private captchaService = inject(CaptchaService);
|
|
||||||
|
|
||||||
private readonly currentUserSubject = new BehaviorSubject<Maybe<User>>(
|
|
||||||
null,
|
|
||||||
);
|
);
|
||||||
private readonly isLoadingSubject = new BehaviorSubject<boolean>(false);
|
}
|
||||||
|
|
||||||
readonly currentUser$ = this.currentUserSubject.asObservable();
|
getInfo(role: TRoles): Observable<Partial<IUserLoginInfo>> {
|
||||||
readonly isLoading$ = this.isLoadingSubject.asObservable();
|
// if (this.modulesGetInfoRoutes[role]) {
|
||||||
|
// return this.http.get<any>(this.modulesGetInfoRoutes[role]).pipe(
|
||||||
// Signals for reactive state management
|
// map((data) => {
|
||||||
// readonly currentUser = signal<Maybe<User>>(null);
|
// switch (role) {
|
||||||
readonly currentUser = signal<Maybe<User>>(null);
|
// case 'SCHOOL':
|
||||||
readonly isLoading = signal<boolean>(false);
|
// return this.prepareUserInfoBasedOnRole(role, data as ISchoolMeResponse);
|
||||||
readonly token = signal<Maybe<string>>(null);
|
// default:
|
||||||
readonly isAuthenticated = computed(() => {
|
// return data as Partial<IUserLoginInfo>;
|
||||||
return Boolean(this.token());
|
// }
|
||||||
});
|
// }),
|
||||||
readonly userRole = computed(() => this.currentUser()?.role);
|
// catchError((err) => {
|
||||||
|
// console.error('GetInfo error:', err);
|
||||||
private initializeAuth(): void {
|
// return throwError(() => err);
|
||||||
const token = localStorage.getItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN);
|
// }),
|
||||||
|
// );
|
||||||
const userData = localStorage.getItem(LOCAL_STORAGE_KEYS.USER_DATA);
|
|
||||||
|
|
||||||
if (token && userData) {
|
|
||||||
try {
|
|
||||||
this.token.set(token);
|
|
||||||
const user = JSON.parse(userData) as User;
|
|
||||||
this.setCurrentUser(user);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error parsing stored user data:', error);
|
|
||||||
this.logout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
login(
|
|
||||||
credentials: LoginCredentials,
|
|
||||||
role: TRoles,
|
|
||||||
): Observable<IAuthResponse> {
|
|
||||||
const { username, password, captcha } = credentials;
|
|
||||||
this.isLoading.set(true);
|
|
||||||
this.isLoadingSubject.next(true);
|
|
||||||
const baseHeaders = this.captchaService.buildCaptchaHeaders(
|
|
||||||
{},
|
|
||||||
captcha,
|
|
||||||
);
|
|
||||||
|
|
||||||
return this.http
|
|
||||||
.post<IAuthResponse>(
|
|
||||||
this.modulesLoginRoutes[role],
|
|
||||||
{ username, password },
|
|
||||||
{
|
|
||||||
headers: baseHeaders,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.pipe(
|
|
||||||
tap((response) => {
|
|
||||||
this.handleAuthSuccess(response);
|
|
||||||
return response;
|
|
||||||
}),
|
|
||||||
catchError((error) => {
|
|
||||||
console.error('Login error:', error);
|
|
||||||
this.isLoadingSubject.next(false);
|
|
||||||
throw error;
|
|
||||||
}),
|
|
||||||
finalize(() => {
|
|
||||||
this.isLoading.set(false);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
signup(
|
|
||||||
credentials: ISignupRequestPayload,
|
|
||||||
role: TRoles,
|
|
||||||
): Observable<IAuthResponse> {
|
|
||||||
this.isLoading.set(true);
|
|
||||||
this.isLoadingSubject.next(true);
|
|
||||||
// const baseHeaders = this.captchaService.buildCaptchaHeaders({}, captcha);
|
|
||||||
|
|
||||||
return this.http
|
|
||||||
.post<IAuthResponse>(
|
|
||||||
this.modulesSignupRoutes[role],
|
|
||||||
credentials,
|
|
||||||
// {
|
|
||||||
// headers: baseHeaders,
|
|
||||||
// },
|
|
||||||
)
|
|
||||||
.pipe(
|
|
||||||
tap((response) => {
|
|
||||||
this.handleAuthSuccess(response);
|
|
||||||
return response;
|
|
||||||
}),
|
|
||||||
catchError((error) => {
|
|
||||||
console.error('Signup error:', error);
|
|
||||||
this.isLoadingSubject.next(false);
|
|
||||||
throw error;
|
|
||||||
}),
|
|
||||||
finalize(() => {
|
|
||||||
this.isLoading.set(false);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
logout(): void {
|
|
||||||
localStorage.removeItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN);
|
|
||||||
localStorage.removeItem(LOCAL_STORAGE_KEYS.USER_DATA);
|
|
||||||
localStorage.removeItem(LOCAL_STORAGE_KEYS.REFRESH_TOKEN);
|
|
||||||
|
|
||||||
this.setCurrentUser(null);
|
|
||||||
this.router.navigate(['/auth']);
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshToken(): Observable<IAuthResponse> {
|
|
||||||
const refreshToken = this.getRefreshToken();
|
|
||||||
if (!refreshToken) {
|
|
||||||
this.logout();
|
|
||||||
return throwError(() => new Error('No refresh token available'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.http
|
|
||||||
.post<IAuthResponse>('/api/auth/refresh', { refreshToken })
|
|
||||||
.pipe(
|
|
||||||
tap((response) => {
|
|
||||||
this.handleAuthSuccess(response);
|
|
||||||
}),
|
|
||||||
catchError((error) => {
|
|
||||||
console.error('Token refresh error:', error);
|
|
||||||
this.logout();
|
|
||||||
return throwError(() => error);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
getInfo(role: TRoles): Observable<Partial<IUserLoginInfo>> {
|
|
||||||
// if (this.modulesGetInfoRoutes[role]) {
|
|
||||||
// return this.http.get<any>(this.modulesGetInfoRoutes[role]).pipe(
|
|
||||||
// map((data) => {
|
|
||||||
// switch (role) {
|
|
||||||
// case 'SCHOOL':
|
|
||||||
// return this.prepareUserInfoBasedOnRole(role, data as ISchoolMeResponse);
|
|
||||||
// default:
|
|
||||||
// return data as Partial<IUserLoginInfo>;
|
|
||||||
// }
|
|
||||||
// }),
|
|
||||||
// catchError((err) => {
|
|
||||||
// console.error('GetInfo error:', err);
|
|
||||||
// return throwError(() => err);
|
|
||||||
// }),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
return throwError(() => new Error('متاسفانه مشکلی پیش آمده'));
|
|
||||||
}
|
|
||||||
changeInfo(
|
|
||||||
credentials: IUserLoginInfo,
|
|
||||||
role: TRoles,
|
|
||||||
): Observable<IAuthResponse> {
|
|
||||||
return this.http.post<IAuthResponse>(
|
|
||||||
this.modulesChangeInfoRoutes[role],
|
|
||||||
credentials,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// prepareUserInfoBasedOnRole(role: TRoles, info: ISchoolMeResponse): Partial<IUserLoginInfo> {
|
|
||||||
// if (role === 'SCHOOL') {
|
|
||||||
// return {
|
|
||||||
// username: info.username,
|
|
||||||
// email: info.managerInfo.email,
|
|
||||||
// mobile: info.managerInfo.mobile,
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
// return {};
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
return throwError(() => new Error('متاسفانه مشکلی پیش آمده'));
|
||||||
* Get current access token
|
}
|
||||||
*/
|
changeInfo(credentials: IUserLoginInfo, role: TRoles): Observable<IAuthResponse> {
|
||||||
getToken(): Maybe<string> {
|
return this.http.post<IAuthResponse>(this.modulesChangeInfoRoutes[role], credentials);
|
||||||
return localStorage.getItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN);
|
}
|
||||||
|
|
||||||
|
// prepareUserInfoBasedOnRole(role: TRoles, info: ISchoolMeResponse): Partial<IUserLoginInfo> {
|
||||||
|
// if (role === 'SCHOOL') {
|
||||||
|
// return {
|
||||||
|
// username: info.username,
|
||||||
|
// email: info.managerInfo.email,
|
||||||
|
// mobile: info.managerInfo.mobile,
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// return {};
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current access token
|
||||||
|
*/
|
||||||
|
getToken(): Maybe<string> {
|
||||||
|
return localStorage.getItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current refresh token
|
||||||
|
*/
|
||||||
|
getRefreshToken(): Maybe<string> {
|
||||||
|
return localStorage.getItem(LOCAL_STORAGE_KEYS.REFRESH_TOKEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if token is expired (optional - requires JWT parsing)
|
||||||
|
*/
|
||||||
|
isTokenExpired(): boolean {
|
||||||
|
const token = this.getToken();
|
||||||
|
if (!token) return true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Parse JWT token to check expiration
|
||||||
|
const payload = JSON.parse(atob(token.split('.')[1]));
|
||||||
|
const currentTime = Math.floor(Date.now() / 1000);
|
||||||
|
return payload.exp < currentTime;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error parsing token:', error);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if refresh token is expired
|
||||||
|
*/
|
||||||
|
isRefreshTokenExpired(): boolean {
|
||||||
|
const refreshToken = this.getRefreshToken();
|
||||||
|
if (!refreshToken) return true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Parse JWT refresh token to check expiration
|
||||||
|
const payload = JSON.parse(atob(refreshToken.split('.')[1]));
|
||||||
|
const currentTime = Math.floor(Date.now() / 1000);
|
||||||
|
return payload.exp < currentTime;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error parsing refresh token:', error);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hasRole(role: TRoles): boolean {
|
||||||
|
return this.currentAccount()?.type === role;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasAnyRole(roles: TRoles[]): boolean {
|
||||||
|
const currentRole = this.currentAccount()?.type;
|
||||||
|
return currentRole ? roles.includes(currentRole) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasPermission(permission: string): boolean {
|
||||||
|
const user = this.currentAccount();
|
||||||
|
if (!user) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
// return user.permissions.some(
|
||||||
|
// (p) => p.name === permission || `${p.resource}:${p.action}` === permission,
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
|
||||||
|
canAccess(requiredRoles?: TRoles[], requiredPermissions?: string[]): boolean {
|
||||||
|
if (!this.isAuthenticated()) return false;
|
||||||
|
|
||||||
|
if (requiredRoles && requiredRoles.length > 0) {
|
||||||
|
if (!this.hasAnyRole(requiredRoles)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if (requiredPermissions && requiredPermissions.length > 0) {
|
||||||
* Get current refresh token
|
return requiredPermissions.every((permission) => this.hasPermission(permission));
|
||||||
*/
|
|
||||||
getRefreshToken(): Maybe<string> {
|
|
||||||
return localStorage.getItem(LOCAL_STORAGE_KEYS.REFRESH_TOKEN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return true;
|
||||||
* Check if token is expired (optional - requires JWT parsing)
|
}
|
||||||
*/
|
|
||||||
isTokenExpired(): boolean {
|
|
||||||
const token = this.getToken();
|
|
||||||
if (!token) return true;
|
|
||||||
|
|
||||||
try {
|
private handleAuthSuccess(response: IAuthResponse): void {
|
||||||
// Parse JWT token to check expiration
|
localStorage.setItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN, response.accessToken);
|
||||||
const payload = JSON.parse(atob(token.split('.')[1]));
|
this.token.set(response.accessToken);
|
||||||
const currentTime = Math.floor(Date.now() / 1000);
|
this.refreshToken.set(response.refreshToken);
|
||||||
return payload.exp < currentTime;
|
localStorage.setItem(LOCAL_STORAGE_KEYS.REFRESH_TOKEN, response.refreshToken);
|
||||||
} catch (error) {
|
|
||||||
console.error('Error parsing token:', error);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
this.setCurrentUser(response.account);
|
||||||
* Check if refresh token is expired
|
this.isLoadingSubject.next(false);
|
||||||
*/
|
|
||||||
isRefreshTokenExpired(): boolean {
|
|
||||||
const refreshToken = this.getRefreshToken();
|
|
||||||
if (!refreshToken) return true;
|
|
||||||
|
|
||||||
try {
|
// Navigate based on user role
|
||||||
// Parse JWT refresh token to check expiration
|
// this.navigateByRole(response.user.role);
|
||||||
const payload = JSON.parse(atob(refreshToken.split('.')[1]));
|
}
|
||||||
const currentTime = Math.floor(Date.now() / 1000);
|
|
||||||
return payload.exp < currentTime;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error parsing refresh token:', error);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hasRole(role: TRoles): boolean {
|
private setCurrentUser(account: Maybe<IAuthAccountResponse>): void {
|
||||||
return this.currentUser()?.role === role;
|
this.currentAccount.set(account);
|
||||||
}
|
this.currentAccountSubject.next(account);
|
||||||
|
localStorage.setItem(LOCAL_STORAGE_KEYS.USER_DATA, JSON.stringify(account));
|
||||||
hasAnyRole(roles: TRoles[]): boolean {
|
}
|
||||||
const currentRole = this.currentUser()?.role;
|
|
||||||
return currentRole ? roles.includes(currentRole) : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasPermission(permission: string): boolean {
|
|
||||||
const user = this.currentUser();
|
|
||||||
if (!user) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
// return user.permissions.some(
|
|
||||||
// (p) => p.name === permission || `${p.resource}:${p.action}` === permission,
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
|
|
||||||
canAccess(
|
|
||||||
requiredRoles?: TRoles[],
|
|
||||||
requiredPermissions?: string[],
|
|
||||||
): boolean {
|
|
||||||
if (!this.isAuthenticated()) return false;
|
|
||||||
|
|
||||||
if (requiredRoles && requiredRoles.length > 0) {
|
|
||||||
if (!this.hasAnyRole(requiredRoles)) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (requiredPermissions && requiredPermissions.length > 0) {
|
|
||||||
return requiredPermissions.every((permission) =>
|
|
||||||
this.hasPermission(permission),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleAuthSuccess(response: IAuthResponse): void {
|
|
||||||
localStorage.setItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN, response.token);
|
|
||||||
this.token.set(response.token);
|
|
||||||
// localStorage.setItem('refresh_token', response.refreshToken);
|
|
||||||
const user = {
|
|
||||||
fullName: response.fullName,
|
|
||||||
role: response.role as TRoles,
|
|
||||||
};
|
|
||||||
|
|
||||||
localStorage.setItem(
|
|
||||||
LOCAL_STORAGE_KEYS.USER_DATA,
|
|
||||||
JSON.stringify(user),
|
|
||||||
);
|
|
||||||
|
|
||||||
this.setCurrentUser(user);
|
|
||||||
// this.isLoading.set(false);
|
|
||||||
this.currentUser.set({
|
|
||||||
fullName: response.fullName,
|
|
||||||
role: response.role as TRoles,
|
|
||||||
});
|
|
||||||
this.isLoadingSubject.next(false);
|
|
||||||
|
|
||||||
// Navigate based on user role
|
|
||||||
// this.navigateByRole(response.user.role);
|
|
||||||
}
|
|
||||||
|
|
||||||
private setCurrentUser(user: Maybe<User>): void {
|
|
||||||
this.currentUser.set(user);
|
|
||||||
this.currentUserSubject.next(user);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,20 @@ import { IPaginatedQuery, IResponseMetadata } from '../models/service.model';
|
|||||||
/**
|
/**
|
||||||
* Base interface for all state objects
|
* Base interface for all state objects
|
||||||
*/
|
*/
|
||||||
export interface BaseState<T = any> {
|
export interface BaseState {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: Maybe<string>;
|
error: Maybe<string>;
|
||||||
isRefreshing?: boolean;
|
isRefreshing?: boolean;
|
||||||
initialized: boolean;
|
initialized: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base interface for entity
|
||||||
|
*/
|
||||||
|
export interface EntityState<T = any> extends BaseState {
|
||||||
|
entity: Maybe<T>;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base interface for paginated lists
|
* Base interface for paginated lists
|
||||||
*/
|
*/
|
||||||
@@ -29,7 +36,7 @@ export interface PaginatedState<T = any> extends BaseState {
|
|||||||
/**
|
/**
|
||||||
* Base interface for entity states (CRUD operations)
|
* Base interface for entity states (CRUD operations)
|
||||||
*/
|
*/
|
||||||
export interface EntityState<T = any> extends BaseState {
|
export interface EntitiesState<T = any> extends BaseState {
|
||||||
entities: Record<string | number, T>;
|
entities: Record<string | number, T>;
|
||||||
selectedId: Maybe<string | number>;
|
selectedId: Maybe<string | number>;
|
||||||
ids: (string | number)[];
|
ids: (string | number)[];
|
||||||
@@ -158,11 +165,31 @@ export abstract class BaseStore<T extends BaseState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity store with CRUD operations
|
* Entity store
|
||||||
*/
|
*/
|
||||||
export abstract class EntityStore<
|
export abstract class EntityStore<
|
||||||
T,
|
T,
|
||||||
TState extends EntityState<T> = EntityState<T>,
|
TState extends EntityState<T> = EntityState<T>,
|
||||||
|
> extends BaseStore<TState> {
|
||||||
|
// Computed selectors
|
||||||
|
readonly entity = computed(() => this._state().entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set entity
|
||||||
|
*/
|
||||||
|
setEntity(entity: Maybe<T>): void {
|
||||||
|
this.patchState({
|
||||||
|
entity,
|
||||||
|
} as Partial<TState>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity store with CRUD operations
|
||||||
|
*/
|
||||||
|
export abstract class EntitiesStore<
|
||||||
|
T,
|
||||||
|
TState extends EntitiesState<T> = EntitiesState<T>,
|
||||||
> extends BaseStore<TState> {
|
> extends BaseStore<TState> {
|
||||||
// Computed selectors
|
// Computed selectors
|
||||||
readonly entities = computed(() => this._state().entities);
|
readonly entities = computed(() => this._state().entities);
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ export * from './base-store';
|
|||||||
// Global state management
|
// Global state management
|
||||||
export * from './global/global.store';
|
export * from './global/global.store';
|
||||||
|
|
||||||
// State effects and utilities
|
// // State effects and utilities
|
||||||
export * from './state-effects.service';
|
// export * from './state-effects.service';
|
||||||
|
|
||||||
// State management interfaces
|
// State management interfaces
|
||||||
export type {
|
export type {
|
||||||
Action,
|
Action,
|
||||||
BaseState,
|
BaseState,
|
||||||
|
EntitiesState,
|
||||||
EntityState,
|
EntityState,
|
||||||
LoadingState,
|
LoadingState,
|
||||||
PaginatedState,
|
PaginatedState,
|
||||||
|
|||||||
@@ -1,326 +0,0 @@
|
|||||||
import { Injectable, inject } from '@angular/core';
|
|
||||||
import { combineLatest, map, shareReplay, startWith } from 'rxjs';
|
|
||||||
import { LOCAL_STORAGE_KEYS } from 'src/assets/constants';
|
|
||||||
import { AuthStore } from '../../modules/auth/state/auth.store';
|
|
||||||
import { GlobalStore } from './global/global.store';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* State effects service for handling cross-store interactions
|
|
||||||
*/
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root',
|
|
||||||
})
|
|
||||||
export class StateEffects {
|
|
||||||
private readonly authStore = inject(AuthStore);
|
|
||||||
private readonly globalStore = inject(GlobalStore);
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.initializeEffects();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize all effects
|
|
||||||
*/
|
|
||||||
private initializeEffects(): void {
|
|
||||||
this.setupAuthEffects();
|
|
||||||
this.setupGlobalEffects();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup authentication-related effects
|
|
||||||
*/
|
|
||||||
private setupAuthEffects(): void {
|
|
||||||
// Update global notifications when auth state changes
|
|
||||||
this.authStore.state$.subscribe((authState) => {
|
|
||||||
// if (authState.isAuthenticated && authState.user) {
|
|
||||||
// this.globalStore.addNotification({
|
|
||||||
// type: 'success',
|
|
||||||
// title: 'خوش آمدید',
|
|
||||||
// message: `${authState.user.firstName} ${authState.user.lastName} عزیز، خوش آمدید`,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle session expiry warnings
|
|
||||||
this.authStore.state$.subscribe((authState) => {
|
|
||||||
if (authState.sessionExpiry) {
|
|
||||||
const timeUntilExpiry = authState.sessionExpiry - Date.now();
|
|
||||||
const minutesUntilExpiry = Math.floor(timeUntilExpiry / 60000);
|
|
||||||
|
|
||||||
// Show warning when 5 minutes remain
|
|
||||||
if (minutesUntilExpiry === 5) {
|
|
||||||
this.globalStore.addNotification({
|
|
||||||
type: 'warning',
|
|
||||||
title: 'هشدار انقضای جلسه',
|
|
||||||
message: 'جلسه شما در 5 دقیقه منقضی میشود',
|
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
label: 'تمدید جلسه',
|
|
||||||
action: () => this.authStore.refreshAuthToken().subscribe(),
|
|
||||||
type: 'primary',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup global effects
|
|
||||||
*/
|
|
||||||
private setupGlobalEffects(): void {
|
|
||||||
// Auto-save preferences when they change
|
|
||||||
this.globalStore.state$.subscribe((globalState) => {
|
|
||||||
localStorage.setItem('user_preferences', JSON.stringify(globalState.preferences));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle theme changes
|
|
||||||
this.globalStore.state$.subscribe((globalState) => {
|
|
||||||
document.documentElement.setAttribute('data-theme', globalState.theme);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle language changes
|
|
||||||
this.globalStore.state$.subscribe((globalState) => {
|
|
||||||
document.documentElement.setAttribute('lang', globalState.language);
|
|
||||||
document.documentElement.setAttribute('dir', globalState.language === 'fa' ? 'rtl' : 'ltr');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* State selectors for complex cross-store queries
|
|
||||||
*/
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root',
|
|
||||||
})
|
|
||||||
export class StateSelectors {
|
|
||||||
private readonly authStore = inject(AuthStore);
|
|
||||||
private readonly globalStore = inject(GlobalStore);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Combined application state for UI components
|
|
||||||
*/
|
|
||||||
readonly appState$ = combineLatest([this.authStore.state$, this.globalStore.state$]).pipe(
|
|
||||||
map(([authState, globalState]) => ({
|
|
||||||
isAuthenticated: authState.isAuthenticated,
|
|
||||||
user: authState.user,
|
|
||||||
userRole: authState.user?.role,
|
|
||||||
loading: authState.loading || globalState.loading,
|
|
||||||
sidebarCollapsed: globalState.sidebarCollapsed,
|
|
||||||
theme: globalState.theme,
|
|
||||||
language: globalState.language,
|
|
||||||
notifications: globalState.notifications,
|
|
||||||
unreadCount: globalState.notifications.filter((n) => !n.read).length,
|
|
||||||
breadcrumbs: globalState.breadcrumbs,
|
|
||||||
isOnline: globalState.isOnline,
|
|
||||||
})),
|
|
||||||
shareReplay(1),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User permissions combined with role-based access
|
|
||||||
*/
|
|
||||||
readonly userAccess$ = this.authStore.state$.pipe(
|
|
||||||
map((authState) => ({
|
|
||||||
isAuthenticated: authState.isAuthenticated,
|
|
||||||
role: authState.user?.role,
|
|
||||||
permissions: authState.permissions,
|
|
||||||
canAccessAdmin: authState.user?.role === 'ADMIN' || authState.user?.role === 'SUPERADMIN',
|
|
||||||
canAccessStudent: authState.user?.role === 'STUDENTS',
|
|
||||||
canAccessGrader: authState.user?.role === 'GRADER',
|
|
||||||
canAccessSchools: authState.user?.role === 'SCHOOL',
|
|
||||||
canAccessSuperAdmin: authState.user?.role === 'SUPERADMIN',
|
|
||||||
})),
|
|
||||||
shareReplay(1),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Navigation state for header/sidebar components
|
|
||||||
*/
|
|
||||||
readonly navigationState$ = combineLatest([this.authStore.state$, this.globalStore.state$]).pipe(
|
|
||||||
map(([authState, globalState]) => ({
|
|
||||||
user: authState.user,
|
|
||||||
sidebarCollapsed: globalState.sidebarCollapsed,
|
|
||||||
breadcrumbs: globalState.breadcrumbs,
|
|
||||||
// userInitials: authState.user
|
|
||||||
// ? `${authState.user.firstName[0]}${authState.user.lastName[0]}`
|
|
||||||
// : '',
|
|
||||||
// userFullName: authState.user ? `${authState.user.firstName} ${authState.user.lastName}` : '',
|
|
||||||
})),
|
|
||||||
shareReplay(1),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notification state for notification components
|
|
||||||
*/
|
|
||||||
readonly notificationState$ = this.globalStore.state$.pipe(
|
|
||||||
map((globalState) => ({
|
|
||||||
notifications: globalState.notifications,
|
|
||||||
unreadCount: globalState.notifications.filter((n) => !n.read).length,
|
|
||||||
hasUnread: globalState.notifications.some((n) => !n.read),
|
|
||||||
recentNotifications: globalState.notifications
|
|
||||||
.sort((a, b) => b.timestamp - a.timestamp)
|
|
||||||
.slice(0, 5),
|
|
||||||
})),
|
|
||||||
shareReplay(1),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loading state across all stores
|
|
||||||
*/
|
|
||||||
readonly loadingState$ = combineLatest([this.authStore.state$, this.globalStore.state$]).pipe(
|
|
||||||
map(([authState, globalState]) => ({
|
|
||||||
isLoading: authState.loading || globalState.loading,
|
|
||||||
authLoading: authState.loading,
|
|
||||||
globalLoading: globalState.loading,
|
|
||||||
})),
|
|
||||||
startWith({ isLoading: false, authLoading: false, globalLoading: false }),
|
|
||||||
shareReplay(1),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* State utilities for common operations
|
|
||||||
*/
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root',
|
|
||||||
})
|
|
||||||
export class StateUtils {
|
|
||||||
private readonly authStore = inject(AuthStore);
|
|
||||||
private readonly globalStore = inject(GlobalStore);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if user can access route
|
|
||||||
*/
|
|
||||||
canAccessRoute(requiredRoles?: string[], requiredPermissions?: string[]): boolean {
|
|
||||||
const authState = this.authStore.getCurrentState();
|
|
||||||
|
|
||||||
if (!authState.isAuthenticated) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (requiredRoles && requiredRoles.length > 0) {
|
|
||||||
const userRole = authState.user?.role;
|
|
||||||
if (!userRole || !requiredRoles.includes(userRole)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (requiredPermissions && requiredPermissions.length > 0) {
|
|
||||||
const hasAllPermissions = requiredPermissions.every((permission) =>
|
|
||||||
authState.permissions.includes(permission),
|
|
||||||
);
|
|
||||||
if (!hasAllPermissions) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show success message
|
|
||||||
*/
|
|
||||||
showSuccess(title: string, message: string): void {
|
|
||||||
this.globalStore.addNotification({
|
|
||||||
type: 'success',
|
|
||||||
title,
|
|
||||||
message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show error message
|
|
||||||
*/
|
|
||||||
showError(title: string, message: string): void {
|
|
||||||
this.globalStore.addNotification({
|
|
||||||
type: 'error',
|
|
||||||
title,
|
|
||||||
message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show warning message
|
|
||||||
*/
|
|
||||||
showWarning(title: string, message: string): void {
|
|
||||||
this.globalStore.addNotification({
|
|
||||||
type: 'warning',
|
|
||||||
title,
|
|
||||||
message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show info message
|
|
||||||
*/
|
|
||||||
showInfo(title: string, message: string): void {
|
|
||||||
this.globalStore.addNotification({
|
|
||||||
type: 'info',
|
|
||||||
title,
|
|
||||||
message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update page breadcrumbs
|
|
||||||
*/
|
|
||||||
setBreadcrumbs(breadcrumbs: Array<{ label: string; url?: string; icon?: string }>): void {
|
|
||||||
this.globalStore.setBreadcrumbs(breadcrumbs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get user display name
|
|
||||||
*/
|
|
||||||
getUserDisplayName(): string {
|
|
||||||
const user = this.authStore.getCurrentState().user;
|
|
||||||
return '';
|
|
||||||
// return user ? `${user.firstName} ${user.lastName}` : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get user initials
|
|
||||||
*/
|
|
||||||
getUserInitials(): string {
|
|
||||||
const user = this.authStore.getCurrentState().user;
|
|
||||||
return '';
|
|
||||||
// return user ? `${user.firstName[0]}${user.lastName[0]}` : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if user is online
|
|
||||||
*/
|
|
||||||
isOnline(): boolean {
|
|
||||||
return this.globalStore.getCurrentState().isOnline;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get current theme
|
|
||||||
*/
|
|
||||||
getCurrentTheme(): 'light' | 'dark' {
|
|
||||||
return this.globalStore.getCurrentState().theme;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get current language
|
|
||||||
*/
|
|
||||||
getCurrentLanguage(): 'fa' | 'en' {
|
|
||||||
return this.globalStore.getCurrentState().language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear all application state (useful for logout)
|
|
||||||
*/
|
|
||||||
clearAllState(): void {
|
|
||||||
this.authStore.reset();
|
|
||||||
this.globalStore.reset();
|
|
||||||
|
|
||||||
// Clear localStorage
|
|
||||||
localStorage.removeItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN);
|
|
||||||
localStorage.removeItem(LOCAL_STORAGE_KEYS.REFRESH_TOKEN);
|
|
||||||
localStorage.removeItem(LOCAL_STORAGE_KEYS.USER_DATA);
|
|
||||||
localStorage.removeItem(LOCAL_STORAGE_KEYS.LAST_LOGIN_TIME);
|
|
||||||
localStorage.removeItem(LOCAL_STORAGE_KEYS.LOGIN_ATTEMPTS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<p-dialog header="دستهبندی کالاها" [(visible)]="visible" [modal]="true" [style]="{ width: '500px' }" [closable]="true">
|
||||||
|
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||||
|
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||||
|
|
||||||
|
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
|
||||||
|
</form>
|
||||||
|
</p-dialog>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||||
|
import { InputComponent } from '@/shared/components';
|
||||||
|
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||||
|
import { Component, inject, Input } from '@angular/core';
|
||||||
|
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
|
import { Dialog } from 'primeng/dialog';
|
||||||
|
|
||||||
|
import { IGoodCategoriesResponse, IGoodCategoryRequest } from '../../models';
|
||||||
|
import { GuildGoodCategoriesService } from '../../services/goodCategories.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'admin-guild-good-categories-form',
|
||||||
|
templateUrl: './form.component.html',
|
||||||
|
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||||
|
})
|
||||||
|
export class GuildGoodCategoryFormComponent extends AbstractFormDialog<
|
||||||
|
IGoodCategoryRequest,
|
||||||
|
IGoodCategoriesResponse
|
||||||
|
> {
|
||||||
|
@Input() guildId!: string;
|
||||||
|
@Input() categoryId?: string;
|
||||||
|
|
||||||
|
private service = inject(GuildGoodCategoriesService);
|
||||||
|
|
||||||
|
form = this.fb.group({
|
||||||
|
name: [this.initialValues?.name || '', [Validators.required]],
|
||||||
|
});
|
||||||
|
|
||||||
|
override submitForm(payload: IGoodCategoryRequest) {
|
||||||
|
if (this.editMode) {
|
||||||
|
return this.service.update(this.guildId!, this.categoryId!, payload);
|
||||||
|
}
|
||||||
|
return this.service.create(this.guildId!, payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<app-page-data-list
|
||||||
|
[pageTitle]="'مدیریت دستهبندیهای کالا'"
|
||||||
|
[addNewCtaLabel]="'افزودن دستهبندی جدید'"
|
||||||
|
[columns]="columns"
|
||||||
|
[showAdd]="true"
|
||||||
|
emptyPlaceholderTitle="دستهبندی یافت نشد"
|
||||||
|
emptyPlaceholderDescription="برای افزودن دستهبندی جدید، روی دکمهٔ بالا کلیک کنید."
|
||||||
|
[items]="items()"
|
||||||
|
[loading]="loading()"
|
||||||
|
[showDetails]="true"
|
||||||
|
[showAdd]="true"
|
||||||
|
[showEdit]="true"
|
||||||
|
[fullHeight]="fullHeight"
|
||||||
|
(onEdit)="onEditClick($event)"
|
||||||
|
(onAdd)="openAddForm()"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<admin-guild-good-categories-form
|
||||||
|
[(visible)]="visibleForm"
|
||||||
|
[initialValues]="selectedItemForEdit() || undefined"
|
||||||
|
[categoryId]="selectedItemForEdit()?.id"
|
||||||
|
[guildId]="guildId"
|
||||||
|
[editMode]="editMode()"
|
||||||
|
(onSubmit)="refresh()"
|
||||||
|
/>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||||
|
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||||
|
import {
|
||||||
|
IColumn,
|
||||||
|
PageDataListComponent,
|
||||||
|
} from '@/shared/components/pageDataList/page-data-list.component';
|
||||||
|
import { Component, inject, Input } from '@angular/core';
|
||||||
|
import { IGoodCategoriesResponse } from '../../models';
|
||||||
|
import { GuildGoodCategoriesService } from '../../services/goodCategories.service';
|
||||||
|
import { GuildGoodCategoryFormComponent } from './form.component';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'admin-guild-good-categories-list',
|
||||||
|
templateUrl: './list.component.html',
|
||||||
|
imports: [PageDataListComponent, GuildGoodCategoryFormComponent],
|
||||||
|
})
|
||||||
|
export class GuildGoodCategoriesListComponent extends AbstractList<IGoodCategoriesResponse> {
|
||||||
|
@Input() guildId!: string;
|
||||||
|
@Input() fullHeight?: boolean;
|
||||||
|
@Input() header: IColumn[] = [
|
||||||
|
{ field: 'id', header: 'شناسه' },
|
||||||
|
{ field: 'name', header: 'عنوان' },
|
||||||
|
{
|
||||||
|
field: 'created_at',
|
||||||
|
header: 'تاریخ ایجاد',
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
service = inject(GuildGoodCategoriesService);
|
||||||
|
|
||||||
|
override setColumns(): void {
|
||||||
|
this.columns = this.header;
|
||||||
|
}
|
||||||
|
|
||||||
|
override getDataRequest() {
|
||||||
|
return this.service.getAll(this.guildId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<p-dialog header="فرم صنف" [(visible)]="visible" [modal]="true" [style]="{ width: '500px' }" [closable]="true" ()>
|
||||||
|
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||||
|
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||||
|
<app-input label="کد" [control]="form.controls.code" name="code" />
|
||||||
|
|
||||||
|
{{ editMode }}
|
||||||
|
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||||
|
</form>
|
||||||
|
</p-dialog>
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||||
|
import { InputComponent } from '@/shared/components';
|
||||||
|
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||||
|
import { Component, inject, Input } from '@angular/core';
|
||||||
|
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
|
import { Dialog } from 'primeng/dialog';
|
||||||
|
import { IGuildRequest, IGuildResponse } from '../models';
|
||||||
|
import { GuildsService } from '../services/main.service';
|
||||||
|
|
||||||
|
interface T {
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'admin-guild-form',
|
||||||
|
templateUrl: './form.component.html',
|
||||||
|
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||||
|
})
|
||||||
|
export class GuildFormComponent extends AbstractFormDialog<IGuildRequest, IGuildResponse> {
|
||||||
|
@Input() guildId?: string;
|
||||||
|
private service = inject(GuildsService);
|
||||||
|
|
||||||
|
form = this.fb.group({
|
||||||
|
name: [
|
||||||
|
{ value: this.initialValues?.name, disabled: this.submitLoading() },
|
||||||
|
Validators.required,
|
||||||
|
],
|
||||||
|
code: [
|
||||||
|
{ value: this.initialValues?.code, disabled: this.submitLoading() },
|
||||||
|
Validators.required,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
override ngOnChanges() {
|
||||||
|
this.form.patchValue(this.initialValues ?? {});
|
||||||
|
if (this.editMode && !this.guildId) {
|
||||||
|
throw 'missing some arguments';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initForm() {
|
||||||
|
// const form = this.fb.group({
|
||||||
|
// name: [
|
||||||
|
// { value: this.initialValues?.name, disabled: !this.initialValues?.name },
|
||||||
|
// Validators.required,
|
||||||
|
// ],
|
||||||
|
// code: [
|
||||||
|
// { value: this.initialValues?.code, disabled: this.submitLoading() },
|
||||||
|
// Validators.required,
|
||||||
|
// ],
|
||||||
|
// });
|
||||||
|
// this.code = form.get<string>('code')!.valueChanges.pipe(
|
||||||
|
// tap((code) => {
|
||||||
|
// const nameControl = form.get('name');
|
||||||
|
// code === '1234' ? nameControl?.disable() : nameControl?.enable();
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
// return form;
|
||||||
|
}
|
||||||
|
|
||||||
|
override submitForm(payload: IGuildRequest) {
|
||||||
|
if (this.editMode) {
|
||||||
|
return this.service.update(this.guildId!, payload);
|
||||||
|
}
|
||||||
|
return this.service.create(payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<p-dialog header="فرم صنف" [(visible)]="visible" [modal]="true" [style]="{ width: '500px' }" [closable]="true">
|
||||||
|
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||||
|
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||||
|
|
||||||
|
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||||
|
</form>
|
||||||
|
</p-dialog>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||||
|
import { InputComponent } from '@/shared/components';
|
||||||
|
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||||
|
import { Component, inject, Input } from '@angular/core';
|
||||||
|
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
|
import { Dialog } from 'primeng/dialog';
|
||||||
|
|
||||||
|
import { IGuildGoodRequest, IGuildGoodsResponse } from '../../models';
|
||||||
|
import { GuildGoodsService } from '../../services/goods.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'admin-guild-good-form',
|
||||||
|
templateUrl: './form.component.html',
|
||||||
|
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||||
|
})
|
||||||
|
export class GuildGoodCategoryFormComponent extends AbstractFormDialog<
|
||||||
|
IGuildGoodRequest,
|
||||||
|
IGuildGoodsResponse
|
||||||
|
> {
|
||||||
|
@Input() guildId!: string;
|
||||||
|
@Input() categoryId?: string;
|
||||||
|
|
||||||
|
private service = inject(GuildGoodsService);
|
||||||
|
|
||||||
|
form = this.fb.group({
|
||||||
|
name: [this.initialValues?.name || '', [Validators.required]],
|
||||||
|
});
|
||||||
|
|
||||||
|
override submitForm(payload: IGuildGoodRequest) {
|
||||||
|
if (this.editMode) {
|
||||||
|
return this.service.update(this.guildId, this.categoryId!, payload);
|
||||||
|
}
|
||||||
|
return this.service.create(this.guildId, payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<app-page-data-list
|
||||||
|
pageTitle="مدیریت کالاها"
|
||||||
|
[addNewCtaLabel]="'افزودن کالای جدید'"
|
||||||
|
[columns]="columns"
|
||||||
|
[showAdd]="true"
|
||||||
|
emptyPlaceholderTitle="کالایی یافت نشد"
|
||||||
|
emptyPlaceholderDescription="برای افزودن کالای جدید، روی دکمهٔ بالا کلیک کنید."
|
||||||
|
[items]="items()"
|
||||||
|
[loading]="loading()"
|
||||||
|
[showDetails]="true"
|
||||||
|
[showAdd]="true"
|
||||||
|
(onAdd)="openAddForm()"
|
||||||
|
/>
|
||||||
|
<admin-guild-good-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||||
|
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||||
|
import {
|
||||||
|
IColumn,
|
||||||
|
PageDataListComponent,
|
||||||
|
} from '@/shared/components/pageDataList/page-data-list.component';
|
||||||
|
import { Component, inject, Input } from '@angular/core';
|
||||||
|
import { IGuildGoodsResponse } from '../../models';
|
||||||
|
import { GuildGoodsService } from '../../services/goods.service';
|
||||||
|
import { GuildGoodCategoryFormComponent } from './form.component';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'admin-guild-goods-list',
|
||||||
|
templateUrl: './list.component.html',
|
||||||
|
imports: [PageDataListComponent, GuildGoodCategoryFormComponent],
|
||||||
|
})
|
||||||
|
export class GuildGoodsListComponent extends AbstractList<IGuildGoodsResponse> {
|
||||||
|
@Input() guildId!: string;
|
||||||
|
@Input() fullHeight?: boolean;
|
||||||
|
@Input() header: IColumn[] = [
|
||||||
|
{ field: 'id', header: 'شناسه' },
|
||||||
|
{ field: 'name', header: 'عنوان' },
|
||||||
|
{ field: 'sku', header: 'شناسهی عمومی' },
|
||||||
|
{ field: 'category', header: 'دستهبندی', type: 'nested', nestedPath: 'name' },
|
||||||
|
{
|
||||||
|
field: 'created_at',
|
||||||
|
header: 'تاریخ ایجاد',
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
service = inject(GuildGoodsService);
|
||||||
|
|
||||||
|
override setColumns(): void {
|
||||||
|
this.columns = this.header;
|
||||||
|
}
|
||||||
|
|
||||||
|
override getDataRequest() {
|
||||||
|
return this.service.getAll(this.guildId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
const baseUrl = (guildId: string) => `/api/v1/admin/guilds/${guildId}/good_categories`;
|
||||||
|
|
||||||
|
export const GUILD_GOOD_CATEGORIES_API_ROUTES = {
|
||||||
|
list: (guildId: string) => `${baseUrl(guildId)}`,
|
||||||
|
single: (guildId: string, id: string) => `${baseUrl(guildId)}/${id}`,
|
||||||
|
};
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
const baseUrl = (guildId: string) => `/api/v1/admin/guilds/${guildId}/goods`;
|
||||||
|
|
||||||
|
export const GUILD_GOODS_API_ROUTES = {
|
||||||
|
list: (guildId: string) => `${baseUrl(guildId)}`,
|
||||||
|
single: (guildId: string, id: string) => `${baseUrl(guildId)}/${id}`,
|
||||||
|
};
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
const baseUrl = '/api/v1/admin/guilds';
|
||||||
|
|
||||||
|
export const GUILDS_API_ROUTES = {
|
||||||
|
list: () => `${baseUrl}`,
|
||||||
|
single: (id: string) => `${baseUrl}/${id}`,
|
||||||
|
};
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { NamedRoutes } from '@/core';
|
||||||
|
import { Routes } from '@angular/router';
|
||||||
|
|
||||||
|
export type TGuildGoodCategoriesRouteNames = 'goodCategories';
|
||||||
|
|
||||||
|
export const guildGoodCategoriesNamedRoutes: NamedRoutes<TGuildGoodCategoriesRouteNames> = {
|
||||||
|
goodCategories: {
|
||||||
|
path: 'good_categories',
|
||||||
|
loadComponent: () =>
|
||||||
|
import('../../views/categories/list.component').then((m) => m.GuildGoodCategoriesComponent),
|
||||||
|
// @ts-ignore
|
||||||
|
meta: {
|
||||||
|
title: 'دستهبندیهای کالا',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// goodCategory: {
|
||||||
|
// path: 'good_categories/:categoryId',
|
||||||
|
// loadComponent: () => import('../../views/categories/').then((m) => m.GuildComponent),
|
||||||
|
// // @ts-ignore
|
||||||
|
// meta: {
|
||||||
|
// title: 'دستهبندی کالا',
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GUILD_GOOD_CATEGORIES_ROUTES: Routes = Object.values(guildGoodCategoriesNamedRoutes);
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { NamedRoutes } from '@/core';
|
||||||
|
import { Routes } from '@angular/router';
|
||||||
|
|
||||||
|
export type TGuildGoodsRouteNames = 'goods';
|
||||||
|
|
||||||
|
export const guildGoodsNamedRoutes: NamedRoutes<TGuildGoodsRouteNames> = {
|
||||||
|
goods: {
|
||||||
|
path: 'goods',
|
||||||
|
loadComponent: () =>
|
||||||
|
import('../../views/goods/list.component').then((m) => m.GuildGoodsComponent),
|
||||||
|
// @ts-ignore
|
||||||
|
meta: {
|
||||||
|
title: 'کالاها',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// goodCategory: {
|
||||||
|
// path: 'good_categories/:categoryId',
|
||||||
|
// loadComponent: () => import('../../views/categories/').then((m) => m.GuildComponent),
|
||||||
|
// // @ts-ignore
|
||||||
|
// meta: {
|
||||||
|
// title: 'دستهبندی کالا',
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GUILD_GOODS_ROUTES: Routes = Object.values(guildGoodsNamedRoutes);
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { NamedRoutes } from '@/core';
|
||||||
|
import { Routes } from '@angular/router';
|
||||||
|
import { GUILD_GOOD_CATEGORIES_ROUTES } from './goodCategories';
|
||||||
|
import { GUILD_GOODS_ROUTES } from './goods';
|
||||||
|
|
||||||
|
export type TGuildsRouteNames = 'guilds' | 'guild';
|
||||||
|
|
||||||
|
export const guildsNamedRoutes: NamedRoutes<TGuildsRouteNames> = {
|
||||||
|
guilds: {
|
||||||
|
path: 'guilds',
|
||||||
|
loadComponent: () => import('../../views/list.component').then((m) => m.GuildsComponent),
|
||||||
|
meta: {
|
||||||
|
title: 'اصناف',
|
||||||
|
pagePath: () => '/super_admin/guilds',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
guild: {
|
||||||
|
path: 'guilds/:guildId',
|
||||||
|
loadComponent: () => import('../../views/single.component').then((m) => m.GuildComponent),
|
||||||
|
// @ts-ignore
|
||||||
|
meta: {
|
||||||
|
title: 'صنف',
|
||||||
|
pagePath: (guildId: string) => `/super_admin/guilds/${guildId}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GUILDS_ROUTES: Routes = [
|
||||||
|
guildsNamedRoutes.guilds,
|
||||||
|
{
|
||||||
|
path: 'guilds/:guildId',
|
||||||
|
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
loadComponent: () => import('../../views/single.component').then((m) => m.GuildComponent),
|
||||||
|
},
|
||||||
|
|
||||||
|
...GUILD_GOOD_CATEGORIES_ROUTES,
|
||||||
|
...GUILD_GOODS_ROUTES,
|
||||||
|
// {
|
||||||
|
// path: 'good_categories/:categoryId',
|
||||||
|
// loadComponent: () => import('../../views/categories/').then((m) => m.GuildComponent),
|
||||||
|
// // @ts-ignore
|
||||||
|
// meta: {
|
||||||
|
// title: 'دستهبندی کالا',
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import ISummary from '@/core/models';
|
||||||
|
|
||||||
|
export interface IGuildGoodsRawResponse {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
sku: string;
|
||||||
|
category: ISummary;
|
||||||
|
description?: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
export interface IGuildGoodsResponse extends IGuildGoodsRawResponse {}
|
||||||
|
|
||||||
|
export interface IGuildGoodRequest {
|
||||||
|
name: string;
|
||||||
|
sku: string;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './goods_io';
|
||||||
|
export * from './io';
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
export interface IGuildRawResponse {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
created_at: string;
|
||||||
|
}
|
||||||
|
export interface IGuildResponse extends IGuildRawResponse {}
|
||||||
|
|
||||||
|
export interface IGuildRequest {
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IGoodCategoriesRawResponse {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
created_at: string;
|
||||||
|
}
|
||||||
|
export interface IGoodCategoriesResponse extends IGoodCategoriesRawResponse {}
|
||||||
|
|
||||||
|
export interface IGoodCategoryRequest {
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { GUILD_GOOD_CATEGORIES_API_ROUTES } from '../constants/apiRoutes/goodCategories';
|
||||||
|
import {
|
||||||
|
IGoodCategoriesRawResponse,
|
||||||
|
IGoodCategoriesResponse,
|
||||||
|
IGoodCategoryRequest,
|
||||||
|
} from '../models';
|
||||||
|
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class GuildGoodCategoriesService {
|
||||||
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
private apiRoutes = GUILD_GOOD_CATEGORIES_API_ROUTES;
|
||||||
|
|
||||||
|
getAll(guildId: string): Observable<IPaginatedResponse<IGoodCategoriesResponse>> {
|
||||||
|
return this.http.get<IPaginatedResponse<IGoodCategoriesRawResponse>>(
|
||||||
|
this.apiRoutes.list(guildId),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
getSingle(guildId: string, id: string): Observable<IGoodCategoriesResponse> {
|
||||||
|
return this.http.get<IGoodCategoriesRawResponse>(this.apiRoutes.single(guildId, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
create(guildId: string, data: IGoodCategoryRequest): Observable<IGoodCategoriesResponse> {
|
||||||
|
return this.http.post<IGoodCategoriesResponse>(this.apiRoutes.list(guildId), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
update(
|
||||||
|
guildId: string,
|
||||||
|
id: string,
|
||||||
|
data: IGoodCategoryRequest,
|
||||||
|
): Observable<IGoodCategoriesResponse> {
|
||||||
|
return this.http.patch<IGoodCategoriesResponse>(this.apiRoutes.single(guildId, id), data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { GUILD_GOODS_API_ROUTES } from '../constants/apiRoutes/goods';
|
||||||
|
import { IGuildGoodRequest, IGuildGoodsRawResponse, IGuildGoodsResponse } from '../models';
|
||||||
|
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class GuildGoodsService {
|
||||||
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
private apiRoutes = GUILD_GOODS_API_ROUTES;
|
||||||
|
|
||||||
|
getAll(guildId: string): Observable<IPaginatedResponse<IGuildGoodsResponse>> {
|
||||||
|
return this.http.get<IPaginatedResponse<IGuildGoodsRawResponse>>(this.apiRoutes.list(guildId));
|
||||||
|
}
|
||||||
|
getSingle(guildId: string, id: string): Observable<IGuildGoodsResponse> {
|
||||||
|
return this.http.get<IGuildGoodsRawResponse>(this.apiRoutes.single(guildId, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
create(guildId: string, data: IGuildGoodRequest): Observable<IGuildGoodsResponse> {
|
||||||
|
return this.http.post<IGuildGoodsResponse>(this.apiRoutes.list(guildId), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
update(guildId: string, id: string, data: IGuildGoodRequest): Observable<IGuildGoodsResponse> {
|
||||||
|
return this.http.patch<IGuildGoodsResponse>(this.apiRoutes.single(guildId, id), data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { GUILDS_API_ROUTES } from '../constants';
|
||||||
|
import { IGuildRawResponse, IGuildRequest, IGuildResponse } from '../models';
|
||||||
|
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class GuildsService {
|
||||||
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
private apiRoutes = GUILDS_API_ROUTES;
|
||||||
|
|
||||||
|
getAll(): Observable<IPaginatedResponse<IGuildResponse>> {
|
||||||
|
return this.http.get<IPaginatedResponse<IGuildRawResponse>>(this.apiRoutes.list());
|
||||||
|
}
|
||||||
|
getSingle(id: string): Observable<IGuildResponse> {
|
||||||
|
return this.http.get<IGuildRawResponse>(this.apiRoutes.single(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
create(data: IGuildRequest): Observable<IGuildResponse> {
|
||||||
|
return this.http.post<IGuildResponse>(this.apiRoutes.list(), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
update(id: string, data: IGuildRequest): Observable<IGuildResponse> {
|
||||||
|
return this.http.patch<IGuildResponse>(this.apiRoutes.single(id), data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { EntityState, EntityStore } from '@/core/state';
|
||||||
|
import { inject, Injectable } from '@angular/core';
|
||||||
|
import { catchError, finalize, throwError } from 'rxjs';
|
||||||
|
import { IGuildResponse } from '../models';
|
||||||
|
import { GuildsService } from '../services/main.service';
|
||||||
|
|
||||||
|
interface GuildState extends EntityState<IGuildResponse> {}
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class GuildStore extends EntityStore<IGuildResponse, GuildState> {
|
||||||
|
private readonly service = inject(GuildsService);
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
loading: false,
|
||||||
|
error: null,
|
||||||
|
entity: null,
|
||||||
|
initialized: false,
|
||||||
|
isRefreshing: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getData(guildId: string) {
|
||||||
|
this.patchState({ loading: true });
|
||||||
|
this.service
|
||||||
|
.getSingle(guildId)
|
||||||
|
.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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<admin-guild-good-categories-list [guildId]="guildId()" [fullHeight]="true" />
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||||
|
import { Component, inject, signal } from '@angular/core';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { GuildGoodCategoriesListComponent } from '../../components/categories/list.component';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'admin-guild-good-categories',
|
||||||
|
templateUrl: './list.component.html',
|
||||||
|
imports: [GuildGoodCategoriesListComponent],
|
||||||
|
})
|
||||||
|
export class GuildGoodCategoriesComponent {
|
||||||
|
route = inject(ActivatedRoute);
|
||||||
|
guildId = signal<string>(this.route.snapshot.paramMap.get('guildId')!);
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<admin-guild-goods-list [guildId]="guildId()" />
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||||
|
import { Component, inject, signal } from '@angular/core';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { GuildGoodsListComponent } from '../../components/goods/list.component';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'admin-guild_goods',
|
||||||
|
templateUrl: './list.component.html',
|
||||||
|
imports: [GuildGoodsListComponent],
|
||||||
|
})
|
||||||
|
export class GuildGoodsComponent {
|
||||||
|
route = inject(ActivatedRoute);
|
||||||
|
guildId = signal<string>(this.route.snapshot.paramMap.get('guildId')!);
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<app-page-data-list
|
||||||
|
[pageTitle]="'مدیریت اصناف'"
|
||||||
|
[addNewCtaLabel]="'افزودن صنف جدید'"
|
||||||
|
[columns]="columns"
|
||||||
|
[showAdd]="true"
|
||||||
|
emptyPlaceholderTitle="صنفی یافت نشد"
|
||||||
|
emptyPlaceholderDescription="برای افزودن صنف جدید، روی دکمهٔ بالا کلیک کنید."
|
||||||
|
[items]="items()"
|
||||||
|
[loading]="loading()"
|
||||||
|
[showDetails]="true"
|
||||||
|
[showAdd]="true"
|
||||||
|
(onAdd)="openAddForm()"
|
||||||
|
(onDetails)="toSinglePage($event)"
|
||||||
|
/>
|
||||||
|
<admin-guild-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||||
|
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||||
|
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||||
|
import {
|
||||||
|
IColumn,
|
||||||
|
PageDataListComponent,
|
||||||
|
} from '@/shared/components/pageDataList/page-data-list.component';
|
||||||
|
import { Component, inject } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { GuildFormComponent } from '../components/form.component';
|
||||||
|
import { guildsNamedRoutes } from '../constants';
|
||||||
|
import { IGuildResponse } from '../models';
|
||||||
|
import { GuildsService } from '../services/main.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'admin-guilds',
|
||||||
|
templateUrl: './list.component.html',
|
||||||
|
imports: [PageDataListComponent, GuildFormComponent],
|
||||||
|
})
|
||||||
|
export class GuildsComponent extends AbstractList<IGuildResponse> {
|
||||||
|
private readonly service = inject(GuildsService);
|
||||||
|
private readonly router = inject(Router);
|
||||||
|
|
||||||
|
override setColumns(): void {
|
||||||
|
this.columns = [
|
||||||
|
{ field: 'id', header: 'شناسه' },
|
||||||
|
{ field: 'name', header: 'عنوان' },
|
||||||
|
{ field: 'code', header: 'کد' },
|
||||||
|
{ field: 'businessActivitiesCount', header: 'تعداد فعالیتهای اقتصادی مرتبط' },
|
||||||
|
{
|
||||||
|
field: 'created_at',
|
||||||
|
header: 'تاریخ ایجاد',
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
] as IColumn[];
|
||||||
|
}
|
||||||
|
|
||||||
|
override getDataRequest(): void | Observable<IPaginatedResponse<IGuildResponse>> {
|
||||||
|
return this.service.getAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
toSinglePage(guild: IGuildResponse) {
|
||||||
|
this.router.navigateByUrl(guildsNamedRoutes.guild.meta.pagePath!(guild.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<div class="flex flex-col gap-6">
|
||||||
|
<app-card-data cardTitle="اطلاعات صنف" [editable]="true" [(editMode)]="editMode">
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<div class="grid grid-cols-3 gap-4 items-center">
|
||||||
|
<app-key-value label="عنوان صنف" [value]="guild()?.name" />
|
||||||
|
<app-key-value label="کد صنف" [value]="guild()?.code" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</app-card-data>
|
||||||
|
|
||||||
|
<admin-guild-good-categories-list [guildId]="guildId()" />
|
||||||
|
<admin-guild-goods-list [guildId]="guildId()" />
|
||||||
|
|
||||||
|
<admin-guild-form
|
||||||
|
[(visible)]="editMode"
|
||||||
|
[editMode]="true"
|
||||||
|
[guildId]="guildId()"
|
||||||
|
[initialValues]="guild() || undefined"
|
||||||
|
(onSubmit)="getData()"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { AppCardComponent, KeyValueComponent } from '@/shared/components';
|
||||||
|
import { Component, computed, inject, signal } from '@angular/core';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { GuildGoodCategoriesListComponent } from '../components/categories/list.component';
|
||||||
|
import { GuildFormComponent } from '../components/form.component';
|
||||||
|
import { GuildGoodsListComponent } from '../components/goods/list.component';
|
||||||
|
import { GuildStore } from '../store/guild.store';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'admin-guild',
|
||||||
|
templateUrl: './single.component.html',
|
||||||
|
imports: [
|
||||||
|
AppCardComponent,
|
||||||
|
KeyValueComponent,
|
||||||
|
GuildGoodCategoriesListComponent,
|
||||||
|
GuildGoodsListComponent,
|
||||||
|
GuildFormComponent,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
export class GuildComponent {
|
||||||
|
private readonly store = inject(GuildStore);
|
||||||
|
private readonly route = inject(ActivatedRoute);
|
||||||
|
|
||||||
|
readonly guildId = signal<string>(this.route.snapshot.paramMap.get('guildId')!);
|
||||||
|
editMode = signal<boolean>(false);
|
||||||
|
|
||||||
|
readonly loading = computed(() => this.store.loading());
|
||||||
|
readonly guild = computed(() => this.store.entity());
|
||||||
|
|
||||||
|
getData() {
|
||||||
|
this.store.getData(this.guildId());
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.getData();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<p-dialog
|
||||||
|
header="فرم کاربر"
|
||||||
|
[(visible)]="visible"
|
||||||
|
[modal]="true"
|
||||||
|
[style]="{ width: '500px' }"
|
||||||
|
[closable]="true"
|
||||||
|
(onHide)="close()"
|
||||||
|
>
|
||||||
|
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||||
|
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||||
|
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||||
|
</form>
|
||||||
|
</p-dialog>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||||
|
import { InputComponent } from '@/shared/components';
|
||||||
|
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||||
|
import { Component, inject } from '@angular/core';
|
||||||
|
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
|
import { Dialog } from 'primeng/dialog';
|
||||||
|
import { ILicenseRequest, ILicenseResponse } from '../models';
|
||||||
|
import { LicensesService } from '../services/main.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'license-form',
|
||||||
|
templateUrl: './form.component.html',
|
||||||
|
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||||
|
})
|
||||||
|
export class LicenseFormComponent extends AbstractFormDialog<ILicenseRequest, ILicenseResponse> {
|
||||||
|
private service = inject(LicensesService);
|
||||||
|
|
||||||
|
form = this.fb.group({
|
||||||
|
name: [this.initialValues?.name || '', [Validators.required]],
|
||||||
|
});
|
||||||
|
|
||||||
|
override submitForm(payload: ILicenseRequest) {
|
||||||
|
return this.service.create(payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
const baseUrl = '/api/v1/admin/partners';
|
||||||
|
|
||||||
|
export const LICENSES_API_ROUTES = {
|
||||||
|
list: () => `${baseUrl}`,
|
||||||
|
single: (id: string) => `${baseUrl}/${id}`,
|
||||||
|
};
|
||||||
+1
@@ -1 +1,2 @@
|
|||||||
export * from './apiRoutes';
|
export * from './apiRoutes';
|
||||||
|
export * from './routes';
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { NamedRoutes } from '@/core';
|
||||||
|
import { Routes } from '@angular/router';
|
||||||
|
|
||||||
|
export type TLicensesRouteNames = 'licenses' | 'license';
|
||||||
|
|
||||||
|
export const licensesNamedRoutes: NamedRoutes<TLicensesRouteNames> = {
|
||||||
|
licenses: {
|
||||||
|
path: 'licenses',
|
||||||
|
loadComponent: () => import('../../views/list.component').then((m) => m.LicensesComponent),
|
||||||
|
meta: {
|
||||||
|
title: 'لایسنسها',
|
||||||
|
pagePath: () => '/super_admin/licenses',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
license: {
|
||||||
|
path: 'licenses/:licenseId',
|
||||||
|
loadComponent: () => import('../../views/single.component').then((m) => m.LicenseComponent),
|
||||||
|
meta: {
|
||||||
|
title: 'لایسنس',
|
||||||
|
pagePath: () => '/super_admin/licenses/:licenseId',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LICENSES_ROUTES: Routes = Object.values(licensesNamedRoutes);
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
export interface ILicenseRawResponse {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
export interface ILicenseResponse extends ILicenseRawResponse {}
|
||||||
|
|
||||||
|
export interface ILicenseRequest {
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { LICENSES_API_ROUTES } from '../constants';
|
||||||
|
import { ILicenseRawResponse, ILicenseRequest, ILicenseResponse } from '../models';
|
||||||
|
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class LicensesService {
|
||||||
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
private apiRoutes = LICENSES_API_ROUTES;
|
||||||
|
|
||||||
|
getAll(): Observable<IPaginatedResponse<ILicenseResponse>> {
|
||||||
|
return this.http.get<IPaginatedResponse<ILicenseRawResponse>>(this.apiRoutes.list());
|
||||||
|
}
|
||||||
|
getSingle(userId: string): Observable<ILicenseResponse> {
|
||||||
|
return this.http.get<ILicenseRawResponse>(this.apiRoutes.single(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
create(userData: ILicenseRequest): Observable<ILicenseResponse> {
|
||||||
|
return this.http.post<ILicenseResponse>(this.apiRoutes.list(), userData);
|
||||||
|
}
|
||||||
|
|
||||||
|
update(userId: string, userData: ILicenseRequest): Observable<ILicenseResponse> {
|
||||||
|
return this.http.patch<ILicenseResponse>(this.apiRoutes.single(userId), userData);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './list.component';
|
||||||
|
export * from './single.component';
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<app-page-data-list
|
||||||
|
[pageTitle]="'مدیریت لایسنسها'"
|
||||||
|
[addNewCtaLabel]="'افزودن لایسنس جدید'"
|
||||||
|
[columns]="columns"
|
||||||
|
[showAdd]="true"
|
||||||
|
emptyPlaceholderTitle="لایسنسی یافت نشد"
|
||||||
|
emptyPlaceholderDescription="برای افزودن لایسنس جدید، روی دکمهٔ بالا کلیک کنید."
|
||||||
|
[items]="items()"
|
||||||
|
[loading]="loading()"
|
||||||
|
[showDetails]="true"
|
||||||
|
[showAdd]="true"
|
||||||
|
(onAdd)="openAddForm()"
|
||||||
|
>
|
||||||
|
<!-- <ng-template #role let-data>
|
||||||
|
<catalog-role-tag [role]="data.role" />
|
||||||
|
</ng-template> -->
|
||||||
|
</app-page-data-list>
|
||||||
|
<license-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||||
|
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||||
|
import { PageDataListComponent } from '@/shared/components/pageDataList/page-data-list.component';
|
||||||
|
import { Component, inject } from '@angular/core';
|
||||||
|
import { LicenseFormComponent } from '../components/form.component';
|
||||||
|
import { ILicenseResponse } from '../models';
|
||||||
|
import { LicensesService } from '../services/main.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'admin-licenses',
|
||||||
|
templateUrl: './list.component.html',
|
||||||
|
imports: [PageDataListComponent, LicenseFormComponent],
|
||||||
|
})
|
||||||
|
export class LicensesComponent extends AbstractList<ILicenseResponse> {
|
||||||
|
private readonly service = inject(LicensesService);
|
||||||
|
|
||||||
|
override setColumns(): void {
|
||||||
|
this.columns = [
|
||||||
|
{ field: 'id', header: 'شناسه' },
|
||||||
|
{
|
||||||
|
field: 'created_at',
|
||||||
|
header: 'تاریخ ایجاد',
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
override getDataRequest() {
|
||||||
|
return this.service.getAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'admin-license',
|
||||||
|
templateUrl: './single.component.html',
|
||||||
|
})
|
||||||
|
export class LicenseComponent {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<p-dialog
|
||||||
|
header="فرم کاربر"
|
||||||
|
[(visible)]="visible"
|
||||||
|
[modal]="true"
|
||||||
|
[style]="{ width: '500px' }"
|
||||||
|
[closable]="true"
|
||||||
|
(onHide)="close()"
|
||||||
|
>
|
||||||
|
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||||
|
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||||
|
<app-input label="کد" [control]="form.controls.code" name="code" />
|
||||||
|
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||||
|
</form>
|
||||||
|
</p-dialog>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||||
|
import { InputComponent } from '@/shared/components';
|
||||||
|
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||||
|
import { Component, inject } from '@angular/core';
|
||||||
|
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
|
import { Dialog } from 'primeng/dialog';
|
||||||
|
import { IPartnerRequest, IPartnerResponse } from '../models';
|
||||||
|
import { PartnersService } from '../services/main.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'partner-form',
|
||||||
|
templateUrl: './form.component.html',
|
||||||
|
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||||
|
})
|
||||||
|
export class GuildFormComponent extends AbstractFormDialog<IPartnerRequest, IPartnerResponse> {
|
||||||
|
private service = inject(PartnersService);
|
||||||
|
|
||||||
|
form = this.fb.group({
|
||||||
|
name: this.fb.control<string>(this.initialValues?.name || '', {
|
||||||
|
nonNullable: true,
|
||||||
|
validators: [Validators.required],
|
||||||
|
}),
|
||||||
|
code: this.fb.control<string>(this.initialValues?.code || '', {
|
||||||
|
nonNullable: true,
|
||||||
|
validators: [Validators.required],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
override submitForm(payload: IPartnerRequest) {
|
||||||
|
return this.service.create(payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
const baseUrl = '/api/v1/admin/partners';
|
||||||
|
|
||||||
|
export const PARTNERS_API_ROUTES = {
|
||||||
|
list: () => `${baseUrl}`,
|
||||||
|
single: (id: string) => `${baseUrl}/${id}`,
|
||||||
|
};
|
||||||
+1
@@ -1 +1,2 @@
|
|||||||
export * from './apiRoutes';
|
export * from './apiRoutes';
|
||||||
|
export * from './routes';
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { NamedRoutes } from '@/core';
|
||||||
|
import { Routes } from '@angular/router';
|
||||||
|
|
||||||
|
export type TPartnersRouteNames = 'partners' | 'partner';
|
||||||
|
|
||||||
|
export const partnersNamedRoutes: NamedRoutes<TPartnersRouteNames> = {
|
||||||
|
partners: {
|
||||||
|
path: 'partners',
|
||||||
|
loadComponent: () => import('../../views/list.component').then((m) => m.PartnersComponent),
|
||||||
|
meta: {
|
||||||
|
title: 'کاربران',
|
||||||
|
pagePath: () => '/super_admin/partners',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
partner: {
|
||||||
|
path: 'partners/:partnerId',
|
||||||
|
loadComponent: () => import('../../views/single.component').then((m) => m.PartnerComponent),
|
||||||
|
meta: {
|
||||||
|
title: 'کاربر',
|
||||||
|
pagePath: () => '/super_admin/partners/:partnerId',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const PARTNERS_ROUTES: Routes = Object.values(partnersNamedRoutes);
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export interface IPartnerRawResponse {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
}
|
||||||
|
export interface IPartnerResponse extends IPartnerRawResponse {}
|
||||||
|
|
||||||
|
export interface IPartnerRequest {
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { PARTNERS_API_ROUTES } from '../constants';
|
||||||
|
import { IPartnerRawResponse, IPartnerRequest, IPartnerResponse } from '../models';
|
||||||
|
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class PartnersService {
|
||||||
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
private apiRoutes = PARTNERS_API_ROUTES;
|
||||||
|
|
||||||
|
getAll(): Observable<IPaginatedResponse<IPartnerResponse>> {
|
||||||
|
return this.http.get<IPaginatedResponse<IPartnerRawResponse>>(this.apiRoutes.list());
|
||||||
|
}
|
||||||
|
getSingle(userId: string): Observable<IPartnerResponse> {
|
||||||
|
return this.http.get<IPartnerRawResponse>(this.apiRoutes.single(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
create(userData: IPartnerRequest): Observable<IPartnerResponse> {
|
||||||
|
return this.http.post<IPartnerResponse>(this.apiRoutes.list(), userData);
|
||||||
|
}
|
||||||
|
|
||||||
|
update(userId: string, userData: IPartnerRequest): Observable<IPartnerResponse> {
|
||||||
|
return this.http.patch<IPartnerResponse>(this.apiRoutes.single(userId), userData);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<uikit-field [label]="label" [control]="control" [showLabel]="showLabel" [showErrors]="showErrors">
|
||||||
|
<p-select
|
||||||
|
[loading]="loading()"
|
||||||
|
[options]="items()"
|
||||||
|
optionLabel="name"
|
||||||
|
[optionValue]="selectOptionValue"
|
||||||
|
placeholder="انتخاب شریک تجاری"
|
||||||
|
[formControl]="control"
|
||||||
|
[showClear]="showClear"
|
||||||
|
[filter]="true"
|
||||||
|
appendTo="body"
|
||||||
|
>
|
||||||
|
@if (canInsert) {
|
||||||
|
<ng-template #footer>
|
||||||
|
<div class="p-3">
|
||||||
|
<p-button
|
||||||
|
label="افزودن شریک تجاری"
|
||||||
|
fluid
|
||||||
|
severity="secondary"
|
||||||
|
text
|
||||||
|
size="small"
|
||||||
|
icon="pi pi-plus"
|
||||||
|
(onClick)="onOpenForm()"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
|
}
|
||||||
|
</p-select>
|
||||||
|
<partner-form [(visible)]="isOpenFormDialog" (onSubmit)="refresh()" />
|
||||||
|
</uikit-field>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||||
|
import { AbstractSelectComponent } from '@/shared/abstractClasses';
|
||||||
|
import { UikitFieldComponent } from '@/uikit';
|
||||||
|
import { Component, inject, Input } from '@angular/core';
|
||||||
|
import { ReactiveFormsModule } from '@angular/forms';
|
||||||
|
import { Button } from 'primeng/button';
|
||||||
|
import { Select } from 'primeng/select';
|
||||||
|
import { GuildFormComponent } from '../components/form.component';
|
||||||
|
import { IPartnerResponse } from '../models';
|
||||||
|
import { PartnersService } from '../services/main.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-partner-select',
|
||||||
|
templateUrl: './select.component.html',
|
||||||
|
imports: [UikitFieldComponent, Select, Button, ReactiveFormsModule, GuildFormComponent],
|
||||||
|
})
|
||||||
|
export class InventoryBankAccountSelectComponent extends AbstractSelectComponent<
|
||||||
|
IPartnerResponse,
|
||||||
|
IPaginatedResponse<IPartnerResponse>
|
||||||
|
> {
|
||||||
|
@Input() override showClear: boolean = false;
|
||||||
|
@Input() label: string = '';
|
||||||
|
private readonly service = inject(PartnersService);
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
getDataService() {
|
||||||
|
return this.service.getAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './list.component';
|
||||||
|
export * from './single.component';
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<app-page-data-list
|
||||||
|
[pageTitle]="'مدیریت کاربران'"
|
||||||
|
[addNewCtaLabel]="'افزودن کاربر جدید'"
|
||||||
|
[columns]="columns"
|
||||||
|
[showAdd]="true"
|
||||||
|
emptyPlaceholderTitle="کاربری یافت نشد"
|
||||||
|
emptyPlaceholderDescription="برای افزودن کاربر جدید، روی دکمهٔ بالا کلیک کنید."
|
||||||
|
[items]="items()"
|
||||||
|
[loading]="loading()"
|
||||||
|
[showDetails]="true"
|
||||||
|
[showAdd]="true"
|
||||||
|
(onAdd)="openAddForm()"
|
||||||
|
>
|
||||||
|
<!-- <ng-template #role let-data>
|
||||||
|
<catalog-role-tag [role]="data.role" />
|
||||||
|
</ng-template> -->
|
||||||
|
</app-page-data-list>
|
||||||
|
<partner-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||||
|
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||||
|
import { PageDataListComponent } from '@/shared/components/pageDataList/page-data-list.component';
|
||||||
|
import { Component, inject } from '@angular/core';
|
||||||
|
import { GuildFormComponent } from '../components/form.component';
|
||||||
|
import { IPartnerResponse } from '../models';
|
||||||
|
import { PartnersService } from '../services/main.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-users',
|
||||||
|
templateUrl: './list.component.html',
|
||||||
|
imports: [PageDataListComponent, GuildFormComponent],
|
||||||
|
})
|
||||||
|
export class PartnersComponent extends AbstractList<IPartnerResponse> {
|
||||||
|
private readonly service = inject(PartnersService);
|
||||||
|
|
||||||
|
override setColumns(): void {
|
||||||
|
this.columns = [
|
||||||
|
{ field: 'id', header: 'شناسه' },
|
||||||
|
{ field: 'name', header: 'نام' },
|
||||||
|
{ field: 'code', header: 'کد' },
|
||||||
|
{
|
||||||
|
field: 'created_at',
|
||||||
|
header: 'تاریخ ایجاد',
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
override getDataRequest() {
|
||||||
|
return this.service.getAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<div class=""></div>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-user',
|
||||||
|
templateUrl: './single.component.html',
|
||||||
|
})
|
||||||
|
export class PartnerComponent {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<p-dialog
|
||||||
|
header="فرم کاربر"
|
||||||
|
[(visible)]="visible"
|
||||||
|
[modal]="true"
|
||||||
|
[style]="{ width: '500px' }"
|
||||||
|
[closable]="true"
|
||||||
|
(onHide)="close()"
|
||||||
|
>
|
||||||
|
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||||
|
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||||
|
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||||
|
</form>
|
||||||
|
</p-dialog>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||||
|
import { InputComponent } from '@/shared/components';
|
||||||
|
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||||
|
import { Component, inject } from '@angular/core';
|
||||||
|
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
|
import { Dialog } from 'primeng/dialog';
|
||||||
|
import { IProviderRequest, IProviderResponse } from '../models';
|
||||||
|
import { ProvidersService } from '../services/main.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'provider-form',
|
||||||
|
templateUrl: './form.component.html',
|
||||||
|
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||||
|
})
|
||||||
|
export class GuildFormComponent extends AbstractFormDialog<IProviderRequest, IProviderResponse> {
|
||||||
|
private service = inject(ProvidersService);
|
||||||
|
|
||||||
|
form = this.fb.group({
|
||||||
|
name: [this.initialValues?.name || '', [Validators.required]],
|
||||||
|
});
|
||||||
|
|
||||||
|
override submitForm(payload: IProviderRequest) {
|
||||||
|
return this.service.create(payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
const baseUrl = '/api/v1/admin/providers';
|
||||||
|
|
||||||
|
export const PROVIDERS_API_ROUTES = {
|
||||||
|
list: () => `${baseUrl}`,
|
||||||
|
single: (id: string) => `${baseUrl}/${id}`,
|
||||||
|
};
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './apiRoutes';
|
||||||
|
export * from './routes';
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { NamedRoutes } from '@/core';
|
||||||
|
import { Routes } from '@angular/router';
|
||||||
|
|
||||||
|
export type TProvidersRouteNames = 'providers' | 'provider';
|
||||||
|
|
||||||
|
export const providersNamedRoutes: NamedRoutes<TProvidersRouteNames> = {
|
||||||
|
providers: {
|
||||||
|
path: 'providers',
|
||||||
|
loadComponent: () => import('../../views/list.component').then((m) => m.PartnersComponent),
|
||||||
|
meta: {
|
||||||
|
title: 'ارایهدهندگان',
|
||||||
|
pagePath: () => '/super_admin/providers',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
provider: {
|
||||||
|
path: 'providers/:providerId',
|
||||||
|
loadComponent: () => import('../../views/single.component').then((m) => m.ProviderComponent),
|
||||||
|
meta: {
|
||||||
|
title: 'ارایهدهنده',
|
||||||
|
pagePath: () => '/super_admin/providers/:providerId',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const PROVIDERS_ROUTES: Routes = Object.values(providersNamedRoutes);
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
export interface IProviderRawResponse {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
export interface IProviderResponse extends IProviderRawResponse {}
|
||||||
|
|
||||||
|
export interface IProviderRequest {
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { PROVIDERS_API_ROUTES } from '../constants';
|
||||||
|
import { IProviderRawResponse, IProviderRequest, IProviderResponse } from '../models';
|
||||||
|
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class ProvidersService {
|
||||||
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
private apiRoutes = PROVIDERS_API_ROUTES;
|
||||||
|
|
||||||
|
getAll(): Observable<IPaginatedResponse<IProviderResponse>> {
|
||||||
|
return this.http.get<IPaginatedResponse<IProviderRawResponse>>(this.apiRoutes.list());
|
||||||
|
}
|
||||||
|
getSingle(userId: string): Observable<IProviderResponse> {
|
||||||
|
return this.http.get<IProviderRawResponse>(this.apiRoutes.single(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
create(userData: IProviderRequest): Observable<IProviderResponse> {
|
||||||
|
return this.http.post<IProviderResponse>(this.apiRoutes.list(), userData);
|
||||||
|
}
|
||||||
|
|
||||||
|
update(userId: string, userData: IProviderRequest): Observable<IProviderResponse> {
|
||||||
|
return this.http.patch<IProviderResponse>(this.apiRoutes.single(userId), userData);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<uikit-field [label]="label" [control]="control" [showLabel]="showLabel" [showErrors]="showErrors">
|
||||||
|
<p-select
|
||||||
|
[loading]="loading()"
|
||||||
|
[options]="items()"
|
||||||
|
optionLabel="name"
|
||||||
|
[optionValue]="selectOptionValue"
|
||||||
|
placeholder="انتخاب ارایهدهنده"
|
||||||
|
[formControl]="control"
|
||||||
|
[showClear]="showClear"
|
||||||
|
[filter]="true"
|
||||||
|
appendTo="body"
|
||||||
|
>
|
||||||
|
@if (canInsert) {
|
||||||
|
<ng-template #footer>
|
||||||
|
<div class="p-3">
|
||||||
|
<p-button
|
||||||
|
label="افزودن ارایهدهنده"
|
||||||
|
fluid
|
||||||
|
severity="secondary"
|
||||||
|
text
|
||||||
|
size="small"
|
||||||
|
icon="pi pi-plus"
|
||||||
|
(onClick)="onOpenForm()"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
|
}
|
||||||
|
</p-select>
|
||||||
|
<provider-form [(visible)]="isOpenFormDialog" (onSubmit)="refresh()" />
|
||||||
|
</uikit-field>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||||
|
import { AbstractSelectComponent } from '@/shared/abstractClasses';
|
||||||
|
import { UikitFieldComponent } from '@/uikit';
|
||||||
|
import { Component, inject, Input } from '@angular/core';
|
||||||
|
import { ReactiveFormsModule } from '@angular/forms';
|
||||||
|
import { Button } from 'primeng/button';
|
||||||
|
import { Select } from 'primeng/select';
|
||||||
|
import { GuildFormComponent } from '../components/form.component';
|
||||||
|
import { IProviderResponse } from '../models';
|
||||||
|
import { ProvidersService } from '../services/main.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-provider-select',
|
||||||
|
templateUrl: './select.component.html',
|
||||||
|
imports: [UikitFieldComponent, Select, Button, ReactiveFormsModule, GuildFormComponent],
|
||||||
|
})
|
||||||
|
export class InventoryBankAccountSelectComponent extends AbstractSelectComponent<
|
||||||
|
IProviderResponse,
|
||||||
|
IPaginatedResponse<IProviderResponse>
|
||||||
|
> {
|
||||||
|
@Input() override showClear: boolean = false;
|
||||||
|
@Input() label: string = '';
|
||||||
|
private readonly service = inject(ProvidersService);
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
getDataService() {
|
||||||
|
return this.service.getAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './list.component';
|
||||||
|
export * from './single.component';
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<app-page-data-list
|
||||||
|
[pageTitle]="'مدیریت کاربران'"
|
||||||
|
[addNewCtaLabel]="'افزودن کاربر جدید'"
|
||||||
|
[columns]="columns"
|
||||||
|
[showAdd]="true"
|
||||||
|
emptyPlaceholderTitle="کاربری یافت نشد"
|
||||||
|
emptyPlaceholderDescription="برای افزودن کاربر جدید، روی دکمهٔ بالا کلیک کنید."
|
||||||
|
[items]="items()"
|
||||||
|
[loading]="loading()"
|
||||||
|
[showDetails]="true"
|
||||||
|
[showAdd]="true"
|
||||||
|
(onAdd)="openAddForm()"
|
||||||
|
>
|
||||||
|
<!-- <ng-template #role let-data>
|
||||||
|
<catalog-role-tag [role]="data.role" />
|
||||||
|
</ng-template> -->
|
||||||
|
</app-page-data-list>
|
||||||
|
<provider-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||||
|
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||||
|
import { PageDataListComponent } from '@/shared/components/pageDataList/page-data-list.component';
|
||||||
|
import { Component, inject } from '@angular/core';
|
||||||
|
import { GuildFormComponent } from '../components/form.component';
|
||||||
|
import { IProviderResponse } from '../models';
|
||||||
|
import { ProvidersService } from '../services/main.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-users',
|
||||||
|
templateUrl: './list.component.html',
|
||||||
|
imports: [PageDataListComponent, GuildFormComponent],
|
||||||
|
})
|
||||||
|
export class PartnersComponent extends AbstractList<IProviderResponse> {
|
||||||
|
private readonly service = inject(ProvidersService);
|
||||||
|
|
||||||
|
override setColumns(): void {
|
||||||
|
this.columns = [
|
||||||
|
{ field: 'id', header: 'شناسه' },
|
||||||
|
{ field: 'name', header: 'نام' },
|
||||||
|
{
|
||||||
|
field: 'created_at',
|
||||||
|
header: 'تاریخ ایجاد',
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
override getDataRequest() {
|
||||||
|
return this.service.getAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<div class=""></div>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'admin-provider',
|
||||||
|
templateUrl: './single.component.html',
|
||||||
|
})
|
||||||
|
export class ProviderComponent {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { Route } from '@angular/router';
|
||||||
|
import { GUILDS_ROUTES } from './guilds/constants';
|
||||||
|
import { LICENSES_ROUTES } from './licenses/constants';
|
||||||
|
import { PARTNERS_ROUTES } from './partners/constants';
|
||||||
|
import { PROVIDERS_ROUTES } from './providers/constants';
|
||||||
|
import { USERS_ROUTES } from './users/constants';
|
||||||
|
|
||||||
|
export const SUPER_ADMIN_ROUTES = {
|
||||||
|
path: 'super_admin',
|
||||||
|
component: undefined,
|
||||||
|
children: [
|
||||||
|
...USERS_ROUTES,
|
||||||
|
...GUILDS_ROUTES,
|
||||||
|
...PARTNERS_ROUTES,
|
||||||
|
...PROVIDERS_ROUTES,
|
||||||
|
...LICENSES_ROUTES,
|
||||||
|
],
|
||||||
|
} as Route;
|
||||||
+9
-2
@@ -1,9 +1,16 @@
|
|||||||
<p-dialog header="فرم کاربر" [(visible)]="visible" [modal]="true" [style]="{ width: '500px' }" [closable]="true">
|
<p-dialog
|
||||||
|
header="فرم کاربر"
|
||||||
|
[(visible)]="visible"
|
||||||
|
[modal]="true"
|
||||||
|
[style]="{ width: '500px' }"
|
||||||
|
[closable]="true"
|
||||||
|
(onHide)="close()"
|
||||||
|
>
|
||||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||||
<app-input label="نام" [control]="form.controls.firstName" name="firstName" />
|
<app-input label="نام" [control]="form.controls.firstName" name="firstName" />
|
||||||
<app-input label="نام خانوادگی" [control]="form.controls.lastName" name="lastName" />
|
<app-input label="نام خانوادگی" [control]="form.controls.lastName" name="lastName" />
|
||||||
<app-input label="شماره موبایل" [control]="form.controls.mobileNumber" name="mobileNumber" type="mobile" />
|
<app-input label="شماره موبایل" [control]="form.controls.mobileNumber" name="mobileNumber" type="mobile" />
|
||||||
<catalog-roles-select [control]="form.controls.roleId" />
|
<!-- <catalog-roles-select [control]="form.controls.roleId" /> -->
|
||||||
<uikit-field label="رمز عبور" class="" [control]="form.get('password')">
|
<uikit-field label="رمز عبور" class="" [control]="form.get('password')">
|
||||||
<p-password
|
<p-password
|
||||||
id="password1"
|
id="password1"
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
import { ToastService } from '@/core/services/toast.service';
|
import { ToastService } from '@/core/services/toast.service';
|
||||||
import { mobileValidator, MustMatch, password } from '@/core/validators';
|
import { mobileValidator, MustMatch, password } from '@/core/validators';
|
||||||
import { CatalogRolesComponent } from '@/shared/catalog/roles';
|
// import { CatalogRolesComponent } from '@/shared/catalog/roles';
|
||||||
import { InputComponent } from '@/shared/components';
|
import { InputComponent } from '@/shared/components';
|
||||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||||
import { UikitFieldComponent } from '@/uikit';
|
import { UikitFieldComponent } from '@/uikit';
|
||||||
@@ -19,7 +19,7 @@ import { UsersService } from '../services/main.service';
|
|||||||
Dialog,
|
Dialog,
|
||||||
InputComponent,
|
InputComponent,
|
||||||
FormFooterActionsComponent,
|
FormFooterActionsComponent,
|
||||||
CatalogRolesComponent,
|
// CatalogRolesComponent,
|
||||||
UikitFieldComponent,
|
UikitFieldComponent,
|
||||||
Password,
|
Password,
|
||||||
],
|
],
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
const baseUrl = '/api/v1/users';
|
const baseUrl = '/api/v1/admin/users';
|
||||||
|
|
||||||
export const USERS_API_ROUTES = {
|
export const USERS_API_ROUTES = {
|
||||||
list: () => `${baseUrl}`,
|
list: () => `${baseUrl}`,
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './apiRoutes';
|
||||||
|
export * from './routes';
|
||||||
+2
-2
@@ -9,7 +9,7 @@ export const usersNamedRoutes: NamedRoutes<TUsersRouteNames> = {
|
|||||||
loadComponent: () => import('../../views/list.component').then((m) => m.UsersComponent),
|
loadComponent: () => import('../../views/list.component').then((m) => m.UsersComponent),
|
||||||
meta: {
|
meta: {
|
||||||
title: 'کاربران',
|
title: 'کاربران',
|
||||||
pagePath: () => '/users',
|
pagePath: () => '/super_admin/users',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
@@ -17,7 +17,7 @@ export const usersNamedRoutes: NamedRoutes<TUsersRouteNames> = {
|
|||||||
loadComponent: () => import('../../views/single.component').then((m) => m.UserComponent),
|
loadComponent: () => import('../../views/single.component').then((m) => m.UserComponent),
|
||||||
meta: {
|
meta: {
|
||||||
title: 'کاربر',
|
title: 'کاربر',
|
||||||
pagePath: () => '/users/:userId',
|
pagePath: () => '/super_admin/users/:userId',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from './io';
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './list.component';
|
||||||
|
export * from './single.component';
|
||||||
+2
-2
@@ -11,8 +11,8 @@
|
|||||||
[showAdd]="true"
|
[showAdd]="true"
|
||||||
(onAdd)="openAddForm()"
|
(onAdd)="openAddForm()"
|
||||||
>
|
>
|
||||||
<ng-template #role let-data>
|
<!-- <ng-template #role let-data>
|
||||||
<catalog-role-tag [role]="data.role" />
|
<catalog-role-tag [role]="data.role" />
|
||||||
</ng-template>
|
</ng-template> -->
|
||||||
</app-page-data-list>
|
</app-page-data-list>
|
||||||
<user-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
<user-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||||
|
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||||
|
import { PageDataListComponent } from '@/shared/components/pageDataList/page-data-list.component';
|
||||||
|
import { Component, inject } from '@angular/core';
|
||||||
|
import { UserFormComponent } from '../components/form.component';
|
||||||
|
import { IUserResponse } from '../models';
|
||||||
|
import { UsersService } from '../services/main.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-users',
|
||||||
|
templateUrl: './list.component.html',
|
||||||
|
imports: [PageDataListComponent, UserFormComponent],
|
||||||
|
})
|
||||||
|
export class UsersComponent extends AbstractList<IUserResponse> {
|
||||||
|
private readonly service = inject(UsersService);
|
||||||
|
|
||||||
|
override setColumns(): void {
|
||||||
|
this.columns = [
|
||||||
|
{ field: 'id', header: 'شناسه' },
|
||||||
|
{ field: 'fullname', header: 'نام' },
|
||||||
|
{ field: 'mobile_number', header: 'شماره موبایل' },
|
||||||
|
{ field: 'national_code', header: 'کد ملی' },
|
||||||
|
{
|
||||||
|
field: 'created_at',
|
||||||
|
header: 'تاریخ ایجاد',
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
override getDataRequest() {
|
||||||
|
return this.service.getAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user