Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

family-service.ts 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import { Injectable } from '@angular/core';
  2. import { Family } from '../models/family';
  3. @Injectable({
  4. providedIn: 'root',
  5. })
  6. export class FamilyService {
  7. private families: Family[] = [
  8. {
  9. id: '1',
  10. dankaId: '1',
  11. furigana: 'すずき はなこ',
  12. name: '鈴木 花子',
  13. relationship: '母',
  14. birthDate: '1975-01-01',
  15. note: '次の世帯主',
  16. fatherId: '5',
  17. motherId: '6',
  18. spouseId: '3',
  19. },
  20. {
  21. id: '2',
  22. dankaId: '1',
  23. furigana: 'すずき たろう',
  24. name: '鈴木 太郎',
  25. relationship: '長男',
  26. birthDate: '2005-12-31',
  27. note: '',
  28. fatherId: '3',
  29. motherId: '1',
  30. spouseId: '7',
  31. },
  32. {
  33. id: '3',
  34. dankaId: '1',
  35. furigana: 'すずき いちろう',
  36. name: '鈴木 一郎',
  37. relationship: '父',
  38. birthDate: '1973-05-10',
  39. note: '',
  40. fatherId: '',
  41. motherId: '',
  42. spouseId: '1',
  43. },
  44. {
  45. id: '4',
  46. dankaId: '1',
  47. furigana: 'すずき さくら',
  48. name: '鈴木 さくら',
  49. relationship: '長女',
  50. birthDate: '2008-04-15',
  51. note: '',
  52. fatherId: '3',
  53. motherId: '1',
  54. spouseId: '',
  55. },
  56. {
  57. id: '5',
  58. dankaId: '1',
  59. furigana: 'さとう まさお',
  60. name: '佐藤 正男',
  61. relationship: '母方の祖父',
  62. birthDate: '1948-03-20',
  63. note: '花子の父',
  64. fatherId: '',
  65. motherId: '',
  66. spouseId: '6',
  67. },
  68. {
  69. id: '6',
  70. dankaId: '1',
  71. furigana: 'さとう ひさこ',
  72. name: '佐藤 久子',
  73. relationship: '母方の祖母',
  74. birthDate: '1950-09-08',
  75. note: '花子の母',
  76. fatherId: '',
  77. motherId: '',
  78. spouseId: '5',
  79. },
  80. {
  81. id: '7',
  82. dankaId: '1',
  83. furigana: 'すずき みさき',
  84. name: '鈴木 美咲',
  85. relationship: '長男の妻',
  86. birthDate: '2006-07-22',
  87. note: '',
  88. fatherId: '',
  89. motherId: '',
  90. spouseId: '2',
  91. },
  92. {
  93. id: '8',
  94. dankaId: '1',
  95. furigana: 'すずき れん',
  96. name: '鈴木 蓮',
  97. relationship: '孫',
  98. birthDate: '2026-02-01',
  99. note: '太郎と美咲の子',
  100. fatherId: '2',
  101. motherId: '7',
  102. spouseId: '',
  103. },
  104. ];
  105. //檀家と紐づいている家族情報の取得
  106. getFamiliesByDankaId(dankaId: string): Family[] {
  107. return this.families.filter((family) => family.dankaId === dankaId);
  108. }
  109. //家族の情報を取得
  110. getFamilyById(id: string): Family | undefined {
  111. return this.families.find((family) => family.id === id);
  112. }
  113. //家族の情報を更新
  114. saveFamily(updateFamily: Family) {
  115. const index = this.families.findIndex((families) => families.id === updateFamily.id);
  116. if (index === -1) {
  117. this.families.push(updateFamily);
  118. return;
  119. }
  120. this.families[index] = updateFamily;
  121. }
  122. //家族の情報を削除
  123. deleteFamily(id: string | undefined) {
  124. const index = this.families.findIndex((family) => family.id === id);
  125. if (index === -1) {
  126. return;
  127. }
  128. this.families.splice(index, 1);
  129. }
  130. //家族情報を全件取得する処理
  131. getFamilyList(): Family[] {
  132. return this.families;
  133. }
  134. }