connect api to stock page for get, patch and delete

This commit is contained in:
2025-11-29 23:14:04 +01:00
parent a76b184dc1
commit 0189fb0440
8 changed files with 255 additions and 78 deletions

View File

@@ -1,9 +1,10 @@
import { Component } from '@angular/core';
import {Component, effect, input} from '@angular/core';
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
import {NzInputDirective} from "ng-zorro-antd/input";
import {NzColDirective} from "ng-zorro-antd/grid";
import {NzFlexDirective} from "ng-zorro-antd/flex";
import {GetProductDto} from "../../services/api";
@Component({
selector: 'app-stock-form',
@@ -22,17 +23,19 @@ import {NzFlexDirective} from "ng-zorro-antd/flex";
})
export class StockForm {
stockForm = new FormGroup({
minQuantity: new FormControl<number>(null, [Validators.required])
id: new FormControl<number>(null),
minimalQuantity: new FormControl<number>(null, [Validators.required])
})
submitForm() {
// Pour annuler si le formulaire est invalide
if (this.stockForm.invalid) return;
// Pour obtenir la valeur du formulaire
console.log(this.stockForm.getRawValue())
// Pour vider le formulaire
this.stockForm.reset()
product= input<GetProductDto>();
constructor() {
effect(() => {
if (this.product()) {
this.stockForm.patchValue({
id: this.product().id,
minimalQuantity: this.product().minimalQuantity,
});
}
});
}
}