Refactor code
This commit is contained in:
@@ -7,16 +7,16 @@ import {firstValueFrom} from "rxjs";
|
||||
import {StockAlert} from "../../services/stock.alert";
|
||||
|
||||
@Component({
|
||||
selector: 'app-welcome',
|
||||
selector: 'app-dashboard',
|
||||
imports: [
|
||||
InfoCard,
|
||||
DeliveryValidator,
|
||||
],
|
||||
templateUrl: './welcome.html',
|
||||
styleUrl: './welcome.css'
|
||||
templateUrl: './dashboard.html',
|
||||
styleUrl: './dashboard.css'
|
||||
})
|
||||
|
||||
export class Welcome {
|
||||
export class Dashboard {
|
||||
private productsService = inject(ProductsService);
|
||||
private deliverersService = inject(DeliverersService);
|
||||
private suppliersService = inject(SuppliersService);
|
||||
@@ -32,8 +32,8 @@ export class Welcome {
|
||||
try {
|
||||
const deliverers = await firstValueFrom(this.deliverersService.getAllDelivererEndpoint());
|
||||
this.deliversCount.set(deliverers.length);
|
||||
} catch (e) {
|
||||
this.notificationsService.error('Error', 'Error while getting deliverers.');
|
||||
} catch {
|
||||
this.notificationsService.error('Erreur', 'Impossible de charger les transporteurs');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export class Welcome {
|
||||
this.suppliers.set(suppliers);
|
||||
this.suppliersCount.set(suppliers.length);
|
||||
} catch {
|
||||
this.notificationsService.error('Error', 'Error while getting suppliers.');
|
||||
this.notificationsService.error('Erreur', 'Impossible de charger les fournisseurs');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,11 +52,8 @@ export class Welcome {
|
||||
const products = await firstValueFrom(this.productsService.getAllProductsUnderLimitEndpoint());
|
||||
this.productsUnderLimitCount.set(products.length);
|
||||
await this.stockAlertService.generatePurchaseOrder(products, this.suppliers());
|
||||
} catch (e) {
|
||||
this.notificationsService.error(
|
||||
'Error',
|
||||
'Error while getting products.',
|
||||
)
|
||||
} catch {
|
||||
this.notificationsService.error('Error', 'Impossible de charger les produits.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export class Deliverer {
|
||||
async onModalOk() {
|
||||
await this.addDeliverer()
|
||||
this.createDeliverer().delivererForm.reset();
|
||||
this.modal().isVisible = false;
|
||||
this.onModalCancel();
|
||||
await this.delivererTable().fetchDeliverers()
|
||||
}
|
||||
|
||||
@@ -36,24 +36,15 @@ export class Deliverer {
|
||||
|
||||
async addDeliverer() {
|
||||
if (this.createDeliverer().delivererForm.invalid) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'écriture dans le formulaire'
|
||||
)
|
||||
this.notificationService.error('Erreur', 'Formulaire invalide')
|
||||
}
|
||||
try {
|
||||
const deliverers = this.createDeliverer().delivererForm.getRawValue();
|
||||
await firstValueFrom(this.deliverersService.createDelivererEndpoint(deliverers))
|
||||
|
||||
this.notificationService.success(
|
||||
'Success',
|
||||
'Transporteur enregistré'
|
||||
)
|
||||
} catch (e) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'enregistrement'
|
||||
)
|
||||
this.notificationService.success('Success', 'Transporteur enregistré')
|
||||
} catch {
|
||||
this.notificationService.error('Erreur', 'Erreur d\'enregistrement')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export class Stock implements OnInit {
|
||||
const suppliers = await firstValueFrom(this.suppliersService.getAllSuppliersEndpoint());
|
||||
this.suppliers.set(suppliers);
|
||||
} catch {
|
||||
this.notificationService.error('Erreur', 'Erreur de communication avec l\'API');
|
||||
this.notificationService.error('Erreur', 'Impossible de charger les fournisseurs');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ export class Supplier {
|
||||
async onModalOk() {
|
||||
await this.addSupplier()
|
||||
this.createSupplier().supplierForm.reset();
|
||||
this.modal().isVisible = false;
|
||||
this.onModalCancel();
|
||||
await this.supplierTable().fetchSuppliers()
|
||||
}
|
||||
|
||||
@@ -36,24 +36,15 @@ export class Supplier {
|
||||
|
||||
async addSupplier() {
|
||||
if (this.createSupplier().supplierForm.invalid) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'écriture dans le formulaire'
|
||||
)
|
||||
this.notificationService.error('Erreur', 'Formulaire invalide')
|
||||
}
|
||||
try {
|
||||
const suppliers = this.createSupplier().supplierForm.getRawValue();
|
||||
await firstValueFrom(this.suppliersService.createSupplierEndpoint(suppliers))
|
||||
|
||||
this.notificationService.success(
|
||||
'Success',
|
||||
'Fournisseur enregistré'
|
||||
)
|
||||
} catch (e) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'enregistrement'
|
||||
)
|
||||
this.notificationService.success('Success', 'Fournisseur enregistré')
|
||||
} catch {
|
||||
this.notificationService.error('Erreur', 'Erreur d\'enregistrement')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export class User {
|
||||
async onModalOk() {
|
||||
await this.addUser()
|
||||
this.createUser().profilForm.reset();
|
||||
this.modal().isVisible = false;
|
||||
this.onModalCancel();
|
||||
await this.usersTable().fetchUsers()
|
||||
}
|
||||
|
||||
@@ -36,24 +36,15 @@ export class User {
|
||||
|
||||
async addUser() {
|
||||
if (this.createUser().profilForm.invalid) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'écriture dans le formulaire'
|
||||
)
|
||||
this.notificationService.error('Erreur', 'Formulaire invalide')
|
||||
}
|
||||
try {
|
||||
const users = this.createUser().profilForm.getRawValue();
|
||||
await firstValueFrom(this.usersService.createUserEndpoint(users))
|
||||
|
||||
this.notificationService.success(
|
||||
'Success',
|
||||
'Utilisateur crée'
|
||||
)
|
||||
} catch (e) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'enregistrement'
|
||||
)
|
||||
this.notificationService.success('Success', 'Utilisateur crée')
|
||||
} catch {
|
||||
this.notificationService.error('Erreur', 'Erreur d\'enregistrement')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
import {Routes} from '@angular/router';
|
||||
import {Welcome} from './welcome';
|
||||
|
||||
export const WELCOME_ROUTES: Routes = [
|
||||
{path: '', component: Welcome},
|
||||
];
|
||||
Reference in New Issue
Block a user