chore: add husky pre-commit hook and lint-staged configuration
- Created a pre-commit hook in .husky to run lint-staged. - Added .lintstagedrc.mjs to format frontend files with Prettier and apply Spotless to backend Java files. - Introduced .prettierignore to exclude specific directories from formatting.
This commit is contained in:
1 parent
5d2d85aa8c
commit
878da155bd
564 files changed
+61467
-47179
No files matched your search
@@ -6,137 +6,137 @@ import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import {
|
||||
Apartment,
|
||||
ApartmentLegalProfile,
|
||||
emptyApartmentLegalProfile,
|
||||
PrivateArea,
|
||||
Apartment,
|
||||
ApartmentLegalProfile,
|
||||
emptyApartmentLegalProfile,
|
||||
PrivateArea,
|
||||
} from '../../services/apartment.service';
|
||||
import { ApartmentLegalProfileForm } from '../apartment-legal-profile-form/apartment-legal-profile-form';
|
||||
import { PrivateAreaEditor } from '../private-area-editor/private-area-editor';
|
||||
|
||||
const requiredFieldsError =
|
||||
'Veuillez remplir tous les champs obligatoires (Nom, Adresse, Prix > 0).';
|
||||
'Veuillez remplir tous les champs obligatoires (Nom, Adresse, Prix > 0).';
|
||||
|
||||
@Component({
|
||||
selector: 'app-apartment-form',
|
||||
imports: [
|
||||
FormsModule,
|
||||
FormRoot,
|
||||
FormField,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatProgressSpinnerModule,
|
||||
ApartmentLegalProfileForm,
|
||||
PrivateAreaEditor,
|
||||
],
|
||||
templateUrl: './apartment-form.html',
|
||||
styleUrl: './apartment-form.css',
|
||||
selector: 'app-apartment-form',
|
||||
imports: [
|
||||
FormsModule,
|
||||
FormRoot,
|
||||
FormField,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatProgressSpinnerModule,
|
||||
ApartmentLegalProfileForm,
|
||||
PrivateAreaEditor,
|
||||
],
|
||||
templateUrl: './apartment-form.html',
|
||||
styleUrl: './apartment-form.css',
|
||||
})
|
||||
export class ApartmentForm {
|
||||
readonly apartment = input<Apartment | null>(null);
|
||||
readonly saving = input(false);
|
||||
readonly saveError = input('');
|
||||
readonly closed = output<void>();
|
||||
readonly saved = output<Apartment>();
|
||||
readonly apartment = input<Apartment | null>(null);
|
||||
readonly saving = input(false);
|
||||
readonly saveError = input('');
|
||||
readonly closed = output<void>();
|
||||
readonly saved = output<Apartment>();
|
||||
|
||||
readonly apartmentModel = signal<Apartment>({
|
||||
name: '',
|
||||
address: '',
|
||||
purchasePrice: 0,
|
||||
description: '',
|
||||
legalProfile: emptyApartmentLegalProfile(),
|
||||
privateAreas: [],
|
||||
});
|
||||
readonly apartmentModel = signal<Apartment>({
|
||||
name: '',
|
||||
address: '',
|
||||
purchasePrice: 0,
|
||||
description: '',
|
||||
legalProfile: emptyApartmentLegalProfile(),
|
||||
privateAreas: [],
|
||||
});
|
||||
|
||||
readonly apartmentForm = form(this.apartmentModel, (f) => {
|
||||
required(f.name, { message: requiredFieldsError });
|
||||
required(f.address, { message: requiredFieldsError });
|
||||
required(f.purchasePrice, { message: requiredFieldsError });
|
||||
min(f.purchasePrice, 1, { message: requiredFieldsError });
|
||||
min(f.legalProfile.habitableSurface, 0, {
|
||||
message: 'La surface habitable doit être positive ou nulle.',
|
||||
});
|
||||
min(f.legalProfile.estimatedAnnualEnergyCost, 0, {
|
||||
message: 'Le coût annuel énergétique doit être positif ou nul.',
|
||||
});
|
||||
required(f.legalProfile.estimatedAnnualEnergyCostReferenceYear, {
|
||||
when: ({ valueOf }) => valueOf(f.legalProfile.estimatedAnnualEnergyCost) !== null,
|
||||
message: "Renseignez l'année de référence du coût énergétique.",
|
||||
});
|
||||
min(f.legalProfile.estimatedAnnualEnergyCostReferenceYear, 1900, {
|
||||
message: "L'année de référence énergétique doit être comprise entre 1900 et 2100.",
|
||||
});
|
||||
max(f.legalProfile.estimatedAnnualEnergyCostReferenceYear, 2100, {
|
||||
message: "L'année de référence énergétique doit être comprise entre 1900 et 2100.",
|
||||
});
|
||||
});
|
||||
readonly apartmentForm = form(this.apartmentModel, (f) => {
|
||||
required(f.name, { message: requiredFieldsError });
|
||||
required(f.address, { message: requiredFieldsError });
|
||||
required(f.purchasePrice, { message: requiredFieldsError });
|
||||
min(f.purchasePrice, 1, { message: requiredFieldsError });
|
||||
min(f.legalProfile.habitableSurface, 0, {
|
||||
message: 'La surface habitable doit être positive ou nulle.',
|
||||
});
|
||||
min(f.legalProfile.estimatedAnnualEnergyCost, 0, {
|
||||
message: 'Le coût annuel énergétique doit être positif ou nul.',
|
||||
});
|
||||
required(f.legalProfile.estimatedAnnualEnergyCostReferenceYear, {
|
||||
when: ({ valueOf }) => valueOf(f.legalProfile.estimatedAnnualEnergyCost) !== null,
|
||||
message: "Renseignez l'année de référence du coût énergétique.",
|
||||
});
|
||||
min(f.legalProfile.estimatedAnnualEnergyCostReferenceYear, 1900, {
|
||||
message: "L'année de référence énergétique doit être comprise entre 1900 et 2100.",
|
||||
});
|
||||
max(f.legalProfile.estimatedAnnualEnergyCostReferenceYear, 2100, {
|
||||
message: "L'année de référence énergétique doit être comprise entre 1900 et 2100.",
|
||||
});
|
||||
});
|
||||
|
||||
readonly error = signal('');
|
||||
readonly error = signal('');
|
||||
|
||||
constructor() {
|
||||
effect(() => this.resetForm(this.apartment()));
|
||||
}
|
||||
constructor() {
|
||||
effect(() => this.resetForm(this.apartment()));
|
||||
}
|
||||
|
||||
save(): void {
|
||||
if (this.saving()) return;
|
||||
this.apartmentForm().markAsTouched();
|
||||
if (
|
||||
this.apartmentForm().invalid() ||
|
||||
!this.apartmentModel().name.trim() ||
|
||||
!this.apartmentModel().address.trim()
|
||||
) {
|
||||
const firstError = this.apartmentForm().errorSummary()[0];
|
||||
this.error.set(firstError?.message ?? requiredFieldsError);
|
||||
return;
|
||||
}
|
||||
save(): void {
|
||||
if (this.saving()) return;
|
||||
this.apartmentForm().markAsTouched();
|
||||
if (
|
||||
this.apartmentForm().invalid() ||
|
||||
!this.apartmentModel().name.trim() ||
|
||||
!this.apartmentModel().address.trim()
|
||||
) {
|
||||
const firstError = this.apartmentForm().errorSummary()[0];
|
||||
this.error.set(firstError?.message ?? requiredFieldsError);
|
||||
return;
|
||||
}
|
||||
|
||||
this.saved.emit({
|
||||
id: this.apartment()?.id,
|
||||
name: this.apartmentModel().name.trim(),
|
||||
address: this.apartmentModel().address.trim(),
|
||||
purchasePrice: this.apartmentModel().purchasePrice,
|
||||
description: this.apartmentModel().description.trim(),
|
||||
legalProfile: this.normalizedLegalProfile(),
|
||||
privateAreas: this.apartmentModel().privateAreas,
|
||||
});
|
||||
}
|
||||
this.saved.emit({
|
||||
id: this.apartment()?.id,
|
||||
name: this.apartmentModel().name.trim(),
|
||||
address: this.apartmentModel().address.trim(),
|
||||
purchasePrice: this.apartmentModel().purchasePrice,
|
||||
description: this.apartmentModel().description.trim(),
|
||||
legalProfile: this.normalizedLegalProfile(),
|
||||
privateAreas: this.apartmentModel().privateAreas,
|
||||
});
|
||||
}
|
||||
|
||||
setPrivateAreas(privateAreas: PrivateArea[]): void {
|
||||
this.apartmentModel.update((apartment) => ({ ...apartment, privateAreas }));
|
||||
}
|
||||
setPrivateAreas(privateAreas: PrivateArea[]): void {
|
||||
this.apartmentModel.update((apartment) => ({ ...apartment, privateAreas }));
|
||||
}
|
||||
|
||||
private resetForm(apartment: Apartment | null): void {
|
||||
this.apartmentModel.set({
|
||||
id: apartment?.id,
|
||||
name: apartment?.name ?? '',
|
||||
address: apartment?.address ?? '',
|
||||
purchasePrice: apartment?.purchasePrice ?? 0,
|
||||
description: apartment?.description ?? '',
|
||||
legalProfile: apartment?.legalProfile ?? emptyApartmentLegalProfile(),
|
||||
privateAreas: apartment?.privateAreas ?? [],
|
||||
});
|
||||
this.error.set('');
|
||||
}
|
||||
private resetForm(apartment: Apartment | null): void {
|
||||
this.apartmentModel.set({
|
||||
id: apartment?.id,
|
||||
name: apartment?.name ?? '',
|
||||
address: apartment?.address ?? '',
|
||||
purchasePrice: apartment?.purchasePrice ?? 0,
|
||||
description: apartment?.description ?? '',
|
||||
legalProfile: apartment?.legalProfile ?? emptyApartmentLegalProfile(),
|
||||
privateAreas: apartment?.privateAreas ?? [],
|
||||
});
|
||||
this.error.set('');
|
||||
}
|
||||
|
||||
private normalizedLegalProfile(): ApartmentLegalProfile {
|
||||
const profile = this.apartmentModel().legalProfile;
|
||||
return {
|
||||
...profile,
|
||||
estimatedAnnualEnergyCostReferenceYear:
|
||||
profile.estimatedAnnualEnergyCost === null
|
||||
? null
|
||||
: profile.estimatedAnnualEnergyCostReferenceYear,
|
||||
taxIdentifier: profile.taxIdentifier.trim(),
|
||||
ownershipRegime: profile.ownershipRegime.trim(),
|
||||
equipment: profile.equipment.trim(),
|
||||
heating: profile.heating.trim(),
|
||||
hotWater: profile.hotWater.trim(),
|
||||
destination: profile.destination.trim(),
|
||||
privateAccessories: profile.privateAccessories.trim(),
|
||||
commonAreas: profile.commonAreas.trim(),
|
||||
internetAccess: profile.internetAccess.trim(),
|
||||
departmentCode: profile.departmentCode.trim().toUpperCase(),
|
||||
};
|
||||
}
|
||||
private normalizedLegalProfile(): ApartmentLegalProfile {
|
||||
const profile = this.apartmentModel().legalProfile;
|
||||
return {
|
||||
...profile,
|
||||
estimatedAnnualEnergyCostReferenceYear:
|
||||
profile.estimatedAnnualEnergyCost === null
|
||||
? null
|
||||
: profile.estimatedAnnualEnergyCostReferenceYear,
|
||||
taxIdentifier: profile.taxIdentifier.trim(),
|
||||
ownershipRegime: profile.ownershipRegime.trim(),
|
||||
equipment: profile.equipment.trim(),
|
||||
heating: profile.heating.trim(),
|
||||
hotWater: profile.hotWater.trim(),
|
||||
destination: profile.destination.trim(),
|
||||
privateAccessories: profile.privateAccessories.trim(),
|
||||
commonAreas: profile.commonAreas.trim(),
|
||||
internetAccess: profile.internetAccess.trim(),
|
||||
departmentCode: profile.departmentCode.trim().toUpperCase(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user