refactor user accounts structure

This commit is contained in:
2026-03-16 00:35:34 +03:30
parent 20be653499
commit 3c9f6eed1d
286 changed files with 2812 additions and 1133 deletions
@@ -0,0 +1,14 @@
<p-dialog
[header]="preparedTitle"
[(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" />
<catalog-deviceBrand-select [control]="form.controls.brand_id" />
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
</form>
</p-dialog>
@@ -0,0 +1,52 @@
// import { CatalogRolesComponent } from '@/shared/catalog/roles';
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { CatalogDeviceBrandSelectComponent } from '@/shared/catalog/deviceBrands';
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 { IDeviceRequest, IDeviceResponse } from '../models';
import { SuperAdminDeviceService } from '../services/main.service';
@Component({
selector: 'superAdmin-device-form',
templateUrl: './form.component.html',
imports: [
ReactiveFormsModule,
Dialog,
InputComponent,
FormFooterActionsComponent,
CatalogDeviceBrandSelectComponent,
],
})
export class UserComplexFormComponent extends AbstractFormDialog<IDeviceRequest, IDeviceResponse> {
private readonly service = inject(SuperAdminDeviceService);
@Input() deviceId?: string;
initForm = () => {
return this.fb.group({
name: [this.initialValues?.name || '', [Validators.required]],
brand_id: [this.initialValues?.brand.id || '', [Validators.required]],
});
};
form = this.initForm();
get preparedTitle() {
return `${this.editMode ? 'ویرایش' : 'ایجاد'} دستگاه`;
}
override ngOnChanges(): void {
this.form = this.initForm();
}
submitForm() {
const formValue = this.form.value as IDeviceRequest;
if (this.editMode) {
return this.service.update(this.deviceId!, formValue);
}
return this.service.create(formValue);
}
}
@@ -0,0 +1,6 @@
const baseUrl = '/api/v1/admin/devices';
export const DEVICES_API_ROUTES = {
list: () => `${baseUrl}`,
single: (id: string) => `${baseUrl}/${id}`,
};
@@ -0,0 +1,2 @@
export * from './apiRoutes';
export * from './routes';
@@ -0,0 +1,17 @@
import { NamedRoutes } from '@/core';
import { Routes } from '@angular/router';
export type TDevicesRouteNames = 'devices';
export const devicesRoutes: NamedRoutes<TDevicesRouteNames> = {
devices: {
path: 'devices',
loadComponent: () => import('../../views/list.component').then((m) => m.DevicesComponent),
meta: {
title: 'دستگاه‌ها',
pagePath: () => '/super_admin/devices',
},
},
};
export const DEVICES_ROUTES: Routes = Object.values(devicesRoutes);
@@ -0,0 +1 @@
export * from './io';
@@ -0,0 +1,13 @@
import ISummary from '@/core/models/summary';
export interface IDeviceRawResponse {
id: string;
name: string;
brand: ISummary;
}
export interface IDeviceResponse extends IDeviceRawResponse {}
export interface IDeviceRequest {
name: string;
brand_id: 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 { DEVICES_API_ROUTES } from '../constants';
import { IDeviceRawResponse, IDeviceRequest, IDeviceResponse } from '../models';
@Injectable({ providedIn: 'root' })
export class SuperAdminDeviceService {
constructor(private http: HttpClient) {}
private apiRoutes = DEVICES_API_ROUTES;
getAll(): Observable<IPaginatedResponse<IDeviceResponse>> {
return this.http.get<IPaginatedResponse<IDeviceRawResponse>>(this.apiRoutes.list());
}
// getSingle(userId: string): Observable<IDeviceBrandResponse> {
// return this.http.get<IDeviceBrandRawResponse>(this.apiRoutes.single(userId));
// }
create(userData: IDeviceRequest): Observable<IDeviceResponse> {
return this.http.post<IDeviceResponse>(this.apiRoutes.list(), userData);
}
update(userId: string, userData: IDeviceRequest): Observable<IDeviceResponse> {
return this.http.patch<IDeviceResponse>(this.apiRoutes.single(userId), userData);
}
}
@@ -0,0 +1 @@
export * from './list.component';
@@ -0,0 +1,21 @@
<app-page-data-list
pageTitle="مدیریت دستگاه‌ها"
[addNewCtaLabel]="'افزودن دستگاه جدید'"
[columns]="columns"
[showAdd]="true"
emptyPlaceholderTitle="دستگاه یافت نشد"
emptyPlaceholderDescription="برای افزودن دستگاه جدید، روی دکمهٔ بالا کلیک کنید."
[items]="items()"
[loading]="loading()"
[showAdd]="true"
[showEdit]="true"
(onAdd)="openAddForm()"
(onEdit)="onEditClick($event)"
/>
<superAdmin-device-form
[(visible)]="visibleForm"
[editMode]="editMode()"
[deviceId]="selectedItemForEdit()?.id"
[initialValues]="selectedItemForEdit() || undefined"
(onSubmit)="refresh()"
/>
@@ -0,0 +1,37 @@
// 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 { UserComplexFormComponent } from '../components/form.component';
import { IDeviceResponse } from '../models';
import { SuperAdminDeviceService } from '../services/main.service';
@Component({
selector: 'superAdmin-deviceBrands',
templateUrl: './list.component.html',
imports: [PageDataListComponent, UserComplexFormComponent],
})
export class DevicesComponent extends AbstractList<IDeviceResponse> {
private readonly service = inject(SuperAdminDeviceService);
override setColumns(): void {
this.columns = [
{ field: 'id', header: 'شناسه' },
{ field: 'name', header: 'عنوان' },
{ field: 'brand', header: 'برند دستگاه', type: 'nested', nestedPath: 'name' },
{
field: 'created_at',
header: 'تاریخ ایجاد',
type: 'date',
},
];
}
override getDataRequest() {
return this.service.getAll();
}
// toSinglePage(partner: IDeviceBrandResponse) {
// this.router.navigateByUrl(partnersNamedRoutes.partner.meta.pagePath!(partner.id));
// }
}