diff --git a/src/app/components/create-loan/create-loan.ts b/src/app/components/create-loan/create-loan.ts index 6874244..6cf0a61 100644 --- a/src/app/components/create-loan/create-loan.ts +++ b/src/app/components/create-loan/create-loan.ts @@ -6,6 +6,7 @@ import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select"; import {BooksService, GetBookDto, GetUserDto, UsersService} from "../../services/api"; import {NzNotificationService} from "ng-zorro-antd/notification"; import {firstValueFrom} from "rxjs"; +import {format} from "date-fns"; @Component({ selector: 'app-create-loan', @@ -27,7 +28,8 @@ import {firstValueFrom} from "rxjs"; export class CreateLoan implements OnInit { createLoanForm = new FormGroup({ userId: new FormControl(null, Validators.required), - bookId: new FormControl(null, Validators.required) + bookId: new FormControl(null, Validators.required), + date: new FormControl(format(new Date(), 'yyyy-MM-dd')) }) private userService = inject(UsersService); diff --git a/src/app/pages/author/author.html b/src/app/pages/author/author.html index 4632316..ffc8db4 100644 --- a/src/app/pages/author/author.html +++ b/src/app/pages/author/author.html @@ -1,8 +1,8 @@ - - +> +
- +
diff --git a/src/app/pages/author/author.ts b/src/app/pages/author/author.ts index eea4efc..88c8cbe 100644 --- a/src/app/pages/author/author.ts +++ b/src/app/pages/author/author.ts @@ -1,7 +1,10 @@ -import {Component} from '@angular/core'; +import {Component, inject, viewChild} from '@angular/core'; import {CreateAuthor} from "../../components/create-author/create-author"; import {Modal} from "../../components/modal/modal"; import {AuthorTable} from "../../components/author-table/author-table"; +import {AuthorsService} from "../../services/api"; +import {NzNotificationService} from "ng-zorro-antd/notification"; +import {firstValueFrom} from "rxjs"; @Component({ selector: 'app-author', @@ -14,5 +17,45 @@ import {AuthorTable} from "../../components/author-table/author-table"; styleUrl: './author.css', }) export class Author{ + modal = viewChild.required('modal'); + createAuthor = viewChild.required('createAuthor'); + authorTable = viewChild.required('authorTable'); + private authorsService = inject(AuthorsService); + private notificationService = inject(NzNotificationService) + async onModalOk() { + await this.addAuthor() + this.createAuthor().createAuthorForm.reset(); + this.modal().isVisible = false; + await this.authorTable().fetchAuthors() + } + + onModalCancel() { + this.modal().isVisible = false; + } + + async addAuthor() { + if (this.createAuthor().createAuthorForm.invalid) + { + this.notificationService.error( + 'Erreur', + 'Erreur d\'écriture dans le formulaire' + ) + } + try { + const authors = this.createAuthor().createAuthorForm.getRawValue(); + + await firstValueFrom(this.authorsService.createAuthorEndpoint(authors)) + + this.notificationService.success( + 'Success', + 'Utilisateur crée' + ) + } catch (e) { + this.notificationService.error( + 'Erreur', + 'Erreur d\'enregistrement' + ) + } + } } diff --git a/src/app/pages/book/book.html b/src/app/pages/book/book.html index b634a6e..b5a0977 100644 --- a/src/app/pages/book/book.html +++ b/src/app/pages/book/book.html @@ -1,8 +1,8 @@ - - + +
- +
diff --git a/src/app/pages/book/book.ts b/src/app/pages/book/book.ts index 602a52c..10f9e8f 100644 --- a/src/app/pages/book/book.ts +++ b/src/app/pages/book/book.ts @@ -1,7 +1,10 @@ -import {Component, inject, OnInit, signal} from '@angular/core'; +import {Component, inject, viewChild} from '@angular/core'; import {BookTable} from "../../components/book-table/book-table"; import {Modal} from "../../components/modal/modal"; import {CreateBook} from "../../components/create-book/create-book"; +import {BooksService} from "../../services/api"; +import {NzNotificationService} from "ng-zorro-antd/notification"; +import {firstValueFrom} from "rxjs"; @Component({ selector: 'app-book', @@ -14,4 +17,45 @@ import {CreateBook} from "../../components/create-book/create-book"; styleUrls: ['./book.css'], }) export class Book{ + modal = viewChild.required('modal'); + createBook = viewChild.required('createBook'); + booksTable = viewChild.required('bookTable'); + private booksService = inject(BooksService); + private notificationService = inject(NzNotificationService) + + async onModalOk() { + await this.addBook() + this.createBook().createBookForm.reset(); + this.modal().isVisible = false; + await this.booksTable().fetchBooks() + } + + onModalCancel() { + this.modal().isVisible = false; + } + + async addBook() { + if (this.createBook().createBookForm.invalid) + { + this.notificationService.error( + 'Erreur', + 'Erreur d\'écriture dans le formulaire' + ) + } + try { + const books = this.createBook().createBookForm.getRawValue(); + await firstValueFrom(this.booksService.createBookEndpoint(books)) + + this.notificationService.success( + 'Success', + 'Enregistrement réussi' + ) + } catch (e) { + this.notificationService.error( + 'Erreur', + 'Erreur d\'enregistrement' + ) + } + } } + diff --git a/src/app/pages/loan/loan.html b/src/app/pages/loan/loan.html index a0806d4..712ac96 100644 --- a/src/app/pages/loan/loan.html +++ b/src/app/pages/loan/loan.html @@ -1,7 +1,7 @@ - - + +
- +
\ No newline at end of file diff --git a/src/app/pages/loan/loan.ts b/src/app/pages/loan/loan.ts index 56e5d87..055295c 100644 --- a/src/app/pages/loan/loan.ts +++ b/src/app/pages/loan/loan.ts @@ -1,7 +1,11 @@ -import { Component } from '@angular/core'; +import {Component, inject, viewChild} from '@angular/core'; import {Modal} from "../../components/modal/modal"; import {CreateLoan} from "../../components/create-loan/create-loan"; import {LoanTable} from "../../components/loan-table/loan-table"; +import {LoansService} from "../../services/api"; +import {NzNotificationService} from "ng-zorro-antd/notification"; +import {format} from "date-fns"; +import {firstValueFrom} from "rxjs"; @Component({ selector: 'app-loan', @@ -14,5 +18,44 @@ import {LoanTable} from "../../components/loan-table/loan-table"; styleUrl: './loan.css', }) export class Loan { + modal = viewChild.required('modal'); + createLoan = viewChild.required('createLoan'); + loansTable = viewChild.required('loanTable'); + private loansService = inject(LoansService); + private notificationService = inject(NzNotificationService) + async onModalOk() { + await this.addLoan() + this.createLoan().createLoanForm.reset(); + this.modal().isVisible = false; + await this.loansTable().fetchLoans() + } + + onModalCancel() { + this.modal().isVisible = false; + } + + async addLoan() { + if (this.createLoan().createLoanForm.invalid) + { + this.notificationService.error( + 'Erreur', + 'Erreur d\'écriture dans le formulaire' + ) + } + try { + const loans = this.createLoan().createLoanForm.getRawValue(); + await firstValueFrom(this.loansService.createLoanEndpoint(loans)) + + this.notificationService.success( + 'Success', + 'Enregistrement réussi' + ) + } catch (e) { + this.notificationService.error( + 'Erreur', + 'Erreur d\'enregistrement' + ) + } + } } diff --git a/src/app/pages/user/user.ts b/src/app/pages/user/user.ts index c75bf1e..349bc5d 100644 --- a/src/app/pages/user/user.ts +++ b/src/app/pages/user/user.ts @@ -1,8 +1,8 @@ -import {Component, inject, OnInit, viewChild} from '@angular/core'; +import {Component, inject, viewChild} from '@angular/core'; import {Modal} from "../../components/modal/modal"; import {CreateUser} from "../../components/create-user/create-user"; import {UserTable} from "../../components/user-table/user-table"; -import {CreateUserDto, UsersService} from "../../services/api"; +import {UsersService} from "../../services/api"; import {NzNotificationService} from "ng-zorro-antd/notification"; import {firstValueFrom} from "rxjs"; import { format } from 'date-fns';