diff --git a/src/app/core/constants/defaultData.const.ts b/src/app/core/constants/defaultData.const.ts index 1ac587b..5ff4acb 100644 --- a/src/app/core/constants/defaultData.const.ts +++ b/src/app/core/constants/defaultData.const.ts @@ -1,6 +1,6 @@ import { IPaginatedQuery } from '../models/service.model'; export const PAGINATED_QUERY_DEFAULT_VALUES: IPaginatedQuery = { - lastSeen: '', - pageSize: 10, + page: 1, + pageSize: 50, }; diff --git a/src/app/core/models/service.model.ts b/src/app/core/models/service.model.ts index 653b3c8..cad1674 100644 --- a/src/app/core/models/service.model.ts +++ b/src/app/core/models/service.model.ts @@ -1,10 +1,16 @@ -export interface IPaginatedQuery { - lastSeen: LastSeen; +export interface IPaginatedQuery { + page: number; pageSize: number; } -export interface IPaginatedResponse { - lastSeen: LastSeen; - totalCount: number; - items: T[]; +export interface IPaginatedResponse { + meta: IResponseMetadata; + data: T[]; +} + +export interface IResponseMetadata { + page: number; + perPage: number; + totalPages: number; + totalRecords: number; } diff --git a/src/app/modules/customers/services/main.service.ts b/src/app/modules/customers/services/main.service.ts index 8cdbcaf..64bdc77 100644 --- a/src/app/modules/customers/services/main.service.ts +++ b/src/app/modules/customers/services/main.service.ts @@ -1,3 +1,4 @@ +import { IPaginatedResponse } from '@/core/models/service.model'; import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; @@ -10,8 +11,8 @@ export class CustomersService { private apiRoutes = CUSTOMERS_API_ROUTES; - getAll(): Observable { - return this.http.get(this.apiRoutes.list()); + getAll(): Observable> { + return this.http.get>(this.apiRoutes.list()); } getSingle(customerId: string): Observable { diff --git a/src/app/modules/customers/views/list.component.html b/src/app/modules/customers/views/list.component.html index 60a32bf..1e87d46 100644 --- a/src/app/modules/customers/views/list.component.html +++ b/src/app/modules/customers/views/list.component.html @@ -8,5 +8,7 @@ [items]="items()" [loading]="loading()" [showDetails]="true" -> - + (onAdd)="openAddForm()" +/> + + diff --git a/src/app/modules/customers/views/list.component.ts b/src/app/modules/customers/views/list.component.ts index 5c305fb..54eaf52 100644 --- a/src/app/modules/customers/views/list.component.ts +++ b/src/app/modules/customers/views/list.component.ts @@ -3,13 +3,14 @@ import { PageDataListComponent, } from '@/shared/components/pageDataList/page-data-list.component'; import { Component, signal } from '@angular/core'; +import { CustomerFormComponent } from '../components/form.component'; import { ICustomerResponse } from '../models'; import { CustomersService } from '../services/main.service'; @Component({ selector: 'app-customers', templateUrl: './list.component.html', - imports: [PageDataListComponent], + imports: [PageDataListComponent, CustomerFormComponent], }) export class CustomersComponent { constructor(private customerService: CustomersService) { @@ -34,12 +35,21 @@ export class CustomersComponent { loading = signal(false); items = signal([]); + visibleForm = signal(false); + + refresh() { + this.getData(); + } getData() { this.loading.set(true); this.customerService.getAll().subscribe((res) => { this.loading.set(false); - this.items.set(res); + this.items.set(res.data); }); } + + openAddForm() { + this.visibleForm.set(true); + } } diff --git a/src/app/modules/inventories/services/main.service.ts b/src/app/modules/inventories/services/main.service.ts index df7b9f9..a335423 100644 --- a/src/app/modules/inventories/services/main.service.ts +++ b/src/app/modules/inventories/services/main.service.ts @@ -1,3 +1,4 @@ +import { IPaginatedResponse } from '@/core/models/service.model'; import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; @@ -10,8 +11,8 @@ export class InventoriesService { private apiRoutes = INVENTORIES_API_ROUTES; - getAll(): Observable { - return this.http.get(this.apiRoutes.list()); + getAll(): Observable> { + return this.http.get>(this.apiRoutes.list()); } getSingle(inventoryId: string): Observable { diff --git a/src/app/modules/inventories/views/list.component.html b/src/app/modules/inventories/views/list.component.html index f01f345..8738bc3 100644 --- a/src/app/modules/inventories/views/list.component.html +++ b/src/app/modules/inventories/views/list.component.html @@ -8,5 +8,7 @@ [items]="items()" [loading]="loading()" [showDetails]="true" -> - + (onAdd)="openAddForm()" +/> + + diff --git a/src/app/modules/inventories/views/list.component.ts b/src/app/modules/inventories/views/list.component.ts index 0cf6c14..47780da 100644 --- a/src/app/modules/inventories/views/list.component.ts +++ b/src/app/modules/inventories/views/list.component.ts @@ -3,13 +3,14 @@ import { PageDataListComponent, } from '@/shared/components/pageDataList/page-data-list.component'; import { Component, signal } from '@angular/core'; +import { InventoryFormComponent } from '../components/form.component'; import { IInventoryResponse } from '../models'; import { InventoriesService } from '../services/main.service'; @Component({ selector: 'app-inventories', templateUrl: './list.component.html', - imports: [PageDataListComponent], + imports: [PageDataListComponent, InventoryFormComponent], }) export class InventoriesComponent { constructor(private inventoryService: InventoriesService) { @@ -26,12 +27,21 @@ export class InventoriesComponent { loading = signal(false); items = signal([]); + visibleForm = signal(false); + + refresh() { + this.getData(); + } getData() { this.loading.set(true); this.inventoryService.getAll().subscribe((res) => { this.loading.set(false); - this.items.set(res); + this.items.set(res.data); }); } + + openAddForm() { + this.visibleForm.set(true); + } } diff --git a/src/app/modules/productBrands/services/main.service.ts b/src/app/modules/productBrands/services/main.service.ts index 523349b..27a1905 100644 --- a/src/app/modules/productBrands/services/main.service.ts +++ b/src/app/modules/productBrands/services/main.service.ts @@ -1,3 +1,4 @@ +import { IPaginatedResponse } from '@/core/models/service.model'; import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; @@ -10,8 +11,8 @@ export class ProductBrandsService { private apiRoutes = PRODUCT_BRANDS_API_ROUTES; - getAll(): Observable { - return this.http.get(this.apiRoutes.list()); + getAll(): Observable> { + return this.http.get>(this.apiRoutes.list()); } getSingle(brandId: string): Observable { diff --git a/src/app/modules/productBrands/views/list.component.html b/src/app/modules/productBrands/views/list.component.html index d827102..2db2c91 100644 --- a/src/app/modules/productBrands/views/list.component.html +++ b/src/app/modules/productBrands/views/list.component.html @@ -8,5 +8,7 @@ [items]="items()" [loading]="loading()" [showDetails]="true" -> - + (onAdd)="openAddForm()" +/> + + diff --git a/src/app/modules/productBrands/views/list.component.ts b/src/app/modules/productBrands/views/list.component.ts index c3025f1..032bebb 100644 --- a/src/app/modules/productBrands/views/list.component.ts +++ b/src/app/modules/productBrands/views/list.component.ts @@ -3,13 +3,14 @@ import { PageDataListComponent, } from '@/shared/components/pageDataList/page-data-list.component'; import { Component, signal } from '@angular/core'; +import { ProductBrandFormComponent } from '../components/form.component'; import { IProductBrandResponse } from '../models'; import { ProductBrandsService } from '../services/main.service'; @Component({ selector: 'app-product-brands', templateUrl: './list.component.html', - imports: [PageDataListComponent], + imports: [PageDataListComponent, ProductBrandFormComponent], }) export class ProductBrandsComponent { constructor(private productBrandService: ProductBrandsService) { @@ -28,12 +29,21 @@ export class ProductBrandsComponent { loading = signal(false); items = signal([]); + visibleForm = signal(false); + + refresh() { + this.getData(); + } getData() { this.loading.set(true); this.productBrandService.getAll().subscribe((res) => { this.loading.set(false); - this.items.set(res); + this.items.set(res.data); }); } + + openAddForm() { + this.visibleForm.set(true); + } } diff --git a/src/app/modules/productCategories/services/main.service.ts b/src/app/modules/productCategories/services/main.service.ts index 741d9dd..e9ede0a 100644 --- a/src/app/modules/productCategories/services/main.service.ts +++ b/src/app/modules/productCategories/services/main.service.ts @@ -1,3 +1,4 @@ +import { IPaginatedResponse } from '@/core/models/service.model'; import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; @@ -14,8 +15,8 @@ export class ProductCategoriesService { private apiRoutes = PRODUCT_CATEGORIES_API_ROUTES; - getAll(): Observable { - return this.http.get(this.apiRoutes.list()); + getAll(): Observable> { + return this.http.get>(this.apiRoutes.list()); } getSingle(categoryId: string): Observable { diff --git a/src/app/modules/productCategories/views/list.component.html b/src/app/modules/productCategories/views/list.component.html index 0213263..a1d72b1 100644 --- a/src/app/modules/productCategories/views/list.component.html +++ b/src/app/modules/productCategories/views/list.component.html @@ -8,5 +8,7 @@ [items]="items()" [loading]="loading()" [showDetails]="true" -> - + (onAdd)="openAddForm()" +/> + + diff --git a/src/app/modules/productCategories/views/list.component.ts b/src/app/modules/productCategories/views/list.component.ts index 0a7fc7f..1b730e3 100644 --- a/src/app/modules/productCategories/views/list.component.ts +++ b/src/app/modules/productCategories/views/list.component.ts @@ -3,13 +3,14 @@ import { PageDataListComponent, } from '@/shared/components/pageDataList/page-data-list.component'; import { Component, signal } from '@angular/core'; +import { ProductCategoryFormComponent } from '../components/form.component'; import { IProductCategoryResponse } from '../models'; import { ProductCategoriesService } from '../services/main.service'; @Component({ selector: 'app-product-categories', templateUrl: './list.component.html', - imports: [PageDataListComponent], + imports: [PageDataListComponent, ProductCategoryFormComponent], }) export class ProductCategoriesComponent { constructor(private productCategoryService: ProductCategoriesService) { @@ -27,12 +28,21 @@ export class ProductCategoriesComponent { loading = signal(false); items = signal([]); + visibleForm = signal(false); + + refresh() { + this.getData(); + } getData() { this.loading.set(true); this.productCategoryService.getAll().subscribe((res) => { this.loading.set(false); - this.items.set(res); + this.items.set(res.data); }); } + + openAddForm() { + this.visibleForm.set(true); + } } diff --git a/src/app/modules/products/components/form.component.html b/src/app/modules/products/components/form.component.html new file mode 100644 index 0000000..2caa167 --- /dev/null +++ b/src/app/modules/products/components/form.component.html @@ -0,0 +1,11 @@ + +
+ + + + + + +
diff --git a/src/app/modules/products/components/form.component.ts b/src/app/modules/products/components/form.component.ts new file mode 100644 index 0000000..03b4697 --- /dev/null +++ b/src/app/modules/products/components/form.component.ts @@ -0,0 +1,71 @@ +import { InputComponent } from '@/shared/components'; +import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component'; +import { Component, effect, EventEmitter, inject, Input, Output, signal } from '@angular/core'; +import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms'; +import { Dialog } from 'primeng/dialog'; +import { IProductRequest, IProductResponse } from '../models'; +import { ProductsService } from '../services/main.service'; + +@Component({ + selector: 'product-form', + templateUrl: './form.component.html', + imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent], +}) +export class ProductFormComponent { + @Input() initialValues?: IProductResponse; + + @Input() + set visible(v: boolean) { + this.visibleSignal.set(!!v); + } + get visible() { + return this.visibleSignal(); + } + private visibleSignal = signal(false); + + @Output() visibleChange = new EventEmitter(); + @Output() onSubmit = new EventEmitter(); + + private fb = inject(FormBuilder); + constructor(private service: ProductsService) { + effect(() => { + const v = this.visibleSignal(); + if (!v) this.form.reset(); + }); + } + + form = this.fb.group({ + name: [this.initialValues?.name || null, [Validators.required]], + description: [this.initialValues?.description || null, [Validators.required]], + productType: [this.initialValues?.productType || null, [Validators.required]], + brandId: [this.initialValues?.brandId || null, [Validators.required]], + categoryId: [this.initialValues?.categoryId || null, [Validators.required]], + supplierId: [this.initialValues?.supplierId || null, [Validators.required]], + }); + + submitLoading = signal(false); + + submit() { + this.form.markAllAsTouched(); + if (this.form.valid) { + this.form.disable(); + this.submitLoading.set(true); + this.service.create(this.form.value as IProductRequest).subscribe({ + next: (res) => { + this.submitLoading.set(false); + this.form.enable(); + this.form.reset(); + this.onSubmit.emit(res); + }, + error: () => { + this.submitLoading.set(false); + this.form.enable(); + }, + }); + } + } + + close() { + this.visibleChange.emit(false); + } +} diff --git a/src/app/modules/products/constants/apiRoutes/index.ts b/src/app/modules/products/constants/apiRoutes/index.ts new file mode 100644 index 0000000..a68ef6a --- /dev/null +++ b/src/app/modules/products/constants/apiRoutes/index.ts @@ -0,0 +1,6 @@ +const baseUrl = '/api/v1/products'; + +export const PRODUCTS_API_ROUTES = { + list: () => `${baseUrl}`, + single: (productId: string) => `${baseUrl}/${productId}`, +}; diff --git a/src/app/modules/products/constants/index.ts b/src/app/modules/products/constants/index.ts new file mode 100644 index 0000000..ee61bd7 --- /dev/null +++ b/src/app/modules/products/constants/index.ts @@ -0,0 +1,2 @@ +export * from './apiRoutes'; +export * from './routes'; diff --git a/src/app/modules/products/constants/routes/index.ts b/src/app/modules/products/constants/routes/index.ts new file mode 100644 index 0000000..f63d3cb --- /dev/null +++ b/src/app/modules/products/constants/routes/index.ts @@ -0,0 +1,25 @@ +import { NamedRoutes } from '@/core'; +import { Routes } from '@angular/router'; + +export type TProductsRouteNames = 'products' | 'product'; + +export const productsNamedRoutes: NamedRoutes = { + products: { + path: 'products', + loadComponent: () => import('../../views/list.component').then((m) => m.ProductsComponent), + meta: { + title: 'محصولات', + pagePath: () => '/products', + }, + }, + product: { + path: 'products/:productId', + loadComponent: () => import('../../views/single.component').then((m) => m.ProductComponent), + meta: { + title: 'محصول', + pagePath: () => '/products/:productId', + }, + }, +}; + +export const PRODUCTS_ROUTES: Routes = Object.values(productsNamedRoutes); diff --git a/src/app/modules/products/models/index.ts b/src/app/modules/products/models/index.ts new file mode 100644 index 0000000..61a518a --- /dev/null +++ b/src/app/modules/products/models/index.ts @@ -0,0 +1 @@ +export * from './io'; diff --git a/src/app/modules/products/models/io.d.ts b/src/app/modules/products/models/io.d.ts new file mode 100644 index 0000000..8c64896 --- /dev/null +++ b/src/app/modules/products/models/io.d.ts @@ -0,0 +1,23 @@ +export interface IProductRawResponse { + id: number; + name: string; + description: string; + productType: string; + createdAt: Date; + updatedAt: Date; + deletedAt: Date; + brandId: number; + categoryId: number; + supplierId: number; +} + +export interface IProductResponse extends IProductRawResponse {} + +export interface IProductRequest { + name: string; + description: string; + productType: string; + brandId: number; + categoryId: number; + supplierId: number; +} diff --git a/src/app/modules/products/services/main.service.ts b/src/app/modules/products/services/main.service.ts new file mode 100644 index 0000000..90cb791 --- /dev/null +++ b/src/app/modules/products/services/main.service.ts @@ -0,0 +1,25 @@ +import { IPaginatedResponse } from '@/core/models/service.model'; +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { PRODUCTS_API_ROUTES } from '../constants'; +import { IProductRawResponse, IProductRequest, IProductResponse } from '../models'; + +@Injectable({ providedIn: 'root' }) +export class ProductsService { + constructor(private http: HttpClient) {} + + private apiRoutes = PRODUCTS_API_ROUTES; + + getAll(): Observable> { + return this.http.get>(this.apiRoutes.list()); + } + + getSingle(productId: string): Observable { + return this.http.get(this.apiRoutes.single(productId)); + } + + create(data: IProductRequest): Observable { + return this.http.post(this.apiRoutes.list(), data); + } +} diff --git a/src/app/modules/products/views/index.ts b/src/app/modules/products/views/index.ts new file mode 100644 index 0000000..bc9dfc9 --- /dev/null +++ b/src/app/modules/products/views/index.ts @@ -0,0 +1,2 @@ +export * from './list.component'; +export * from './single.component'; diff --git a/src/app/modules/products/views/list.component.html b/src/app/modules/products/views/list.component.html new file mode 100644 index 0000000..48f9b55 --- /dev/null +++ b/src/app/modules/products/views/list.component.html @@ -0,0 +1,14 @@ + + + diff --git a/src/app/modules/products/views/list.component.ts b/src/app/modules/products/views/list.component.ts new file mode 100644 index 0000000..d5442f1 --- /dev/null +++ b/src/app/modules/products/views/list.component.ts @@ -0,0 +1,52 @@ +import { + IColumn, + PageDataListComponent, +} from '@/shared/components/pageDataList/page-data-list.component'; +import { Component, signal } from '@angular/core'; +import { ProductFormComponent } from '../components/form.component'; +import { IProductResponse } from '../models'; +import { ProductsService } from '../services/main.service'; + +@Component({ + selector: 'app-products', + templateUrl: './list.component.html', + imports: [PageDataListComponent, ProductFormComponent], +}) +export class ProductsComponent { + constructor(private productService: ProductsService) { + this.getData(); + } + + columns = [ + { field: 'id', header: 'شناسه' }, + { field: 'name', header: 'نام' }, + { field: 'description', header: 'توضیحات' }, + { field: 'productType', header: 'نوع محصول' }, + { field: 'brandId', header: 'برند' }, + { field: 'categoryId', header: 'دسته‌بندی' }, + { field: 'supplierId', header: 'تامین‌کننده' }, + { field: 'createdAt', header: 'تاریخ ایجاد' }, + { field: 'updatedAt', header: 'تاریخ به‌روزرسانی' }, + { field: 'actions' }, + ] as IColumn[]; + + loading = signal(false); + items = signal([]); + visibleForm = signal(false); + + refresh() { + this.getData(); + } + + getData() { + this.loading.set(true); + this.productService.getAll().subscribe((res) => { + this.loading.set(false); + this.items.set(res.data); + }); + } + + openAddForm() { + this.visibleForm.set(true); + } +} diff --git a/src/app/modules/products/views/single.component.html b/src/app/modules/products/views/single.component.html new file mode 100644 index 0000000..7144e26 --- /dev/null +++ b/src/app/modules/products/views/single.component.html @@ -0,0 +1 @@ +
diff --git a/src/app/modules/products/views/single.component.ts b/src/app/modules/products/views/single.component.ts new file mode 100644 index 0000000..85335d1 --- /dev/null +++ b/src/app/modules/products/views/single.component.ts @@ -0,0 +1,9 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-product', + templateUrl: './single.component.html', +}) +export class ProductComponent { + constructor() {} +} diff --git a/src/app/modules/stores/services/main.service.ts b/src/app/modules/stores/services/main.service.ts index 8f8edb1..619d9f5 100644 --- a/src/app/modules/stores/services/main.service.ts +++ b/src/app/modules/stores/services/main.service.ts @@ -1,3 +1,4 @@ +import { IPaginatedResponse } from '@/core/models/service.model'; import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; @@ -10,8 +11,8 @@ export class StoresService { private apiRoutes = STORES_API_ROUTES; - getAll(): Observable { - return this.http.get(this.apiRoutes.list()); + getAll(): Observable> { + return this.http.get>(this.apiRoutes.list()); } getSingle(storeId: string): Observable { diff --git a/src/app/modules/stores/views/list.component.html b/src/app/modules/stores/views/list.component.html index 71e4440..a077024 100644 --- a/src/app/modules/stores/views/list.component.html +++ b/src/app/modules/stores/views/list.component.html @@ -8,5 +8,7 @@ [items]="items()" [loading]="loading()" [showDetails]="true" -> -
+ (onAdd)="openAddForm()" +/> + + diff --git a/src/app/modules/stores/views/list.component.ts b/src/app/modules/stores/views/list.component.ts index 81ce25a..37da2dd 100644 --- a/src/app/modules/stores/views/list.component.ts +++ b/src/app/modules/stores/views/list.component.ts @@ -3,13 +3,14 @@ import { PageDataListComponent, } from '@/shared/components/pageDataList/page-data-list.component'; import { Component, signal } from '@angular/core'; +import { StoreFormComponent } from '../components/form.component'; import { IStoreResponse } from '../models'; import { StoresService } from '../services/main.service'; @Component({ selector: 'app-stores', templateUrl: './list.component.html', - imports: [PageDataListComponent], + imports: [PageDataListComponent, StoreFormComponent], }) export class StoresComponent { constructor(private storeService: StoresService) { @@ -28,12 +29,21 @@ export class StoresComponent { loading = signal(false); items = signal([]); + visibleForm = signal(false); + + refresh() { + this.getData(); + } getData() { this.loading.set(true); this.storeService.getAll().subscribe((res) => { this.loading.set(false); - this.items.set(res); + this.items.set(res.data); }); } + + openAddForm() { + this.visibleForm.set(true); + } } diff --git a/src/app/modules/suppliers/services/main.service.ts b/src/app/modules/suppliers/services/main.service.ts index ddbf516..ed3eeb3 100644 --- a/src/app/modules/suppliers/services/main.service.ts +++ b/src/app/modules/suppliers/services/main.service.ts @@ -1,3 +1,4 @@ +import { IPaginatedResponse } from '@/core/models/service.model'; import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; @@ -10,8 +11,8 @@ export class SuppliersService { private apiRoutes = SUPPLIERS_API_ROUTES; - getAll(): Observable { - return this.http.get(this.apiRoutes.list()); + getAll(): Observable> { + return this.http.get>(this.apiRoutes.list()); } getSingle(supplierId: string): Observable { diff --git a/src/app/modules/suppliers/views/list.component.html b/src/app/modules/suppliers/views/list.component.html index f853845..5a656bc 100644 --- a/src/app/modules/suppliers/views/list.component.html +++ b/src/app/modules/suppliers/views/list.component.html @@ -8,5 +8,7 @@ [items]="items()" [loading]="loading()" [showDetails]="true" -> - + (onAdd)="openAddForm()" +/> + + diff --git a/src/app/modules/suppliers/views/list.component.ts b/src/app/modules/suppliers/views/list.component.ts index 57e2779..422e17b 100644 --- a/src/app/modules/suppliers/views/list.component.ts +++ b/src/app/modules/suppliers/views/list.component.ts @@ -3,13 +3,14 @@ import { PageDataListComponent, } from '@/shared/components/pageDataList/page-data-list.component'; import { Component, signal } from '@angular/core'; +import { SupplierFormComponent } from '../components/form.component'; import { ISupplierResponse } from '../models'; import { SuppliersService } from '../services/main.service'; @Component({ selector: 'app-suppliers', templateUrl: './list.component.html', - imports: [PageDataListComponent], + imports: [PageDataListComponent, SupplierFormComponent], }) export class SuppliersComponent { constructor(private supplierService: SuppliersService) { @@ -34,12 +35,21 @@ export class SuppliersComponent { loading = signal(false); items = signal([]); + visibleForm = signal(false); + + refresh() { + this.getData(); + } getData() { this.loading.set(true); this.supplierService.getAll().subscribe((res) => { this.loading.set(false); - this.items.set(res); + this.items.set(res.data); }); } + + openAddForm() { + this.visibleForm.set(true); + } } diff --git a/src/app/modules/users/services/main.service.ts b/src/app/modules/users/services/main.service.ts index ac7a81f..a112d5e 100644 --- a/src/app/modules/users/services/main.service.ts +++ b/src/app/modules/users/services/main.service.ts @@ -1,3 +1,4 @@ +import { IPaginatedResponse } from '@/core/models/service.model'; import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; @@ -10,8 +11,8 @@ export class UsersService { private apiRoutes = USERS_API_ROUTES; - getAll(): Observable { - return this.http.get(this.apiRoutes.list()); + getAll(): Observable> { + return this.http.get>(this.apiRoutes.list()); } getSingle(userId: string): Observable { return this.http.get(this.apiRoutes.single(userId)); diff --git a/src/app/modules/users/views/list.component.html b/src/app/modules/users/views/list.component.html index 439b495..5b6bfaf 100644 --- a/src/app/modules/users/views/list.component.html +++ b/src/app/modules/users/views/list.component.html @@ -5,7 +5,7 @@ [showAdd]="true" emptyPlaceholderTitle="کاربری یافت نشد" emptyPlaceholderDescription="برای افزودن کاربر جدید، روی دکمهٔ بالا کلیک کنید." - [items]="[]" + [items]="items()" [loading]="loading()" [showDetails]="true" [showAdd]="true" diff --git a/src/app/modules/users/views/list.component.ts b/src/app/modules/users/views/list.component.ts index a762cc5..8c972ab 100644 --- a/src/app/modules/users/views/list.component.ts +++ b/src/app/modules/users/views/list.component.ts @@ -37,8 +37,10 @@ export class UsersComponent { getData() { this.loading.set(true); this.userService.getAll().subscribe((res) => { + console.log(res); + this.loading.set(false); - this.items.set(res); + this.items.set(res.data); }); }