fix: validate tenant and lease contact details
This commit is contained in:
1 parent
8603b98714
commit
bf6d8e6bb6
27 files changed
+444
-54
No files matched your search
+17
-1
@@ -41,6 +41,7 @@ export class App implements OnInit {
|
||||
readonly apartments = signal<Apartment[]>([]);
|
||||
readonly tenants = signal<Tenant[]>([]);
|
||||
readonly leases = signal<Lease[]>([]);
|
||||
readonly tenantAttachmentError = signal('');
|
||||
private readonly _isLoggedIn = signal<boolean>(false);
|
||||
private readonly _username = signal<string>('');
|
||||
private readonly _email = signal<string>('');
|
||||
@@ -179,9 +180,13 @@ export class App implements OnInit {
|
||||
}
|
||||
|
||||
uploadTenantAttachment(request: { tenantId: string; file: File }): void {
|
||||
this.tenantAttachmentError.set('');
|
||||
this.tenantService.uploadAttachment(request.tenantId, request.file).subscribe({
|
||||
next: () => this.loadTenants(),
|
||||
error: (err) => console.error('Error uploading tenant attachment', err),
|
||||
error: (error: unknown) => {
|
||||
console.error('Error uploading tenant attachment', error);
|
||||
this.tenantAttachmentError.set(this.errorMessage(error, 'Impossible d’envoyer cette pièce jointe.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -234,4 +239,15 @@ export class App implements OnInit {
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
private errorMessage(error: unknown, fallback: string): string {
|
||||
if (typeof error !== 'object' || error === null || !('error' in error)) {
|
||||
return fallback;
|
||||
}
|
||||
const response = error.error;
|
||||
if (typeof response !== 'object' || response === null || !('message' in response)) {
|
||||
return fallback;
|
||||
}
|
||||
return typeof response.message === 'string' ? response.message : fallback;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user