|
|
@@ -123,14 +123,42 @@ export class FamilyService {
|
|
123
|
123
|
}
|
|
124
|
124
|
|
|
125
|
125
|
//家族の情報を更新
|
|
126
|
|
- saveFamily(updateFamily: Family) {
|
|
127
|
|
- const index = this.families.findIndex((families) => families.id === updateFamily.id);
|
|
128
|
|
- if (index === -1) {
|
|
129
|
|
- this.families.push(updateFamily);
|
|
130
|
|
- return;
|
|
|
126
|
+ saveFamily(updatedFamily: Family): void {
|
|
|
127
|
+ const oldFamily = this.families.find((family) => family.id === updatedFamily.id);
|
|
|
128
|
+
|
|
|
129
|
+ const oldSpouseId = oldFamily?.spouseId ?? '';
|
|
|
130
|
+ const newSpouseId = updatedFamily.spouseId ?? '';
|
|
|
131
|
+
|
|
|
132
|
+ const familyIndex = this.families.findIndex((family) => family.id === updatedFamily.id);
|
|
|
133
|
+
|
|
|
134
|
+ if (familyIndex !== -1) {
|
|
|
135
|
+ this.families[familyIndex] = updatedFamily;
|
|
|
136
|
+ } else {
|
|
|
137
|
+ this.families.push(updatedFamily);
|
|
|
138
|
+ }
|
|
|
139
|
+
|
|
|
140
|
+ if (oldSpouseId && oldSpouseId !== newSpouseId) {
|
|
|
141
|
+ const oldSpouseIndex = this.families.findIndex((family) => family.id === oldSpouseId);
|
|
|
142
|
+ if (oldSpouseIndex !== -1 && this.families[oldSpouseIndex].spouseId === updatedFamily.id) {
|
|
|
143
|
+ this.families[oldSpouseIndex] = {
|
|
|
144
|
+ ...this.families[oldSpouseIndex],
|
|
|
145
|
+ spouseId: '',
|
|
|
146
|
+ };
|
|
|
147
|
+ }
|
|
|
148
|
+ }
|
|
|
149
|
+
|
|
|
150
|
+ if (newSpouseId) {
|
|
|
151
|
+ const newSpouseIndex = this.families.findIndex((family) => family.id === newSpouseId);
|
|
|
152
|
+
|
|
|
153
|
+ if (newSpouseIndex !== -1) {
|
|
|
154
|
+ this.families[newSpouseIndex] = {
|
|
|
155
|
+ ...this.families[newSpouseIndex],
|
|
|
156
|
+ spouseId: updatedFamily.id,
|
|
|
157
|
+ };
|
|
|
158
|
+ }
|
|
131
|
159
|
}
|
|
132
|
|
- this.families[index] = updateFamily;
|
|
133
|
160
|
}
|
|
|
161
|
+
|
|
134
|
162
|
//家族の情報を削除
|
|
135
|
163
|
deleteFamily(id: string | undefined) {
|
|
136
|
164
|
const index = this.families.findIndex((family) => family.id === id);
|