updated create-form of loan and book
This commit is contained in:
@@ -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<number>(null, Validators.required),
|
||||
bookId: new FormControl<number>(null, Validators.required)
|
||||
bookId: new FormControl<number>(null, Validators.required),
|
||||
date: new FormControl<string>(format(new Date(), 'yyyy-MM-dd'))
|
||||
})
|
||||
|
||||
private userService = inject(UsersService);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<app-modal type="primary" [name]="'Ajouter un auteur'">
|
||||
<app-create-author></app-create-author>
|
||||
<app-modal #modal type="primary" [name]="'Ajouter un auteur'" (ok)="onModalOk()" (cancel)="onModalCancel()">>
|
||||
<app-create-author #createAuthor></app-create-author>
|
||||
</app-modal>
|
||||
|
||||
<section class="mt-5">
|
||||
<app-author-table></app-author-table>
|
||||
<app-author-table #authorTable></app-author-table>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -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>('modal');
|
||||
createAuthor = viewChild.required<CreateAuthor>('createAuthor');
|
||||
authorTable = viewChild.required<AuthorTable>('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'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<app-modal type="primary" [name]="'Ajouter un livre'">
|
||||
<app-create-book></app-create-book>
|
||||
<app-modal #modal type="primary" [name]="'Ajouter un livre'" (ok)="onModalOk()" (cancel)="onModalCancel()">
|
||||
<app-create-book #createBook></app-create-book>
|
||||
</app-modal>
|
||||
|
||||
<section class="mt-5">
|
||||
<app-book-table></app-book-table>
|
||||
<app-book-table #bookTable></app-book-table>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -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>('modal');
|
||||
createBook = viewChild.required<CreateBook>('createBook');
|
||||
booksTable = viewChild.required<BookTable>('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'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<app-modal type="primary" [name]="'Ajouter un emprunt'">
|
||||
<app-create-loan></app-create-loan>
|
||||
<app-modal #modal type="primary" [name]="'Ajouter un emprunt'" (ok)="onModalOk()" (cancel)="onModalCancel()">
|
||||
<app-create-loan #createLoan></app-create-loan>
|
||||
</app-modal>
|
||||
|
||||
<div class="mt-5">
|
||||
<app-loan-table></app-loan-table>
|
||||
<app-loan-table #loanTable></app-loan-table>
|
||||
</div>
|
||||
@@ -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>('modal');
|
||||
createLoan = viewChild.required<CreateLoan>('createLoan');
|
||||
loansTable = viewChild.required<LoanTable>('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'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user