hl-core 0.0.7-beta.14 → 0.0.7-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,8 @@ import { defineStore } from 'pinia';
2
2
  import { useDataStore } from './data.store';
3
3
  import { useFormStore } from './form.store';
4
4
  import { ErrorHandler } from '../composables';
5
+ import { AxiosError } from 'axios';
6
+ import { Member } from '../composables/classes';
5
7
 
6
8
  export const useMemberStore = defineStore('members', {
7
9
  state: () => ({
@@ -10,15 +12,33 @@ export const useMemberStore = defineStore('members', {
10
12
  dataStore: useDataStore(),
11
13
  formStore: useFormStore(),
12
14
  }),
13
- getters: {},
14
15
  actions: {
16
+ isStatementEditible(whichForm: string, showToaster: boolean = false) {
17
+ if (this.formStore.isDisabled[whichForm as keyof typeof this.formStore.isDisabled] === true) {
18
+ if (showToaster) this.dataStore.showToaster('error', this.dataStore.t('toaster.viewErrorText'), 2000);
19
+ return false;
20
+ }
21
+ return true;
22
+ },
23
+ validateInitiator(showToaster: boolean = true) {
24
+ if (!this.dataStore.isInitiator()) {
25
+ if (showToaster) this.dataStore.showToaster('error', this.dataStore.t('toaster.viewErrorText'));
26
+ return false;
27
+ }
28
+ return true;
29
+ },
15
30
  hasMemberData(whichForm: keyof typeof this.formStore, whichIndex?: number, key: string = 'id', emptyValue: any = 0) {
16
31
  if (!this.validateInitiator(false)) return false;
32
+ if (!this.isStatementEditible(whichForm)) return false;
17
33
  return typeof whichIndex === 'number' ? this.formStore[whichForm][whichIndex][key] != emptyValue : this.formStore[whichForm][key] != emptyValue;
18
34
  },
19
35
  canMemberDeleted(whichForm: keyof typeof this.formStore, whichIndex?: number) {
20
36
  if (!whichForm) return false;
37
+ if (!this.isStatementEditible(whichForm)) return false;
21
38
  if (!this.validateInitiator(false)) return false;
39
+ if (typeof whichIndex === 'number' && whichIndex > 0) {
40
+ return true;
41
+ }
22
42
  if (this.dataStore.isTask() && this.dataStore.isProcessEditable(this.formStore.applicationData.statusCode)) {
23
43
  if (whichForm !== this.formStore.policyholderFormKey) {
24
44
  return this.hasMemberData(whichForm, whichIndex);
@@ -26,8 +46,7 @@ export const useMemberStore = defineStore('members', {
26
46
  }
27
47
  return false;
28
48
  },
29
- getMemberFromStore(whichForm: keyof typeof this.formStore, whichIndex?: number) {
30
- if (!whichForm) return false;
49
+ getMemberFromStore(whichForm: keyof typeof this.formStore, whichIndex?: number): Member | null {
31
50
  switch (whichForm) {
32
51
  case this.formStore.policyholderFormKey:
33
52
  return this.formStore.policyholderForm;
@@ -39,6 +58,8 @@ export const useMemberStore = defineStore('members', {
39
58
  return this.formStore.beneficiaryForm[whichIndex!];
40
59
  case this.formStore.beneficialOwnerFormKey:
41
60
  return this.formStore.beneficialOwnerForm[whichIndex!];
61
+ default:
62
+ return null;
42
63
  }
43
64
  },
44
65
  getMemberFromApplication(whichForm: keyof typeof this.formStore, whichIndex?: number) {
@@ -81,6 +102,8 @@ export const useMemberStore = defineStore('members', {
81
102
  },
82
103
  getMemberCode(whichForm: keyof typeof this.formStore) {
83
104
  switch (whichForm) {
105
+ case this.formStore.policyholderFormKey:
106
+ return 'Client';
84
107
  case this.formStore.insuredFormKey:
85
108
  return 'Insured';
86
109
  case this.formStore.beneficiaryFormKey:
@@ -91,24 +114,15 @@ export const useMemberStore = defineStore('members', {
91
114
  return 'Spokesman';
92
115
  }
93
116
  },
94
- validateInitiator(showToaster: boolean = true) {
95
- if (!this.dataStore.isInitiator()) {
96
- if (showToaster) this.dataStore.showToaster('error', this.dataStore.t('toaster.viewErrorText'));
97
- return false;
98
- }
99
- return true;
100
- },
101
117
  clearMember(whichForm: keyof typeof this.formStore, whichIndex?: number) {
102
118
  if (!whichForm) return false;
119
+ if (!this.isStatementEditible(whichForm)) return false;
103
120
  if (!this.validateInitiator()) return false;
104
121
  const memberClass = this.getMemberClass(whichForm);
105
122
  if (!memberClass) return false;
106
- if (whichForm === this.formStore.policyholderFormKey) {
123
+ if (whichForm === this.formStore.policyholderFormKey || whichForm === this.formStore.policyholdersRepresentativeFormKey) {
107
124
  this.formStore[whichForm].resetForm();
108
125
  }
109
- if (whichForm === this.formStore.policyholdersRepresentativeFormKey) {
110
- this.formStore[whichForm].resetMember();
111
- }
112
126
  if (typeof whichIndex === 'number') {
113
127
  if (this.formStore[whichForm].length === 1) {
114
128
  this.formStore[whichForm][whichIndex] = memberClass;
@@ -120,24 +134,161 @@ export const useMemberStore = defineStore('members', {
120
134
  },
121
135
  async deleteMember(whichForm: keyof typeof this.formStore, whichIndex?: number) {
122
136
  if (!whichForm) return false;
137
+ if (!this.isStatementEditible(whichForm)) return false;
123
138
  if (!this.validateInitiator()) return false;
124
139
  try {
125
140
  const memberCode = this.getMemberCode(whichForm);
141
+ const memberData = this.getMemberFromApplication(whichForm, whichIndex);
126
142
  if (!memberCode) return false;
127
143
  if (typeof whichIndex !== 'number') {
128
144
  if (whichForm === this.formStore.policyholdersRepresentativeFormKey) {
129
145
  await this.dataStore.api.deleteMember(memberCode, this.formStore.applicationData.processInstanceId);
130
146
  }
131
147
  } else {
132
- const memberData = this.getMemberFromApplication(whichForm, whichIndex);
133
- if (!memberData) return false;
134
- await this.dataStore.api.deleteMember(memberCode, memberData.id as number);
148
+ if (memberData) await this.dataStore.api.deleteMember(memberCode, memberData.id as number);
135
149
  }
136
- await this.dataStore.getApplicationData(this.route.params.taskId, true, true, true, false);
150
+ if (memberData) await this.dataStore.getApplicationData(this.route.params.taskId, true, true, true, false);
137
151
  return this.clearMember(whichForm, whichIndex);
138
152
  } catch (err) {
153
+ console.log(err);
139
154
  return ErrorHandler(err);
140
155
  }
141
156
  },
157
+ addMember(whichForm: keyof typeof this.formStore) {
158
+ if (!whichForm) return false;
159
+ if (!this.isStatementEditible(whichForm)) return false;
160
+ if (!this.validateInitiator()) return false;
161
+ this.formStore[whichForm].push(this.getMemberClass(whichForm));
162
+ },
163
+ async getOtpStatus(iin: string, phone: string, processInstanceId: string | number | null = null) {
164
+ try {
165
+ const otpData = {
166
+ iin: iin.replace(/-/g, ''),
167
+ phoneNumber: formatPhone(phone),
168
+ type: 'AgreementOtp',
169
+ };
170
+ return await this.dataStore.api.getOtpStatus(
171
+ processInstanceId !== null && processInstanceId !== 0
172
+ ? {
173
+ ...otpData,
174
+ processInstanceId: processInstanceId,
175
+ }
176
+ : otpData,
177
+ );
178
+ } catch (err) {
179
+ return ErrorHandler(err);
180
+ }
181
+ },
182
+ async checkOtp(member: Member) {
183
+ if (!member.otpTokenId || !member.otpCode || !member.phoneNumber) {
184
+ this.dataStore.showToaster('error', this.dataStore.t('error.noOtpCode'));
185
+ return;
186
+ }
187
+ try {
188
+ this.dataStore.isLoading = true;
189
+ const otpData = {
190
+ tokenId: member.otpTokenId,
191
+ phoneNumber: formatPhone(member.phoneNumber),
192
+ code: member.otpCode.replace(/\s/g, ''),
193
+ };
194
+ const otpResponse = await this.dataStore.api.checkOtp(otpData);
195
+ if (otpResponse !== null) {
196
+ if ('errMessage' in otpResponse && otpResponse.errMessage !== null) {
197
+ this.dataStore.showToaster('error', otpResponse.errMessage, 3000);
198
+ return false;
199
+ }
200
+ if ('status' in otpResponse && !!otpResponse.status) {
201
+ // TODO Доработать и менять значение hasAgreement.value => true
202
+ this.dataStore.showToaster(otpResponse.status !== 2 ? 'error' : 'success', otpResponse.statusName, 3000);
203
+ if (otpResponse.status === 2) {
204
+ return true;
205
+ }
206
+ }
207
+ }
208
+ return false;
209
+ } catch (err) {
210
+ ErrorHandler(err);
211
+ } finally {
212
+ this.dataStore.isLoading = false;
213
+ }
214
+ return null;
215
+ },
216
+ async sendOtp(member: Member, processInstanceId: string | number | null = null, onInit: boolean = false) {
217
+ if (!this.validateInitiator()) return null;
218
+ this.dataStore.isLoading = true;
219
+ let otpStatus: boolean = false;
220
+ let otpResponse: any = {};
221
+ try {
222
+ if (member.iin && member.phoneNumber && member.iin.length === 15 && member.phoneNumber.length === 18) {
223
+ const status = await this.getOtpStatus(member.iin, member.phoneNumber, processInstanceId);
224
+ if (status === true) {
225
+ this.dataStore.showToaster('success', this.dataStore.t('toaster.hasSuccessOtp'), 3000);
226
+ otpStatus = true;
227
+ this.dataStore.isLoading = false;
228
+ return { otpStatus, otpResponse };
229
+ } else if (status === false && onInit === false) {
230
+ const otpData = {
231
+ iin: member.iin.replace(/-/g, ''),
232
+ phoneNumber: formatPhone(member.phoneNumber),
233
+ type: 'AgreementOtp',
234
+ };
235
+ otpResponse = await this.dataStore.api.sendOtp(
236
+ processInstanceId !== null && processInstanceId !== 0
237
+ ? {
238
+ ...otpData,
239
+ processInstanceId: processInstanceId,
240
+ }
241
+ : otpData,
242
+ );
243
+ this.dataStore.isLoading = false;
244
+ if (!!otpResponse) {
245
+ if ('errMessage' in otpResponse && otpResponse.errMessage !== null) {
246
+ this.dataStore.showToaster('error', otpResponse.errMessage, 3000);
247
+ return { otpStatus };
248
+ }
249
+ if ('result' in otpResponse && otpResponse.result === null) {
250
+ if ('statusName' in otpResponse && !!otpResponse.statusName) {
251
+ this.dataStore.showToaster('error', otpResponse.statusName, 3000);
252
+ return { otpStatus };
253
+ }
254
+ if ('status' in otpResponse && !!otpResponse.status) {
255
+ this.dataStore.showToaster('error', otpResponse.status, 3000);
256
+ return { otpStatus };
257
+ }
258
+ }
259
+ if ('tokenId' in otpResponse && otpResponse.tokenId) {
260
+ member.otpTokenId = otpResponse.tokenId;
261
+ this.dataStore.showToaster('success', this.dataStore.t('toaster.successOtp'), 3000);
262
+ }
263
+ } else {
264
+ this.dataStore.showToaster('error', this.dataStore.t('error.snoOtpResponse'), 3000);
265
+ return { otpStatus };
266
+ }
267
+ }
268
+ } else {
269
+ if (onInit === false) {
270
+ this.dataStore.showToaster('error', this.dataStore.t('toaster.errorFormField').replace('{text}', 'Номер телефона, ИИН'));
271
+ this.dataStore.isLoading = false;
272
+ }
273
+ }
274
+ return { otpStatus, otpResponse };
275
+ } catch (err) {
276
+ this.dataStore.isLoading = false;
277
+ if (err instanceof AxiosError)
278
+ if ('response' in err && err.response && err.response.data) {
279
+ if ('statusName' in err.response.data && !!err.response.data.statusName) {
280
+ this.dataStore.showToaster('error', this.dataStore.t('toaster.phoneNotFoundInBMG'), 3000);
281
+ return { otpStatus };
282
+ }
283
+ if ('status' in err.response.data && !!err.response.data.status) {
284
+ this.dataStore.showToaster('error', err.response.data.status, 3000);
285
+ return { otpStatus };
286
+ }
287
+ }
288
+ } finally {
289
+ this.dataStore.isLoading = false;
290
+ }
291
+ return { otpStatus, otpResponse };
292
+ },
142
293
  },
143
294
  });
package/store/messages.ts CHANGED
@@ -28,7 +28,16 @@ export const messages = {
28
28
  rejectCause: 'Причина отказа',
29
29
  returnCause: 'Причина возврата на доработку',
30
30
  },
31
+ error: {
32
+ title: 'Ошибка 404',
33
+ description: 'Страница, которую вы запрашиваете, не существует либо устарела.',
34
+ connectionLost: 'Нет подключения к Интернету',
35
+ checkConnection: 'Проверьте ваше подключение',
36
+ noOtpResponse: 'Отсутствует ответ при отправке OTP кода',
37
+ noOtpCode: 'Заполните поля: ИИН, Номер телефона, Код подтверждения',
38
+ },
31
39
  toaster: {
40
+ noIinOrPhone: 'Отсутствуют данные для отправки СМС',
32
41
  ESBDErrorMessage: 'Введены не корректные данные по этому ИИН',
33
42
  phoneNotFoundInBMG: 'Введите номер зарегистрированный в БМГ или зарегистрируйте клиента в БМГ',
34
43
  errorSumOrPercentage: 'Процент от суммы выплат не может быть меньше или больше 100',
@@ -92,6 +101,7 @@ export const messages = {
92
101
  tokenExpire: 'Истекло время ожидания',
93
102
  },
94
103
  buttons: {
104
+ add: 'Добавить',
95
105
  userLogin: 'Логин',
96
106
  password: 'Пароль',
97
107
  login: 'Вход в систему',
@@ -134,12 +144,6 @@ export const messages = {
134
144
  accept: 'Одобрить',
135
145
  reject: 'Отказать',
136
146
  },
137
- error: {
138
- title: 'Ошибка 404',
139
- description: 'Страница, которую вы запрашиваете, не существует либо устарела.',
140
- connectionLost: 'Нет подключения к Интернету',
141
- checkConnection: 'Проверьте ваше подключение',
142
- },
143
147
  dialog: {
144
148
  title: 'Подтверждение',
145
149
  exit: 'Вы действительно хотите выйти?',
@@ -194,6 +198,7 @@ export const messages = {
194
198
  generalConditions: 'Основные условия страхования',
195
199
  isPolicyholderInsured: 'Является ли страхователь застрахованным?',
196
200
  isPolicyholderIPDL: 'Принадлежит ли и/или причастен ли Застрахованный / Страхователь или его члены семьи и близкие родственники к иностранному публичному должностному лицу?',
201
+ isMemberIPDL: 'Отметка о принадлежности и/или причастности к публичному должностному лицу, его супруге (супругу) и близким родственникам?',
197
202
  isPolicyholderBeneficiary: 'Является ли страхователь выгодоприобретателем?',
198
203
  hasRepresentative: 'Подписантом договора выступает представитель? ',
199
204
  isActOwnBehalf: ' Клиент действует от своего имени и в своих интересах?',
@@ -231,6 +236,9 @@ export const messages = {
231
236
  conditions: 'Условия оплаты страховой премии',
232
237
  processTariff: 'Тариф',
233
238
  riskGroup: 'Группа риска',
239
+ requestedProductConditions: 'Запрашиваемые условия страхования',
240
+ coverPeriodFrom3to20: 'Срок страхования (от 3-х до 20 лет)',
241
+ insurancePremiumAmount: 'Размер Страховой премии (страховой взнос)',
234
242
  },
235
243
  history: {
236
244
  addRegNumber: 'Номер',
@@ -301,7 +309,7 @@ export const messages = {
301
309
  basisDocRu: 'Действует на основании документа (рус)',
302
310
  basisDocRuParentCase: 'Действует на основании документа в родительском падеже (рус)',
303
311
  numberDoc: 'Номер документа подтверждающий полномочия',
304
- numberVisa: 'Номер визы или миграционный карточки',
312
+ numberVisa: 'Номер миграционный карточки',
305
313
  numberLicense: 'Номер лицензии',
306
314
  confirmAuthority: 'Лицо, подписавшего документ, подтверждающий полномочия, -Нотариус?',
307
315
  documentIssuers: 'Наименование органа, выдавшего документ',
@@ -322,6 +330,8 @@ export const messages = {
322
330
  recipientNumber: 'Номер получателя СМС',
323
331
  },
324
332
  form: {
333
+ migrationCard: '',
334
+ postIndex: 'Почтовый индекс',
325
335
  name: 'Наименование',
326
336
  bin: 'БИН',
327
337
  fullName: 'ФИО',
package/store/rules.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { t } from './messages';
2
+ import { formatDate } from '../composables';
2
3
 
3
4
  export const rules = {
4
5
  recalculationMultiply: [v => (v !== null && v !== '' && v >= 100) || t('toaster.valueShouldBeHigher', { text: 100 })],