podverse-orm 5.1.15-alpha.0 → 5.1.16-alpha.1

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.
Files changed (50) hide show
  1. package/dist/config/index.d.ts +7 -0
  2. package/dist/config/index.d.ts.map +1 -1
  3. package/dist/config/index.js +7 -0
  4. package/dist/db/index.d.ts.map +1 -1
  5. package/dist/db/index.js +10 -0
  6. package/dist/entities/account/account.d.ts +2 -0
  7. package/dist/entities/account/account.d.ts.map +1 -1
  8. package/dist/entities/account/account.js +5 -0
  9. package/dist/entities/account/accountFCMDevice.d.ts +6 -0
  10. package/dist/entities/account/accountFCMDevice.d.ts.map +1 -1
  11. package/dist/entities/account/accountFCMDevice.js +21 -1
  12. package/dist/entities/account/accountNotificationChannel.d.ts +3 -0
  13. package/dist/entities/account/accountNotificationChannel.d.ts.map +1 -1
  14. package/dist/entities/account/accountNotificationChannel.js +13 -3
  15. package/dist/entities/account/accountNotificationChannelType.d.ts +8 -0
  16. package/dist/entities/account/accountNotificationChannelType.d.ts.map +1 -0
  17. package/dist/entities/account/accountNotificationChannelType.js +34 -0
  18. package/dist/entities/account/accountSettings/accountSettings.d.ts +11 -0
  19. package/dist/entities/account/accountSettings/accountSettings.d.ts.map +1 -0
  20. package/dist/entities/account/accountSettings/accountSettings.js +43 -0
  21. package/dist/entities/account/accountSettings/accountSettingsLocale.d.ts +8 -0
  22. package/dist/entities/account/accountSettings/accountSettingsLocale.d.ts.map +1 -0
  23. package/dist/entities/account/accountSettings/accountSettingsLocale.js +38 -0
  24. package/dist/entities/account/accountSettings/accountSettingsNotification.d.ts +9 -0
  25. package/dist/entities/account/accountSettings/accountSettingsNotification.d.ts.map +1 -0
  26. package/dist/entities/account/accountSettings/accountSettingsNotification.js +38 -0
  27. package/dist/entities/account/accountSettings/accountSettingsNotificationType.d.ts +9 -0
  28. package/dist/entities/account/accountSettings/accountSettingsNotificationType.d.ts.map +1 -0
  29. package/dist/entities/account/accountSettings/accountSettingsNotificationType.js +38 -0
  30. package/dist/index.d.ts +8 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +8 -0
  33. package/dist/services/account/account.d.ts +4 -1
  34. package/dist/services/account/account.d.ts.map +1 -1
  35. package/dist/services/account/account.js +97 -6
  36. package/dist/services/account/accountFCMDevice.d.ts +9 -3
  37. package/dist/services/account/accountFCMDevice.d.ts.map +1 -1
  38. package/dist/services/account/accountFCMDevice.js +73 -14
  39. package/dist/services/account/accountNotificationChannel.d.ts.map +1 -1
  40. package/dist/services/account/accountNotificationChannel.js +20 -1
  41. package/dist/services/account/accountNotificationChannelType.d.ts +13 -0
  42. package/dist/services/account/accountNotificationChannelType.d.ts.map +1 -0
  43. package/dist/services/account/accountNotificationChannelType.js +67 -0
  44. package/dist/services/account/accountSettings/accountSettingsLocale.d.ts +20 -0
  45. package/dist/services/account/accountSettings/accountSettingsLocale.d.ts.map +1 -0
  46. package/dist/services/account/accountSettings/accountSettingsLocale.js +73 -0
  47. package/dist/services/account/accountSettings/accountSettingsNotificationType.d.ts +16 -0
  48. package/dist/services/account/accountSettings/accountSettingsNotificationType.d.ts.map +1 -0
  49. package/dist/services/account/accountSettings/accountSettingsNotificationType.js +61 -0
  50. package/package.json +2 -5
@@ -13,7 +13,6 @@ exports.AccountService = void 0;
13
13
  const podverse_helpers_1 = require("podverse-helpers");
14
14
  const account_1 = require("@orm/entities/account/account");
15
15
  const db_1 = require("@orm/db");
16
- const podverse_helpers_2 = require("podverse-helpers");
17
16
  const sharableStatus_1 = require("@orm/entities/sharableStatus");
18
17
  const password_1 = require("@orm/lib/password");
19
18
  const accountCredentials_1 = require("./accountCredentials");
@@ -21,6 +20,16 @@ const accountMembershipStatus_1 = require("./accountMembershipStatus");
21
20
  const accountVerification_1 = require("./accountVerification");
22
21
  const accountResetPassword_1 = require("./accountResetPassword");
23
22
  const accountProfile_1 = require("./accountProfile");
23
+ const accountSettings_1 = require("@orm/entities/account/accountSettings/accountSettings");
24
+ const accountSettingsLocale_1 = require("@orm/entities/account/accountSettings/accountSettingsLocale");
25
+ const accountSettingsNotification_1 = require("@orm/entities/account/accountSettings/accountSettingsNotification");
26
+ const accountSettingsNotificationType_1 = require("@orm/entities/account/accountSettings/accountSettingsNotificationType");
27
+ const requiredRelations = [
28
+ 'account_settings',
29
+ 'account_settings.account_settings_locale',
30
+ 'account_settings.account_settings_notification',
31
+ 'account_settings.account_settings_notification.account_settings_notification_types'
32
+ ];
24
33
  class AccountService {
25
34
  constructor() {
26
35
  this.repositoryRead = db_1.AppDataSourceRead.getRepository(account_1.Account);
@@ -31,7 +40,18 @@ class AccountService {
31
40
  if (!id) {
32
41
  return null;
33
42
  }
34
- return this.repositoryRead.findOne(Object.assign({ where: { id } }, config));
43
+ let mergedRelations;
44
+ if ((config === null || config === void 0 ? void 0 : config.relations) && Array.isArray(config.relations)) {
45
+ mergedRelations = Array.from(new Set([...config.relations, ...requiredRelations]));
46
+ }
47
+ else {
48
+ mergedRelations = requiredRelations;
49
+ }
50
+ const account = yield this.repositoryRead.findOne(Object.assign(Object.assign({ where: { id } }, (config || {})), { relations: mergedRelations }));
51
+ if (!account)
52
+ return null;
53
+ yield this.ensureAccountSettings(account, { alwaysCreate: false, locale: 'en-US' });
54
+ return this.repositoryRead.findOne({ where: { id }, relations: mergedRelations });
35
55
  });
36
56
  }
37
57
  getByEmail(email, config) {
@@ -59,14 +79,14 @@ class AccountService {
59
79
  }
60
80
  create(dto, qaVerified) {
61
81
  return __awaiter(this, void 0, void 0, function* () {
62
- if (!(0, podverse_helpers_2.validateEmail)(dto.email)) {
82
+ if (!(0, podverse_helpers_1.validateEmail)(dto.email)) {
63
83
  throw new Error('Invalid email');
64
84
  }
65
- if (!(0, podverse_helpers_2.validatePassword)(dto.password)) {
85
+ if (!(0, podverse_helpers_1.validatePassword)(dto.password)) {
66
86
  throw new Error('Invalid password');
67
87
  }
68
88
  const sharableStatusRepository = db_1.AppDataSourceRead.getRepository(sharableStatus_1.SharableStatus);
69
- const sharableStatus = yield sharableStatusRepository.findOne({ where: { id: podverse_helpers_2.SharableStatusEnum.Private } });
89
+ const sharableStatus = yield sharableStatusRepository.findOne({ where: { id: podverse_helpers_1.SharableStatusEnum.Private } });
70
90
  if (!sharableStatus) {
71
91
  throw new Error('SharableStatus not found');
72
92
  }
@@ -80,6 +100,7 @@ class AccountService {
80
100
  verified: qaVerified !== null && qaVerified !== void 0 ? qaVerified : false
81
101
  });
82
102
  const account = yield this.repositoryReadWrite.save(accountObj);
103
+ yield this.ensureAccountSettings(account, { alwaysCreate: true, locale: dto.locale });
83
104
  const saltedPassword = yield (0, password_1.hashPassword)(dto.password);
84
105
  yield accountCredentialsService.update(account, {
85
106
  email: dto.email,
@@ -89,7 +110,7 @@ class AccountService {
89
110
  const membership_expires_at = new Date();
90
111
  membership_expires_at.setMonth(membership_expires_at.getMonth() + 3);
91
112
  yield accountMembershipStatusService.update(account, {
92
- account_membership_id: podverse_helpers_2.AccountMembershipEnum.Trial,
113
+ account_membership_id: podverse_helpers_1.AccountMembershipEnum.Trial,
93
114
  membership_expires_at
94
115
  });
95
116
  });
@@ -117,6 +138,15 @@ class AccountService {
117
138
  account.sharable_status = sharableStatus;
118
139
  yield this.repositoryReadWrite.save(account);
119
140
  }
141
+ const accountSettings = yield db_1.AppDataSourceReadWrite.getRepository(accountSettings_1.AccountSettings).findOne({
142
+ where: { account_id },
143
+ relations: ['account_settings_locale']
144
+ });
145
+ if (accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.account_settings_locale) {
146
+ const localeRepo = db_1.AppDataSourceReadWrite.getRepository(accountSettingsLocale_1.AccountSettingsLocale);
147
+ accountSettings.account_settings_locale.locale = dto.locale;
148
+ yield localeRepo.save(accountSettings.account_settings_locale);
149
+ }
120
150
  return this.repositoryReadWrite.findOne({ where: { id: account_id }, relations: ['account_profile', 'sharable_status'] });
121
151
  });
122
152
  }
@@ -156,5 +186,66 @@ class AccountService {
156
186
  yield this.repositoryReadWrite.remove(account);
157
187
  });
158
188
  }
189
+ ensureAccountSettings(account, params) {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ const accountSettingsRepo = db_1.AppDataSourceReadWrite.getRepository(accountSettings_1.AccountSettings);
192
+ const localeRepo = db_1.AppDataSourceReadWrite.getRepository(accountSettingsLocale_1.AccountSettingsLocale);
193
+ const notificationRepo = db_1.AppDataSourceReadWrite.getRepository(accountSettingsNotification_1.AccountSettingsNotification);
194
+ // If alwaysCreate (used by create), always create new AccountSettings row linked to the account
195
+ if (params.alwaysCreate || !account.account_settings) {
196
+ // First, create and save AccountSettings
197
+ const accountSettings = new accountSettings_1.AccountSettings();
198
+ accountSettings.account_id = account.id;
199
+ const savedAccountSettings = yield accountSettingsRepo.save(accountSettings);
200
+ // Then create and save the locale with the proper foreign key
201
+ const locale = new accountSettingsLocale_1.AccountSettingsLocale();
202
+ locale.account_settings_id = savedAccountSettings.id;
203
+ locale.locale = params.locale;
204
+ yield localeRepo.save(locale);
205
+ // Then create and save the notification with the proper foreign key
206
+ const notification = new accountSettingsNotification_1.AccountSettingsNotification();
207
+ notification.account_settings_id = savedAccountSettings.id;
208
+ yield notificationRepo.save(notification);
209
+ // Finally, create and save the notification types
210
+ const t1 = new accountSettingsNotificationType_1.AccountSettingsNotificationType();
211
+ t1.account_settings_notification_id = notification.id;
212
+ t1.type = podverse_helpers_1.AccountNotificationTypeEnum.NewItem;
213
+ const t2 = new accountSettingsNotificationType_1.AccountSettingsNotificationType();
214
+ t2.account_settings_notification_id = notification.id;
215
+ t2.type = podverse_helpers_1.AccountNotificationTypeEnum.LivestreamStarting;
216
+ const notificationTypeRepo = db_1.AppDataSourceReadWrite.getRepository(accountSettingsNotificationType_1.AccountSettingsNotificationType);
217
+ yield notificationTypeRepo.save([t1, t2]);
218
+ return;
219
+ }
220
+ // Otherwise (used by get) ensure sub-rows exist, create only if missing
221
+ const existingSettings = account.account_settings;
222
+ if (!existingSettings.account_settings_locale) {
223
+ const locale = new accountSettingsLocale_1.AccountSettingsLocale();
224
+ locale.account_settings_id = existingSettings.id;
225
+ locale.locale = params.locale;
226
+ yield localeRepo.save(locale);
227
+ }
228
+ if (!existingSettings.account_settings_notification) {
229
+ const notification = new accountSettingsNotification_1.AccountSettingsNotification();
230
+ notification.account_settings_id = existingSettings.id;
231
+ const t1 = new accountSettingsNotificationType_1.AccountSettingsNotificationType();
232
+ t1.type = podverse_helpers_1.AccountNotificationTypeEnum.NewItem;
233
+ const t2 = new accountSettingsNotificationType_1.AccountSettingsNotificationType();
234
+ t2.type = podverse_helpers_1.AccountNotificationTypeEnum.LivestreamStarting;
235
+ notification.account_settings_notification_types = [t1, t2];
236
+ yield notificationRepo.save(notification);
237
+ }
238
+ else if (!existingSettings.account_settings_notification.account_settings_notification_types || existingSettings.account_settings_notification.account_settings_notification_types.length === 0) {
239
+ // add default types if missing
240
+ const notification = existingSettings.account_settings_notification;
241
+ const t1 = new accountSettingsNotificationType_1.AccountSettingsNotificationType();
242
+ t1.type = podverse_helpers_1.AccountNotificationTypeEnum.NewItem;
243
+ const t2 = new accountSettingsNotificationType_1.AccountSettingsNotificationType();
244
+ t2.type = podverse_helpers_1.AccountNotificationTypeEnum.LivestreamStarting;
245
+ notification.account_settings_notification_types = [t1, t2];
246
+ yield notificationRepo.save(notification);
247
+ }
248
+ });
249
+ }
159
250
  }
160
251
  exports.AccountService = AccountService;
@@ -1,12 +1,18 @@
1
+ import { CreateAccountFCMDeviceParams, UpdateAccountFCMDeviceParams, DeleteAccountFCMDeviceParams } from 'podverse-helpers';
1
2
  import { AccountFCMDevice } from '@orm/entities/account/accountFCMDevice';
2
3
  import { BaseManyService } from '@orm/services/base/baseManyService';
3
4
  export declare class AccountFCMDeviceService extends BaseManyService<AccountFCMDevice, 'account'> {
4
5
  private accountService;
5
6
  private accountNotificationChannelService;
6
7
  constructor();
7
- create(account_id: number, fcm_token: string): Promise<AccountFCMDevice>;
8
- update(account_id: number, previous_fcm_token: string, new_fcm_token: string): Promise<AccountFCMDevice>;
9
- delete(account_id: number, fcm_token: string): Promise<void>;
8
+ create(account_id: number, params: CreateAccountFCMDeviceParams): Promise<AccountFCMDevice>;
9
+ update(account_id: number, params: UpdateAccountFCMDeviceParams): Promise<AccountFCMDevice>;
10
+ delete(account_id: number, params: DeleteAccountFCMDeviceParams): Promise<void>;
10
11
  getFCMTokensByChannelIdText(channel_id_text: string): Promise<string[]>;
12
+ getAllForAccount(account_id: number): Promise<AccountFCMDevice[]>;
13
+ getAllForAccountIds(account_ids: number[]): Promise<AccountFCMDevice[]>;
14
+ updateLocaleForAccount(account_id: number, params: {
15
+ locale: string;
16
+ }): Promise<void>;
11
17
  }
12
18
  //# sourceMappingURL=accountFCMDevice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"accountFCMDevice.d.ts","sourceRoot":"","sources":["../../../src/services/account/accountFCMDevice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAIrE,qBAAa,uBAAwB,SAAQ,eAAe,CAAC,gBAAgB,EAAE,SAAS,CAAC;IACvF,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,iCAAiC,CAAoC;;IAQvE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAUxE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAexG,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS5D,2BAA2B,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAa9E"}
1
+ {"version":3,"file":"accountFCMDevice.d.ts","sourceRoot":"","sources":["../../../src/services/account/accountFCMDevice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EACnC,4BAA4B,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAEvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAIrE,qBAAa,uBAAwB,SAAQ,eAAe,CAAC,gBAAgB,EAAE,SAAS,CAAC;IACvF,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,iCAAiC,CAAoC;;IAQvE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAa3F,MAAM,CACV,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,gBAAgB,CAAC;IA+BtB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB/E,2BAA2B,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAcvE,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAIjE,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAKvE,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAc5F"}
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AccountFCMDeviceService = void 0;
13
+ const typeorm_1 = require("typeorm");
13
14
  const accountFCMDevice_1 = require("@orm/entities/account/accountFCMDevice");
14
15
  const baseManyService_1 = require("@orm/services/base/baseManyService");
15
16
  const account_1 = require("@orm/services/account/account");
@@ -20,37 +21,69 @@ class AccountFCMDeviceService extends baseManyService_1.BaseManyService {
20
21
  this.accountService = new account_1.AccountService();
21
22
  this.accountNotificationChannelService = new accountNotificationChannel_1.AccountNotificationChannelService();
22
23
  }
23
- create(account_id, fcm_token) {
24
+ create(account_id, params) {
24
25
  return __awaiter(this, void 0, void 0, function* () {
26
+ var _a, _b;
25
27
  const account = yield this.accountService.get(account_id);
26
28
  if (!account) {
27
- throw new Error("Account not found.");
29
+ throw new Error('Account not found.');
28
30
  }
29
- const dto = { fcm_token };
30
- return this._update(account, ['fcm_token'], dto);
31
+ const { fcm_token, installation_id, platform } = params;
32
+ const locale = ((_b = (_a = account.account_settings) === null || _a === void 0 ? void 0 : _a.account_settings_locale) === null || _b === void 0 ? void 0 : _b.locale) || 'en-US';
33
+ const dto = { fcm_token, installation_id, platform, locale };
34
+ return this._update(account, ['fcm_token', 'installation_id', 'platform', 'locale'], dto);
31
35
  });
32
36
  }
33
- update(account_id, previous_fcm_token, new_fcm_token) {
37
+ update(account_id, params) {
34
38
  return __awaiter(this, void 0, void 0, function* () {
39
+ var _a, _b;
35
40
  const account = yield this.accountService.get(account_id);
36
41
  if (!account) {
37
- throw new Error("Account not found.");
42
+ throw new Error('Account not found.');
38
43
  }
39
- const existingDevice = yield this.repositoryRead.findOne({ where: { account_id, fcm_token: previous_fcm_token } });
40
- if (!existingDevice) {
41
- throw new Error("FCM device not found.");
44
+ const { new_fcm_token, installation_id, previous_fcm_token, platform } = params;
45
+ const locale = ((_b = (_a = account.account_settings) === null || _a === void 0 ? void 0 : _a.account_settings_locale) === null || _b === void 0 ? void 0 : _b.locale) || 'en-US';
46
+ // Prefer a match by installation_id + account_id
47
+ if (installation_id) {
48
+ const byInstall = yield this.repositoryRead.findOne({ where: { account_id, installation_id } });
49
+ if (byInstall) {
50
+ const dto = { account, fcm_token: new_fcm_token, platform, locale };
51
+ return this._update(account, ['fcm_token', 'platform', 'locale'], dto, undefined, byInstall);
52
+ }
53
+ }
54
+ // Fallback: match by previous_fcm_token + account_id
55
+ if (previous_fcm_token) {
56
+ const byToken = yield this.repositoryRead.findOne({ where: { account_id, fcm_token: previous_fcm_token } });
57
+ if (byToken) {
58
+ const dto = { account, fcm_token: new_fcm_token, platform, locale };
59
+ if (installation_id)
60
+ dto.installation_id = installation_id;
61
+ return this._update(account, ['fcm_token', 'installation_id', 'platform', 'locale'], dto, undefined, byToken);
62
+ }
42
63
  }
43
- const dto = { account, fcm_token: new_fcm_token };
44
- return this._update(account, ['fcm_token'], dto, undefined, existingDevice);
64
+ throw new Error('FCM Device not found for update.');
45
65
  });
46
66
  }
47
- delete(account_id, fcm_token) {
67
+ delete(account_id, params) {
48
68
  return __awaiter(this, void 0, void 0, function* () {
49
69
  const account = yield this.accountService.get(account_id);
50
70
  if (!account) {
51
- throw new Error("Account not found.");
71
+ throw new Error('Account not found.');
72
+ }
73
+ const { fcm_token, installation_id } = params;
74
+ if (installation_id) {
75
+ const byInstall = yield this.repositoryRead.findOne({ where: { account_id, installation_id } });
76
+ if (byInstall) {
77
+ return this._delete(account, { installation_id });
78
+ }
52
79
  }
53
- return this._delete(account, { fcm_token });
80
+ if (fcm_token) {
81
+ const byToken = yield this.repositoryRead.findOne({ where: { account_id, fcm_token } });
82
+ if (byToken) {
83
+ return this._delete(account, { fcm_token });
84
+ }
85
+ }
86
+ throw new Error('FCM Device not found for deletion.');
54
87
  });
55
88
  }
56
89
  getFCMTokensByChannelIdText(channel_id_text) {
@@ -66,5 +99,31 @@ class AccountFCMDeviceService extends baseManyService_1.BaseManyService {
66
99
  return fcmTokens;
67
100
  });
68
101
  }
102
+ getAllForAccount(account_id) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ return this.repositoryRead.find({ where: { account_id } });
105
+ });
106
+ }
107
+ getAllForAccountIds(account_ids) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ if (account_ids.length === 0)
110
+ return [];
111
+ return this.repositoryRead.find({ where: { account_id: (0, typeorm_1.In)(account_ids) } });
112
+ });
113
+ }
114
+ updateLocaleForAccount(account_id, params) {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ const account = yield this.accountService.get(account_id);
117
+ if (!account) {
118
+ throw new Error('Account not found.');
119
+ }
120
+ const { locale } = params;
121
+ yield this.repositoryRead.createQueryBuilder()
122
+ .update(accountFCMDevice_1.AccountFCMDevice)
123
+ .set({ locale })
124
+ .where('account_id = :account_id', { account_id })
125
+ .execute();
126
+ });
127
+ }
69
128
  }
70
129
  exports.AccountFCMDeviceService = AccountFCMDeviceService;
@@ -1 +1 @@
1
- {"version":3,"file":"accountNotificationChannel.d.ts","sourceRoot":"","sources":["../../../src/services/account/accountNotificationChannel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,0BAA0B,EAAE,MAAM,kDAAkD,CAAC;AAC9F,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAIrE,qBAAa,iCAAkC,SAAQ,eAAe,CAAC,0BAA0B,EAAE,SAAS,CAAC;IAC3G,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,cAAc,CAAiB;gBAE3B,0BAA0B,CAAC,EAAE,aAAa;IAMhD,8BAA8B,CAAC,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,CAAC,0BAA0B,CAAC,GAAG,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC;IAc5K,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,eAAe,CAAC,0BAA0B,CAAC,GAAG,OAAO,CAAC,0BAA0B,EAAE,CAAC;IASlI,qBAAqB,CAAC,eAAe,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,eAAe,CAAC,0BAA0B,CAAC,GAAG,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAS3I,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAexF,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAazE"}
1
+ {"version":3,"file":"accountNotificationChannel.d.ts","sourceRoot":"","sources":["../../../src/services/account/accountNotificationChannel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,0BAA0B,EAAE,MAAM,kDAAkD,CAAC;AAE9F,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAKrE,qBAAa,iCAAkC,SAAQ,eAAe,CAAC,0BAA0B,EAAE,SAAS,CAAC;IAC3G,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,cAAc,CAAiB;gBAE3B,0BAA0B,CAAC,EAAE,aAAa;IAMhD,8BAA8B,CAAC,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,CAAC,0BAA0B,CAAC,GAAG,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC;IAc5K,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,eAAe,CAAC,0BAA0B,CAAC,GAAG,OAAO,CAAC,0BAA0B,EAAE,CAAC;IASlI,qBAAqB,CAAC,eAAe,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,eAAe,CAAC,0BAA0B,CAAC,GAAG,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAS3I,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAiCxF,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAazE"}
@@ -11,9 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AccountNotificationChannelService = void 0;
13
13
  const accountNotificationChannel_1 = require("@orm/entities/account/accountNotificationChannel");
14
+ const accountNotificationChannelType_1 = require("@orm/entities/account/accountNotificationChannelType");
14
15
  const baseManyService_1 = require("@orm/services/base/baseManyService");
15
16
  const account_1 = require("@orm/services/account/account");
16
17
  const channel_1 = require("@orm/services/channel/channel");
18
+ const db_1 = require("@orm/db");
17
19
  class AccountNotificationChannelService extends baseManyService_1.BaseManyService {
18
20
  constructor(transactionalEntityManager) {
19
21
  super(accountNotificationChannel_1.AccountNotificationChannel, 'account', transactionalEntityManager);
@@ -53,6 +55,7 @@ class AccountNotificationChannelService extends baseManyService_1.BaseManyServic
53
55
  }
54
56
  create(account_id, channel_id_text) {
55
57
  return __awaiter(this, void 0, void 0, function* () {
58
+ var _a, _b;
56
59
  const account = yield this.accountService.get(account_id);
57
60
  if (!account) {
58
61
  throw new Error("Account not found.");
@@ -62,7 +65,23 @@ class AccountNotificationChannelService extends baseManyService_1.BaseManyServic
62
65
  throw new Error("Channel not found.");
63
66
  }
64
67
  const dto = { account_id, channel_id: channel.id };
65
- return this._update(account, ['account_id', 'channel_id'], dto);
68
+ const accountNotificationChannel = yield this._update(account, ['account_id', 'channel_id'], dto);
69
+ const notificationTypes = (_b = (_a = account.account_settings) === null || _a === void 0 ? void 0 : _a.account_settings_notification) === null || _b === void 0 ? void 0 : _b.account_settings_notification_types;
70
+ if (notificationTypes && notificationTypes.length > 0) {
71
+ const channelTypeRepo = db_1.AppDataSourceReadWrite.getRepository(accountNotificationChannelType_1.AccountNotificationChannelType);
72
+ const channelTypes = notificationTypes.map(settingsType => {
73
+ const channelType = new accountNotificationChannelType_1.AccountNotificationChannelType();
74
+ channelType.account_notification_channel = accountNotificationChannel;
75
+ channelType.type = settingsType.type;
76
+ return channelType;
77
+ });
78
+ yield channelTypeRepo.save(channelTypes);
79
+ }
80
+ else {
81
+ console.warn(`AccountNotificationChannelService.create: No notification types found for account ${account_id}. ` +
82
+ `AccountNotificationChannelTypes will not be created automatically.`);
83
+ }
84
+ return accountNotificationChannel;
66
85
  });
67
86
  }
68
87
  delete(account_id, channel_id_text) {
@@ -0,0 +1,13 @@
1
+ import { EntityManager, FindManyOptions } from 'typeorm';
2
+ import { AccountNotificationTypeEnum } from 'podverse-helpers';
3
+ import { AccountNotificationChannelType } from '@orm/entities/account/accountNotificationChannelType';
4
+ export declare class AccountNotificationChannelTypeService {
5
+ private accountNotificationChannelService;
6
+ private transactionalEntityManager?;
7
+ constructor(transactionalEntityManager?: EntityManager);
8
+ private get repository();
9
+ getAllByAccountNotificationChannelId(account_notification_channel_id: number, config?: FindManyOptions<AccountNotificationChannelType>): Promise<AccountNotificationChannelType[]>;
10
+ create(account_id: number, channel_id_text: string, type: AccountNotificationTypeEnum): Promise<AccountNotificationChannelType>;
11
+ delete(account_id: number, channel_id_text: string, type: AccountNotificationTypeEnum): Promise<void>;
12
+ }
13
+ //# sourceMappingURL=accountNotificationChannelType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountNotificationChannelType.d.ts","sourceRoot":"","sources":["../../../src/services/account/accountNotificationChannelType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAE,MAAM,sDAAsD,CAAC;AAItG,qBAAa,qCAAqC;IAChD,OAAO,CAAC,iCAAiC,CAAoC;IAC7E,OAAO,CAAC,0BAA0B,CAAC,CAAgB;gBAEvC,0BAA0B,CAAC,EAAE,aAAa;IAKtD,OAAO,KAAK,UAAU,GAIrB;IAEK,oCAAoC,CACxC,+BAA+B,EAAE,MAAM,EACvC,MAAM,CAAC,EAAE,eAAe,CAAC,8BAA8B,CAAC,GACvD,OAAO,CAAC,8BAA8B,EAAE,CAAC;IAOtC,MAAM,CACV,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,MAAM,EACvB,IAAI,EAAE,2BAA2B,GAChC,OAAO,CAAC,8BAA8B,CAAC;IA0BpC,MAAM,CACV,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,MAAM,EACvB,IAAI,EAAE,2BAA2B,GAChC,OAAO,CAAC,IAAI,CAAC;CAajB"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AccountNotificationChannelTypeService = void 0;
13
+ const accountNotificationChannelType_1 = require("@orm/entities/account/accountNotificationChannelType");
14
+ const accountNotificationChannel_1 = require("@orm/services/account/accountNotificationChannel");
15
+ const db_1 = require("@orm/db");
16
+ class AccountNotificationChannelTypeService {
17
+ constructor(transactionalEntityManager) {
18
+ this.transactionalEntityManager = transactionalEntityManager;
19
+ this.accountNotificationChannelService = new accountNotificationChannel_1.AccountNotificationChannelService(transactionalEntityManager);
20
+ }
21
+ get repository() {
22
+ return this.transactionalEntityManager
23
+ ? this.transactionalEntityManager.getRepository(accountNotificationChannelType_1.AccountNotificationChannelType)
24
+ : db_1.AppDataSourceReadWrite.getRepository(accountNotificationChannelType_1.AccountNotificationChannelType);
25
+ }
26
+ getAllByAccountNotificationChannelId(account_notification_channel_id, config) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ return this.repository.find(Object.assign({ where: { account_notification_channel: { id: account_notification_channel_id } } }, config));
29
+ });
30
+ }
31
+ create(account_id, channel_id_text, type) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const accountNotificationChannel = yield this.accountNotificationChannelService
34
+ .getByAccountIdAndChannelIdText(account_id, channel_id_text);
35
+ if (!accountNotificationChannel) {
36
+ throw new Error("Account notification channel not found.");
37
+ }
38
+ const existing = yield this.repository.findOne({
39
+ where: {
40
+ account_notification_channel: { id: accountNotificationChannel.id },
41
+ type
42
+ }
43
+ });
44
+ if (existing) {
45
+ return existing;
46
+ }
47
+ const channelType = new accountNotificationChannelType_1.AccountNotificationChannelType();
48
+ channelType.account_notification_channel = accountNotificationChannel;
49
+ channelType.type = type;
50
+ return this.repository.save(channelType);
51
+ });
52
+ }
53
+ delete(account_id, channel_id_text, type) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const accountNotificationChannel = yield this.accountNotificationChannelService
56
+ .getByAccountIdAndChannelIdText(account_id, channel_id_text);
57
+ if (!accountNotificationChannel) {
58
+ throw new Error("Account notification channel not found.");
59
+ }
60
+ yield this.repository.delete({
61
+ account_notification_channel: { id: accountNotificationChannel.id },
62
+ type
63
+ });
64
+ });
65
+ }
66
+ }
67
+ exports.AccountNotificationChannelTypeService = AccountNotificationChannelTypeService;
@@ -0,0 +1,20 @@
1
+ import { Repository } from 'typeorm';
2
+ import { AccountSettingsLocale } from '@orm/entities/account/accountSettings/accountSettingsLocale';
3
+ type CreateDto = {
4
+ account_id: number;
5
+ locale: string;
6
+ };
7
+ type UpdateDto = {
8
+ account_id: number;
9
+ locale: string;
10
+ };
11
+ export declare class AccountSettingsLocaleService {
12
+ protected repositoryReadWrite: Repository<AccountSettingsLocale>;
13
+ protected repositoryRead: Repository<AccountSettingsLocale>;
14
+ constructor();
15
+ create(dto: CreateDto): Promise<AccountSettingsLocale>;
16
+ update(dto: UpdateDto): Promise<AccountSettingsLocale>;
17
+ private updateAccountFCMDeviceLocales;
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=accountSettingsLocale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountSettingsLocale.d.ts","sourceRoot":"","sources":["../../../../src/services/account/accountSettings/accountSettingsLocale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,qBAAqB,EAAE,MAAM,6DAA6D,CAAC;AAIpG,KAAK,SAAS,GAAG;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,SAAS,GAAG;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,qBAAa,4BAA4B;IACvC,SAAS,CAAC,mBAAmB,EAAE,UAAU,CAAC,qBAAqB,CAAC,CAAC;IACjE,SAAS,CAAC,cAAc,EAAE,UAAU,CAAC,qBAAqB,CAAC,CAAC;;IAOtD,MAAM,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAsBtD,MAAM,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAyB9C,6BAA6B;CAW5C"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AccountSettingsLocaleService = void 0;
13
+ const db_1 = require("@orm/db");
14
+ const accountSettingsLocale_1 = require("@orm/entities/account/accountSettings/accountSettingsLocale");
15
+ const accountSettings_1 = require("@orm/entities/account/accountSettings/accountSettings");
16
+ const accountFCMDevice_1 = require("@orm/entities/account/accountFCMDevice");
17
+ class AccountSettingsLocaleService {
18
+ constructor() {
19
+ this.repositoryReadWrite = db_1.AppDataSourceReadWrite.getRepository(accountSettingsLocale_1.AccountSettingsLocale);
20
+ this.repositoryRead = db_1.AppDataSourceRead.getRepository(accountSettingsLocale_1.AccountSettingsLocale);
21
+ }
22
+ create(dto) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const accountSettingsRepo = db_1.AppDataSourceRead.getRepository(accountSettings_1.AccountSettings);
25
+ const accountSettings = yield accountSettingsRepo.findOne({
26
+ where: { account_id: dto.account_id }
27
+ });
28
+ if (!accountSettings) {
29
+ throw new Error('AccountSettings not found for account');
30
+ }
31
+ const obj = this.repositoryReadWrite.create({
32
+ account_settings_id: accountSettings.id,
33
+ locale: dto.locale
34
+ });
35
+ const saved = yield this.repositoryReadWrite.save(obj);
36
+ yield this.updateAccountFCMDeviceLocales(dto.account_id, dto.locale);
37
+ return saved;
38
+ });
39
+ }
40
+ update(dto) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const accountSettingsRepo = db_1.AppDataSourceRead.getRepository(accountSettings_1.AccountSettings);
43
+ const accountSettings = yield accountSettingsRepo.findOne({
44
+ where: { account_id: dto.account_id },
45
+ relations: ['account_settings_locale']
46
+ });
47
+ if (!accountSettings) {
48
+ throw new Error('AccountSettings not found for account');
49
+ }
50
+ if (!accountSettings.account_settings_locale) {
51
+ return this.create(dto);
52
+ }
53
+ const localeSettings = accountSettings.account_settings_locale;
54
+ localeSettings.locale = dto.locale;
55
+ const saved = yield this.repositoryReadWrite.save(localeSettings);
56
+ yield this.updateAccountFCMDeviceLocales(dto.account_id, dto.locale);
57
+ return saved;
58
+ });
59
+ }
60
+ updateAccountFCMDeviceLocales(account_id, locale) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const fcmDeviceRepo = db_1.AppDataSourceReadWrite.getRepository(accountFCMDevice_1.AccountFCMDevice);
63
+ const devices = yield fcmDeviceRepo.find({ where: { account_id } });
64
+ if (devices.length > 0) {
65
+ for (const device of devices) {
66
+ device.locale = locale;
67
+ }
68
+ yield fcmDeviceRepo.save(devices);
69
+ }
70
+ });
71
+ }
72
+ }
73
+ exports.AccountSettingsLocaleService = AccountSettingsLocaleService;
@@ -0,0 +1,16 @@
1
+ import { AccountNotificationTypeValues } from 'podverse-helpers';
2
+ import { Repository } from 'typeorm';
3
+ import { AccountSettingsNotificationType } from '@orm/entities/account/accountSettings/accountSettingsNotificationType';
4
+ type CreateDto = {
5
+ account_id: number;
6
+ type: AccountNotificationTypeValues;
7
+ };
8
+ export declare class AccountSettingsNotificationTypeService {
9
+ protected repositoryReadWrite: Repository<AccountSettingsNotificationType>;
10
+ protected repositoryRead: Repository<AccountSettingsNotificationType>;
11
+ constructor();
12
+ create(dto: CreateDto): Promise<AccountSettingsNotificationType>;
13
+ delete(type: AccountNotificationTypeValues, account_id: number): Promise<void>;
14
+ }
15
+ export {};
16
+ //# sourceMappingURL=accountSettingsNotificationType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountSettingsNotificationType.d.ts","sourceRoot":"","sources":["../../../../src/services/account/accountSettings/accountSettingsNotificationType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,+BAA+B,EAAE,MAAM,uEAAuE,CAAC;AAGxH,KAAK,SAAS,GAAG;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,6BAA6B,CAAC;CACrC,CAAC;AAEF,qBAAa,sCAAsC;IACjD,SAAS,CAAC,mBAAmB,EAAE,UAAU,CAAC,+BAA+B,CAAC,CAAC;IAC3E,SAAS,CAAC,cAAc,EAAE,UAAU,CAAC,+BAA+B,CAAC,CAAC;;IAOhE,MAAM,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,+BAA+B,CAAC;IAiBhE,MAAM,CAAC,IAAI,EAAE,6BAA6B,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BrF"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AccountSettingsNotificationTypeService = void 0;
13
+ const db_1 = require("@orm/db");
14
+ const accountSettingsNotificationType_1 = require("@orm/entities/account/accountSettings/accountSettingsNotificationType");
15
+ const accountSettings_1 = require("@orm/entities/account/accountSettings/accountSettings");
16
+ class AccountSettingsNotificationTypeService {
17
+ constructor() {
18
+ this.repositoryReadWrite = db_1.AppDataSourceReadWrite.getRepository(accountSettingsNotificationType_1.AccountSettingsNotificationType);
19
+ this.repositoryRead = db_1.AppDataSourceRead.getRepository(accountSettingsNotificationType_1.AccountSettingsNotificationType);
20
+ }
21
+ create(dto) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const accountSettingsRepo = db_1.AppDataSourceRead.getRepository(accountSettings_1.AccountSettings);
24
+ const accountSettings = yield accountSettingsRepo.findOne({ where: { account_id: dto.account_id }, relations: ['account_settings_notification'] });
25
+ if (!accountSettings || !accountSettings.account_settings_notification) {
26
+ throw new Error('AccountSettingsNotification not found for account');
27
+ }
28
+ const parent = accountSettings.account_settings_notification;
29
+ const obj = this.repositoryReadWrite.create({
30
+ type: dto.type,
31
+ account_settings_notification: parent,
32
+ });
33
+ return this.repositoryReadWrite.save(obj);
34
+ });
35
+ }
36
+ delete(type, account_id) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const accountSettingsRepo = db_1.AppDataSourceRead.getRepository(accountSettings_1.AccountSettings);
39
+ const accountSettings = yield accountSettingsRepo.findOne({ where: { account_id }, relations: ['account_settings_notification'] });
40
+ if (!accountSettings || !accountSettings.account_settings_notification) {
41
+ throw new Error('AccountSettingsNotification not found for account');
42
+ }
43
+ const parentId = accountSettings.account_settings_notification.id;
44
+ const item = yield this.repositoryRead.findOne({
45
+ where: {
46
+ type,
47
+ account_settings_notification: {
48
+ id: parentId
49
+ }
50
+ },
51
+ relations: ['account_settings_notification']
52
+ });
53
+ if (!item) {
54
+ return;
55
+ }
56
+ yield this.repositoryReadWrite.remove(item);
57
+ return;
58
+ });
59
+ }
60
+ }
61
+ exports.AccountSettingsNotificationTypeService = AccountSettingsNotificationTypeService;