|
|
@@ -23,7 +23,7 @@ import { MarriageRelation } from '../../models/marriage-relation';
|
|
23
|
23
|
templateUrl: './family-edit.html',
|
|
24
|
24
|
styleUrl: './family-edit.scss',
|
|
25
|
25
|
})
|
|
26
|
|
-export class FamilyEdit implements OnInit{
|
|
|
26
|
+export class FamilyEdit implements OnInit {
|
|
27
|
27
|
danka: Danka | undefined;
|
|
28
|
28
|
family: Family | undefined;
|
|
29
|
29
|
families: Family[] = [];
|
|
|
@@ -135,14 +135,13 @@ export class FamilyEdit implements OnInit{
|
|
135
|
135
|
return this.families.filter((family) => family.id !== this.familyId);
|
|
136
|
136
|
}
|
|
137
|
137
|
|
|
138
|
|
- patchMarriageRelationFields(familyId: string): void {
|
|
139
|
|
- const relations = this.marriageRelationService.getMarriageRelationsByFamilyId(familyId);
|
|
|
138
|
+ async patchMarriageRelationFields(familyId: string): Promise<void> {
|
|
|
139
|
+ const relations = await this.marriageRelationService.getMarriageRelationsByFamilyId(familyId);
|
|
|
140
|
+
|
|
140
|
141
|
const relation =
|
|
141
|
142
|
relations.find((marriageRelation) => marriageRelation.status === 'current') ?? relations[0];
|
|
142
|
143
|
|
|
143
|
|
- if (!relation) {
|
|
144
|
|
- return;
|
|
145
|
|
- }
|
|
|
144
|
+ if (!relation) return;
|
|
146
|
145
|
|
|
147
|
146
|
this.familyForm.patchValue({
|
|
148
|
147
|
spouseId: relation.person1Id === familyId ? relation.person2Id : relation.person1Id,
|
|
|
@@ -150,17 +149,21 @@ export class FamilyEdit implements OnInit{
|
|
150
|
149
|
});
|
|
151
|
150
|
}
|
|
152
|
151
|
|
|
153
|
|
- findMarriageRelation(person1Id: string, person2Id: string): MarriageRelation | undefined {
|
|
154
|
|
- return this.marriageRelationService
|
|
155
|
|
- .getMarriageRelationsByFamilyId(person1Id)
|
|
156
|
|
- .find(
|
|
157
|
|
- (relation) =>
|
|
158
|
|
- (relation.person1Id === person1Id && relation.person2Id === person2Id) ||
|
|
159
|
|
- (relation.person1Id === person2Id && relation.person2Id === person1Id),
|
|
160
|
|
- );
|
|
|
152
|
+ async findMarriageRelation(
|
|
|
153
|
+ person1Id: string,
|
|
|
154
|
+ person2Id: string
|
|
|
155
|
+ ): Promise<MarriageRelation | undefined> {
|
|
|
156
|
+
|
|
|
157
|
+ const relations = await this.marriageRelationService.getMarriageRelationsByFamilyId(person1Id);
|
|
|
158
|
+
|
|
|
159
|
+ return relations.find(
|
|
|
160
|
+ (relation) =>
|
|
|
161
|
+ (relation.person1Id === person1Id && relation.person2Id === person2Id) ||
|
|
|
162
|
+ (relation.person1Id === person2Id && relation.person2Id === person1Id),
|
|
|
163
|
+ );
|
|
161
|
164
|
}
|
|
162
|
165
|
|
|
163
|
|
- saveFamily() {
|
|
|
166
|
+ async saveFamily() {
|
|
164
|
167
|
if (this.familyForm.invalid) {
|
|
165
|
168
|
return;
|
|
166
|
169
|
}
|
|
|
@@ -187,9 +190,10 @@ export class FamilyEdit implements OnInit{
|
|
187
|
190
|
};
|
|
188
|
191
|
|
|
189
|
192
|
if (spouseId) {
|
|
190
|
|
- const existingRelation = this.findMarriageRelation(familyId, spouseId);
|
|
191
|
|
- const errors = this.marriageRelationService.saveMarriageRelation({
|
|
192
|
|
- id: existingRelation?.id ?? Date.now().toString(),
|
|
|
193
|
+ const existingRelation = await this.findMarriageRelation(familyId, spouseId);
|
|
|
194
|
+
|
|
|
195
|
+ const errors = await this.marriageRelationService.saveMarriageRelation({
|
|
|
196
|
+ id: existingRelation?.id ?? crypto.randomUUID(),
|
|
193
|
197
|
dankaId,
|
|
194
|
198
|
person1Id: familyId,
|
|
195
|
199
|
person2Id: spouseId,
|
|
|
@@ -204,7 +208,7 @@ export class FamilyEdit implements OnInit{
|
|
204
|
208
|
return;
|
|
205
|
209
|
}
|
|
206
|
210
|
} else {
|
|
207
|
|
- const currentMarriage = this.marriageRelationService.getCurrentMarriageByFamilyId(familyId);
|
|
|
211
|
+ const currentMarriage = await this.marriageRelationService.getCurrentMarriageByFamilyId(familyId);
|
|
208
|
212
|
if (currentMarriage) {
|
|
209
|
213
|
this.marriageRelationService.deleteMarriageRelation(currentMarriage.id);
|
|
210
|
214
|
}
|