serene-core-server 0.1.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.
- package/dist/apollo/resolvers/mutations/mailing-lists.d.ts +11 -0
- package/dist/apollo/resolvers/mutations/mailing-lists.js +30 -0
- package/dist/apollo/resolvers/mutations/user-preferences.d.ts +13 -0
- package/dist/apollo/resolvers/mutations/user-preferences.js +31 -0
- package/dist/apollo/resolvers/mutations/users.d.ts +28 -0
- package/dist/apollo/resolvers/mutations/users.js +44 -0
- package/dist/apollo/resolvers/queries/access.d.ts +11 -0
- package/dist/apollo/resolvers/queries/access.js +25 -0
- package/dist/apollo/resolvers/queries/profile.d.ts +11 -0
- package/dist/apollo/resolvers/queries/profile.js +25 -0
- package/dist/apollo/resolvers/queries/quotas.d.ts +21 -0
- package/dist/apollo/resolvers/queries/quotas.js +25 -0
- package/dist/apollo/resolvers/queries/tech.d.ts +5 -0
- package/dist/apollo/resolvers/queries/tech.js +35 -0
- package/dist/apollo/resolvers/queries/user-preferences.d.ts +5 -0
- package/dist/apollo/resolvers/queries/user-preferences.js +33 -0
- package/dist/apollo/resolvers/queries/users.d.ts +15 -0
- package/dist/apollo/resolvers/queries/users.js +28 -0
- package/dist/apollo/resolvers/resolvers.d.ts +20 -0
- package/dist/apollo/resolvers/resolvers.js +38 -0
- package/dist/apollo/typedefs/typedefs.d.ts +1 -0
- package/dist/apollo/typedefs/typedefs.js +142 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +68 -0
- package/dist/models/chat/chat-message-created-model.d.ts +17 -0
- package/dist/models/chat/chat-message-created-model.js +113 -0
- package/dist/models/chat/chat-message-model.d.ts +44 -0
- package/dist/models/chat/chat-message-model.js +523 -0
- package/dist/models/chat/chat-participant-model.d.ts +39 -0
- package/dist/models/chat/chat-participant-model.js +211 -0
- package/dist/models/chat/chat-session-model.d.ts +92 -0
- package/dist/models/chat/chat-session-model.js +301 -0
- package/dist/models/chat/chat-settings-model.d.ts +87 -0
- package/dist/models/chat/chat-settings-model.js +261 -0
- package/dist/models/feature-flags/feature-flag-model.d.ts +40 -0
- package/dist/models/feature-flags/feature-flag-model.js +164 -0
- package/dist/models/instances/instance-model.d.ts +93 -0
- package/dist/models/instances/instance-model.js +432 -0
- package/dist/models/instances/instance-setting-model.d.ts +39 -0
- package/dist/models/instances/instance-setting-model.js +193 -0
- package/dist/models/mailing-lists/mailing-list-model.d.ts +34 -0
- package/dist/models/mailing-lists/mailing-list-model.js +154 -0
- package/dist/models/mailing-lists/mailing-list-subscriber-model.d.ts +36 -0
- package/dist/models/mailing-lists/mailing-list-subscriber-model.js +152 -0
- package/dist/models/quotas/resource-quota-total-model.d.ts +46 -0
- package/dist/models/quotas/resource-quota-total-model.js +200 -0
- package/dist/models/quotas/resource-quota-usage-model.d.ts +51 -0
- package/dist/models/quotas/resource-quota-usage-model.js +181 -0
- package/dist/models/tech/rate-limited-api-event-model.d.ts +25 -0
- package/dist/models/tech/rate-limited-api-event-model.js +161 -0
- package/dist/models/tech/rate-limited-api-model.d.ts +21 -0
- package/dist/models/tech/rate-limited-api-model.js +141 -0
- package/dist/models/tech/tech-model.d.ts +44 -0
- package/dist/models/tech/tech-model.js +268 -0
- package/dist/models/tech/tech-provider-api-key-model.d.ts +43 -0
- package/dist/models/tech/tech-provider-api-key-model.js +224 -0
- package/dist/models/tech/tech-provider-model.d.ts +28 -0
- package/dist/models/tech/tech-provider-model.js +197 -0
- package/dist/models/users/external-user-integration-model.d.ts +36 -0
- package/dist/models/users/external-user-integration-model.js +196 -0
- package/dist/models/users/user-error-model.d.ts +54 -0
- package/dist/models/users/user-error-model.js +173 -0
- package/dist/models/users/user-error-summary-model.d.ts +45 -0
- package/dist/models/users/user-error-summary-model.js +172 -0
- package/dist/models/users/user-group-member-model.d.ts +41 -0
- package/dist/models/users/user-group-member-model.js +193 -0
- package/dist/models/users/user-group-model.d.ts +27 -0
- package/dist/models/users/user-group-model.js +146 -0
- package/dist/models/users/user-model.d.ts +46 -0
- package/dist/models/users/user-model.js +153 -0
- package/dist/models/users/user-preference-model.d.ts +60 -0
- package/dist/models/users/user-preference-model.js +228 -0
- package/dist/models/users/user-profile-model.d.ts +58 -0
- package/dist/models/users/user-profile-model.js +173 -0
- package/dist/prisma.config.d.ts +3 -0
- package/dist/prisma.config.js +13 -0
- package/dist/services/access/access-service.d.ts +12 -0
- package/dist/services/access/access-service.js +44 -0
- package/dist/services/access/encrypt-service.d.ts +13 -0
- package/dist/services/access/encrypt-service.js +84 -0
- package/dist/services/api-usage/api-usage-base-service.d.ts +15 -0
- package/dist/services/api-usage/api-usage-base-service.js +75 -0
- package/dist/services/console/service.d.ts +7 -0
- package/dist/services/console/service.js +70 -0
- package/dist/services/db/pg/pg-estimate-size-service.d.ts +16 -0
- package/dist/services/db/pg/pg-estimate-size-service.js +90 -0
- package/dist/services/files/types.d.ts +6 -0
- package/dist/services/files/types.js +2 -0
- package/dist/services/files/walk-dir-service.d.ts +8 -0
- package/dist/services/files/walk-dir-service.js +94 -0
- package/dist/services/locale/countries.d.ts +6 -0
- package/dist/services/locale/countries.js +484 -0
- package/dist/services/mailing-lists/mailing-list-subscriber-service.d.ts +14 -0
- package/dist/services/mailing-lists/mailing-list-subscriber-service.js +45 -0
- package/dist/services/process/sleep.d.ts +2 -0
- package/dist/services/process/sleep.js +10 -0
- package/dist/services/quotas/mutate-service.d.ts +5 -0
- package/dist/services/quotas/mutate-service.js +54 -0
- package/dist/services/quotas/query-service.d.ts +27 -0
- package/dist/services/quotas/query-service.js +137 -0
- package/dist/services/quotas/utils-service.d.ts +4 -0
- package/dist/services/quotas/utils-service.js +28 -0
- package/dist/services/tech/tech-provider-mutate-service.d.ts +7 -0
- package/dist/services/tech/tech-provider-mutate-service.js +142 -0
- package/dist/services/tech/tech-query-service.d.ts +9 -0
- package/dist/services/tech/tech-query-service.js +77 -0
- package/dist/services/user-preference/service.d.ts +10 -0
- package/dist/services/user-preference/service.js +70 -0
- package/dist/services/users/external-user-integration-service.d.ts +9 -0
- package/dist/services/users/external-user-integration-service.js +42 -0
- package/dist/services/users/profile-service.d.ts +40 -0
- package/dist/services/users/profile-service.js +408 -0
- package/dist/services/users/service.d.ts +64 -0
- package/dist/services/users/service.js +187 -0
- package/dist/services/users/user-error-service.d.ts +4 -0
- package/dist/services/users/user-error-service.js +42 -0
- package/dist/services/users/users-group-service.d.ts +16 -0
- package/dist/services/users/users-group-service.js +68 -0
- package/dist/services/utils/string-utils-service.d.ts +5 -0
- package/dist/services/utils/string-utils-service.js +41 -0
- package/dist/src/apollo/resolvers/mutations/mailing-lists.d.ts +11 -0
- package/dist/src/apollo/resolvers/mutations/mailing-lists.js +19 -0
- package/dist/src/apollo/resolvers/mutations/user-preferences.d.ts +13 -0
- package/dist/src/apollo/resolvers/mutations/user-preferences.js +20 -0
- package/dist/src/apollo/resolvers/mutations/users.d.ts +28 -0
- package/dist/src/apollo/resolvers/mutations/users.js +33 -0
- package/dist/src/apollo/resolvers/queries/access.d.ts +11 -0
- package/dist/src/apollo/resolvers/queries/access.js +14 -0
- package/dist/src/apollo/resolvers/queries/profile.d.ts +11 -0
- package/dist/src/apollo/resolvers/queries/profile.js +14 -0
- package/dist/src/apollo/resolvers/queries/quotas.d.ts +21 -0
- package/dist/src/apollo/resolvers/queries/quotas.js +14 -0
- package/dist/src/apollo/resolvers/queries/tech.d.ts +5 -0
- package/dist/src/apollo/resolvers/queries/tech.js +24 -0
- package/dist/src/apollo/resolvers/queries/user-preferences.d.ts +5 -0
- package/dist/src/apollo/resolvers/queries/user-preferences.js +22 -0
- package/dist/src/apollo/resolvers/queries/users.d.ts +15 -0
- package/dist/src/apollo/resolvers/queries/users.js +17 -0
- package/dist/src/apollo/typedefs/typedefs.d.ts +1 -0
- package/dist/src/apollo/typedefs/typedefs.js +139 -0
- package/dist/src/db.d.ts +3 -0
- package/dist/src/db.js +11 -0
- package/dist/src/index.d.ts +52 -0
- package/dist/src/index.js +52 -0
- package/dist/src/models/chat/chat-message-created-model.d.ts +17 -0
- package/dist/src/models/chat/chat-message-created-model.js +92 -0
- package/dist/src/models/chat/chat-message-model.d.ts +44 -0
- package/dist/src/models/chat/chat-message-model.js +484 -0
- package/dist/src/models/chat/chat-participant-model.d.ts +39 -0
- package/dist/src/models/chat/chat-participant-model.js +178 -0
- package/dist/src/models/chat/chat-session-model.d.ts +92 -0
- package/dist/src/models/chat/chat-session-model.js +266 -0
- package/dist/src/models/chat/chat-settings-model.d.ts +87 -0
- package/dist/src/models/chat/chat-settings-model.js +230 -0
- package/dist/src/models/feature-flags/feature-flag-model.d.ts +40 -0
- package/dist/src/models/feature-flags/feature-flag-model.js +137 -0
- package/dist/src/models/instances/instance-model.d.ts +100 -0
- package/dist/src/models/instances/instance-model.js +466 -0
- package/dist/src/models/instances/instance-setting-model.d.ts +39 -0
- package/dist/src/models/instances/instance-setting-model.js +164 -0
- package/dist/src/models/mailing-lists/mailing-list-model.d.ts +34 -0
- package/dist/src/models/mailing-lists/mailing-list-model.js +127 -0
- package/dist/src/models/mailing-lists/mailing-list-subscriber-model.d.ts +36 -0
- package/dist/src/models/mailing-lists/mailing-list-subscriber-model.js +127 -0
- package/dist/src/models/quotas/resource-quota-total-model.d.ts +46 -0
- package/dist/src/models/quotas/resource-quota-total-model.js +170 -0
- package/dist/src/models/quotas/resource-quota-usage-model.d.ts +51 -0
- package/dist/src/models/quotas/resource-quota-usage-model.js +151 -0
- package/dist/src/models/tech/rate-limited-api-event-model.d.ts +25 -0
- package/dist/src/models/tech/rate-limited-api-event-model.js +134 -0
- package/dist/src/models/tech/rate-limited-api-model.d.ts +21 -0
- package/dist/src/models/tech/rate-limited-api-model.js +116 -0
- package/dist/src/models/tech/tech-model.d.ts +44 -0
- package/dist/src/models/tech/tech-model.js +239 -0
- package/dist/src/models/tech/tech-provider-api-key-model.d.ts +43 -0
- package/dist/src/models/tech/tech-provider-api-key-model.js +195 -0
- package/dist/src/models/tech/tech-provider-model.d.ts +28 -0
- package/dist/src/models/tech/tech-provider-model.js +170 -0
- package/dist/src/models/users/external-user-integration-model.d.ts +36 -0
- package/dist/src/models/users/external-user-integration-model.js +167 -0
- package/dist/src/models/users/user-error-model.d.ts +54 -0
- package/dist/src/models/users/user-error-model.js +146 -0
- package/dist/src/models/users/user-error-summary-model.d.ts +45 -0
- package/dist/src/models/users/user-error-summary-model.js +145 -0
- package/dist/src/models/users/user-group-member-model.d.ts +41 -0
- package/dist/src/models/users/user-group-member-model.js +164 -0
- package/dist/src/models/users/user-group-model.d.ts +27 -0
- package/dist/src/models/users/user-group-model.js +121 -0
- package/dist/src/models/users/user-model.d.ts +46 -0
- package/dist/src/models/users/user-model.js +126 -0
- package/dist/src/models/users/user-preference-model.d.ts +60 -0
- package/dist/src/models/users/user-preference-model.js +197 -0
- package/dist/src/models/users/user-profile-model.d.ts +58 -0
- package/dist/src/models/users/user-profile-model.js +146 -0
- package/dist/src/services/access/access-service.d.ts +12 -0
- package/dist/src/services/access/access-service.js +27 -0
- package/dist/src/services/access/encrypt-service.d.ts +13 -0
- package/dist/src/services/access/encrypt-service.js +79 -0
- package/dist/src/services/api-usage/api-usage-base-service.d.ts +15 -0
- package/dist/src/services/api-usage/api-usage-base-service.js +58 -0
- package/dist/src/services/console/service.d.ts +7 -0
- package/dist/src/services/console/service.js +18 -0
- package/dist/src/services/db/pg/pg-estimate-size-service.d.ts +16 -0
- package/dist/src/services/db/pg/pg-estimate-size-service.js +83 -0
- package/dist/src/services/files/types.d.ts +6 -0
- package/dist/src/services/files/types.js +1 -0
- package/dist/src/services/files/walk-dir-service.d.ts +8 -0
- package/dist/src/services/files/walk-dir-service.js +77 -0
- package/dist/src/services/locale/countries.d.ts +6 -0
- package/dist/src/services/locale/countries.js +481 -0
- package/dist/src/services/mailing-lists/mailing-list-subscriber-service.d.ts +14 -0
- package/dist/src/services/mailing-lists/mailing-list-subscriber-service.js +28 -0
- package/dist/src/services/process/sleep.d.ts +2 -0
- package/dist/src/services/process/sleep.js +6 -0
- package/dist/src/services/quotas/mutate-service.d.ts +5 -0
- package/dist/src/services/quotas/mutate-service.js +37 -0
- package/dist/src/services/quotas/query-service.d.ts +27 -0
- package/dist/src/services/quotas/query-service.js +116 -0
- package/dist/src/services/quotas/utils-service.d.ts +4 -0
- package/dist/src/services/quotas/utils-service.js +22 -0
- package/dist/src/services/tech/tech-provider-mutate-service.d.ts +7 -0
- package/dist/src/services/tech/tech-provider-mutate-service.js +85 -0
- package/dist/src/services/tech/tech-query-service.d.ts +9 -0
- package/dist/src/services/tech/tech-query-service.js +58 -0
- package/dist/src/services/user-preference/service.d.ts +10 -0
- package/dist/src/services/user-preference/service.js +49 -0
- package/dist/src/services/users/external-user-integration-service.d.ts +9 -0
- package/dist/src/services/users/external-user-integration-service.js +25 -0
- package/dist/src/services/users/profile-service.d.ts +40 -0
- package/dist/src/services/users/profile-service.js +385 -0
- package/dist/src/services/users/service.d.ts +64 -0
- package/dist/src/services/users/service.js +152 -0
- package/dist/src/services/users/user-error-service.d.ts +4 -0
- package/dist/src/services/users/user-error-service.js +27 -0
- package/dist/src/services/users/users-group-service.d.ts +16 -0
- package/dist/src/services/users/users-group-service.js +51 -0
- package/dist/src/services/utils/field-naming-service.d.ts +20 -0
- package/dist/src/services/utils/field-naming-service.js +59 -0
- package/dist/src/services/utils/string-utils-service.d.ts +5 -0
- package/dist/src/services/utils/string-utils-service.js +37 -0
- package/dist/src/types/errors.d.ts +9 -0
- package/dist/src/types/errors.js +15 -0
- package/dist/src/types/user-types.d.ts +11 -0
- package/dist/src/types/user-types.js +14 -0
- package/dist/types/errors.d.ts +9 -0
- package/dist/types/errors.js +20 -0
- package/dist/types/user-types.d.ts +11 -0
- package/dist/types/user-types.js +19 -0
- package/package.json +21 -0
- package/prisma/schema.prisma +572 -0
- package/prisma.config.ts +14 -0
- package/src/apollo/README.md +4 -0
- package/src/apollo/resolvers/mutations/mailing-lists.ts +30 -0
- package/src/apollo/resolvers/mutations/user-preferences.ts +33 -0
- package/src/apollo/resolvers/mutations/users.ts +61 -0
- package/src/apollo/resolvers/queries/access.ts +23 -0
- package/src/apollo/resolvers/queries/profile.ts +24 -0
- package/src/apollo/resolvers/queries/quotas.ts +25 -0
- package/src/apollo/resolvers/queries/tech.ts +42 -0
- package/src/apollo/resolvers/queries/user-preferences.ts +34 -0
- package/src/apollo/resolvers/queries/users.ts +33 -0
- package/src/apollo/typedefs/typedefs.ts +139 -0
- package/src/db.ts +19 -0
- package/src/index.ts +52 -0
- package/src/models/chat/chat-message-created-model.ts +126 -0
- package/src/models/chat/chat-message-model.ts +678 -0
- package/src/models/chat/chat-participant-model.ts +248 -0
- package/src/models/chat/chat-session-model.ts +397 -0
- package/src/models/chat/chat-settings-model.ts +336 -0
- package/src/models/feature-flags/feature-flag-model.ts +198 -0
- package/src/models/instances/instance-model.ts +673 -0
- package/src/models/instances/instance-setting-model.ts +235 -0
- package/src/models/mailing-lists/mailing-list-model.ts +177 -0
- package/src/models/mailing-lists/mailing-list-subscriber-model.ts +194 -0
- package/src/models/quotas/resource-quota-total-model.ts +243 -0
- package/src/models/quotas/resource-quota-usage-model.ts +219 -0
- package/src/models/tech/rate-limited-api-event-model.ts +190 -0
- package/src/models/tech/rate-limited-api-model.ts +171 -0
- package/src/models/tech/tech-model.ts +360 -0
- package/src/models/tech/tech-provider-api-key-model.ts +289 -0
- package/src/models/tech/tech-provider-model.ts +247 -0
- package/src/models/users/external-user-integration-model.ts +236 -0
- package/src/models/users/user-error-model.ts +219 -0
- package/src/models/users/user-error-summary-model.ts +216 -0
- package/src/models/users/user-group-member-model.ts +233 -0
- package/src/models/users/user-group-model.ts +174 -0
- package/src/models/users/user-model.ts +172 -0
- package/src/models/users/user-preference-model.ts +285 -0
- package/src/models/users/user-profile-model.ts +207 -0
- package/src/services/access/access-service.ts +36 -0
- package/src/services/access/encrypt-service.ts +122 -0
- package/src/services/api-usage/api-usage-base-service.ts +95 -0
- package/src/services/console/service.ts +24 -0
- package/src/services/db/pg/pg-estimate-size-service.ts +119 -0
- package/src/services/files/types.ts +7 -0
- package/src/services/files/walk-dir-service.ts +135 -0
- package/src/services/locale/countries.ts +483 -0
- package/src/services/mailing-lists/mailing-list-subscriber-service.ts +54 -0
- package/src/services/process/sleep.ts +7 -0
- package/src/services/quotas/mutate-service.ts +66 -0
- package/src/services/quotas/query-service.ts +197 -0
- package/src/services/quotas/utils-service.ts +29 -0
- package/src/services/tech/tech-provider-mutate-service.ts +136 -0
- package/src/services/tech/tech-query-service.ts +93 -0
- package/src/services/user-preference/service.ts +110 -0
- package/src/services/users/external-user-integration-service.ts +51 -0
- package/src/services/users/profile-service.ts +513 -0
- package/src/services/users/service.ts +293 -0
- package/src/services/users/user-error-service.ts +74 -0
- package/src/services/users/users-group-service.ts +85 -0
- package/src/services/utils/field-naming-service.ts +78 -0
- package/src/services/utils/string-utils-service.ts +48 -0
- package/src/types/errors.ts +18 -0
- package/src/types/user-types.ts +19 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { CustomError } from '../../types/errors';
|
|
2
|
+
import { UserModel } from '../../models/users/user-model';
|
|
3
|
+
import { UserPreferenceModel } from '../../models/users/user-preference-model';
|
|
4
|
+
import { UserProfileModel } from '../../models/users/user-profile-model';
|
|
5
|
+
import { countries } from '../locale/countries';
|
|
6
|
+
import { UserPreferenceService } from '../user-preference/service';
|
|
7
|
+
export class ProfileService {
|
|
8
|
+
// Consts
|
|
9
|
+
clName = 'ProfileService';
|
|
10
|
+
// billingAddress = 'billing address'
|
|
11
|
+
personalDetails = 'personal details';
|
|
12
|
+
firstName = 'first name';
|
|
13
|
+
fullName = 'full name';
|
|
14
|
+
lastName = 'last name'; // For legacy compatibility with old Chargebee code in Serene Store
|
|
15
|
+
countryCode = 'country code';
|
|
16
|
+
/* billingNameAsMyName = 'billing name as my name'
|
|
17
|
+
billingCountryAsMyCountry = 'billing country as my country'
|
|
18
|
+
billingCountryCode = 'billing country code'
|
|
19
|
+
billingFirstName = 'billing first name'
|
|
20
|
+
billingLastName = 'billing last name'
|
|
21
|
+
billingAddressLine1 = 'billing address line 1'
|
|
22
|
+
billingAddressLine2 = 'billing address line 2'
|
|
23
|
+
billingCity = 'billing city'
|
|
24
|
+
billingState = 'billing state'
|
|
25
|
+
billingZip = 'billing zip' */
|
|
26
|
+
// Models
|
|
27
|
+
userModel = new UserModel();
|
|
28
|
+
userProfileModel = new UserProfileModel();
|
|
29
|
+
userPreferenceModel = new UserPreferenceModel();
|
|
30
|
+
// Code
|
|
31
|
+
userPreferenceService = new UserPreferenceService();
|
|
32
|
+
// Code
|
|
33
|
+
async getAll(prisma, userProfileId) {
|
|
34
|
+
// Get userPreference records
|
|
35
|
+
const userPreferences = await this.userPreferenceService.getUserPreferences(prisma, userProfileId, this.personalDetails, [this.firstName,
|
|
36
|
+
this.fullName,
|
|
37
|
+
this.countryCode]);
|
|
38
|
+
/* const userPreferences = await
|
|
39
|
+
this.userPreferenceService.getUserPreferences(
|
|
40
|
+
prisma,
|
|
41
|
+
userProfileId,
|
|
42
|
+
this.billingAddress,
|
|
43
|
+
[ this.firstName,
|
|
44
|
+
this.lastName,
|
|
45
|
+
this.countryCode,
|
|
46
|
+
this.billingNameAsMyName,
|
|
47
|
+
this.billingCountryAsMyCountry,
|
|
48
|
+
this.billingCountryCode,
|
|
49
|
+
this.billingFirstName,
|
|
50
|
+
this.billingLastName,
|
|
51
|
+
this.billingAddressLine1,
|
|
52
|
+
this.billingAddressLine2,
|
|
53
|
+
this.billingCity,
|
|
54
|
+
this.billingState,
|
|
55
|
+
this.billingZip ]) */
|
|
56
|
+
var userPreferenceMap = [];
|
|
57
|
+
for (const userPreference of userPreferences) {
|
|
58
|
+
userPreferenceMap[userPreference.key] = userPreference;
|
|
59
|
+
}
|
|
60
|
+
return userPreferenceMap;
|
|
61
|
+
}
|
|
62
|
+
getCountryCodeByName(country) {
|
|
63
|
+
for (const countryIter of countries) {
|
|
64
|
+
if (countryIter.name === country) {
|
|
65
|
+
return countryIter.code;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
async update(prisma, userProfileId, firstName, fullName, countryCode) {
|
|
71
|
+
// Get userPreference records
|
|
72
|
+
const userPreferenceService = new UserPreferenceService();
|
|
73
|
+
// Upsert all records
|
|
74
|
+
await this.userPreferenceModel.upsert(prisma, undefined, // id
|
|
75
|
+
userProfileId, this.personalDetails, this.firstName, firstName, null);
|
|
76
|
+
await this.userPreferenceModel.upsert(prisma, undefined, // id
|
|
77
|
+
userProfileId, this.personalDetails, this.fullName, fullName, null);
|
|
78
|
+
await this.userPreferenceModel.upsert(prisma, undefined, // id
|
|
79
|
+
userProfileId, this.personalDetails, this.countryCode, countryCode, null);
|
|
80
|
+
/* await this.userPreferenceModel.upsert(
|
|
81
|
+
prisma,
|
|
82
|
+
undefined, // id
|
|
83
|
+
userProfileId,
|
|
84
|
+
this.billingAddress,
|
|
85
|
+
this.billingNameAsMyName,
|
|
86
|
+
billingNameAsMyName.toString(),
|
|
87
|
+
null)
|
|
88
|
+
|
|
89
|
+
await this.userPreferenceModel.upsert(
|
|
90
|
+
prisma,
|
|
91
|
+
undefined, // id
|
|
92
|
+
userProfileId,
|
|
93
|
+
this.billingAddress,
|
|
94
|
+
this.billingCountryAsMyCountry,
|
|
95
|
+
billingCountryAsMyCountry.toString(),
|
|
96
|
+
null)
|
|
97
|
+
|
|
98
|
+
await this.userPreferenceModel.upsert(
|
|
99
|
+
prisma,
|
|
100
|
+
undefined, // id
|
|
101
|
+
userProfileId,
|
|
102
|
+
this.billingAddress,
|
|
103
|
+
this.billingCountryCode,
|
|
104
|
+
billingCountryCode,
|
|
105
|
+
null)
|
|
106
|
+
|
|
107
|
+
await this.userPreferenceModel.upsert(
|
|
108
|
+
prisma,
|
|
109
|
+
undefined, // id
|
|
110
|
+
userProfileId,
|
|
111
|
+
this.billingAddress,
|
|
112
|
+
this.billingFirstName,
|
|
113
|
+
billingFirstName,
|
|
114
|
+
null)
|
|
115
|
+
|
|
116
|
+
await this.userPreferenceModel.upsert(
|
|
117
|
+
prisma,
|
|
118
|
+
undefined, // id
|
|
119
|
+
userProfileId,
|
|
120
|
+
this.billingAddress,
|
|
121
|
+
this.billingLastName,
|
|
122
|
+
billingLastName,
|
|
123
|
+
null)
|
|
124
|
+
|
|
125
|
+
await this.userPreferenceModel.upsert(
|
|
126
|
+
prisma,
|
|
127
|
+
undefined, // id
|
|
128
|
+
userProfileId,
|
|
129
|
+
this.billingAddress,
|
|
130
|
+
this.billingAddressLine1,
|
|
131
|
+
billingAddressLine1,
|
|
132
|
+
null)
|
|
133
|
+
|
|
134
|
+
await this.userPreferenceModel.upsert(
|
|
135
|
+
prisma,
|
|
136
|
+
undefined, // id
|
|
137
|
+
userProfileId,
|
|
138
|
+
this.billingAddress,
|
|
139
|
+
this.billingAddressLine2,
|
|
140
|
+
billingAddressLine2,
|
|
141
|
+
null)
|
|
142
|
+
|
|
143
|
+
await this.userPreferenceModel.upsert(
|
|
144
|
+
prisma,
|
|
145
|
+
undefined, // id
|
|
146
|
+
userProfileId,
|
|
147
|
+
this.billingAddress,
|
|
148
|
+
this.billingCity,
|
|
149
|
+
billingCity,
|
|
150
|
+
null)
|
|
151
|
+
|
|
152
|
+
await this.userPreferenceModel.upsert(
|
|
153
|
+
prisma,
|
|
154
|
+
undefined, // id
|
|
155
|
+
userProfileId,
|
|
156
|
+
this.billingAddress,
|
|
157
|
+
this.billingState,
|
|
158
|
+
billingState,
|
|
159
|
+
null)
|
|
160
|
+
|
|
161
|
+
await this.userPreferenceModel.upsert(
|
|
162
|
+
prisma,
|
|
163
|
+
undefined, // id
|
|
164
|
+
userProfileId,
|
|
165
|
+
this.billingAddress,
|
|
166
|
+
this.billingZip,
|
|
167
|
+
billingZip,
|
|
168
|
+
null) */
|
|
169
|
+
}
|
|
170
|
+
async updateViaRestApi({ req, res }, prisma) {
|
|
171
|
+
// Debug
|
|
172
|
+
const fnName = `${this.clName}.updateViaRestApi()`;
|
|
173
|
+
// Get body
|
|
174
|
+
const body = req.body;
|
|
175
|
+
// Validate
|
|
176
|
+
if (!body.userProfileId) {
|
|
177
|
+
return res.status(200).json({
|
|
178
|
+
status: false,
|
|
179
|
+
msg: 'UserProfileId was not found'
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (!body.firstName) {
|
|
183
|
+
return res.status(200).json({
|
|
184
|
+
status: false,
|
|
185
|
+
msg: 'First name not specified'
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (!body.fullName) {
|
|
189
|
+
return res.status(200).json({
|
|
190
|
+
status: false,
|
|
191
|
+
msg: 'Full name not specified'
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (!body.country) {
|
|
195
|
+
return res.status(200).json({
|
|
196
|
+
status: false,
|
|
197
|
+
msg: 'Country not specified'
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/* if (!body.billingNameAsMyName) {
|
|
201
|
+
return res.status(200).json(
|
|
202
|
+
{
|
|
203
|
+
status: false,
|
|
204
|
+
msg: 'Billing name as my name not specified'
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (!body.billingCountryAsMyCountry) {
|
|
209
|
+
return res.status(200).json(
|
|
210
|
+
{
|
|
211
|
+
status: false,
|
|
212
|
+
msg: 'Billing country as my country not specified'
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (body.billingNameAsMyName === 'false' &&
|
|
217
|
+
!body.billingFirstName) {
|
|
218
|
+
return res.status(200).json(
|
|
219
|
+
{
|
|
220
|
+
status: false,
|
|
221
|
+
msg: 'Billing first name not specified'
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (body.billingNameAsMyName === 'false' &&
|
|
226
|
+
!body.billingLastName) {
|
|
227
|
+
return res.status(200).json(
|
|
228
|
+
{
|
|
229
|
+
status: false,
|
|
230
|
+
msg: 'Billing last name not specified'
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (body.billingCountryAsMyCountry === 'false' &&
|
|
235
|
+
!body.billingCountry) {
|
|
236
|
+
return res.status(200).json(
|
|
237
|
+
{
|
|
238
|
+
status: false,
|
|
239
|
+
msg: 'Billing country not specified'
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (!body.billingAddressLine1) {
|
|
244
|
+
return res.status(200).json(
|
|
245
|
+
{
|
|
246
|
+
status: false,
|
|
247
|
+
msg: 'Billing address line 1 not specified'
|
|
248
|
+
})
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (!body.billingCity) {
|
|
252
|
+
return res.status(200).json(
|
|
253
|
+
{
|
|
254
|
+
status: false,
|
|
255
|
+
msg: 'Billing city not specified'
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (!body.billingZip) {
|
|
260
|
+
return res.status(200).json(
|
|
261
|
+
{
|
|
262
|
+
status: false,
|
|
263
|
+
msg: 'Billing zip not specified'
|
|
264
|
+
})
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
console.log(`. body.zip: ${body.zip}`) */
|
|
268
|
+
// Get UserProfile record
|
|
269
|
+
const userProfile = await this.userProfileModel.getById(prisma, body.userProfileId);
|
|
270
|
+
// Get country codes for countries
|
|
271
|
+
const countryCode = this.getCountryCodeByName(body.country);
|
|
272
|
+
// const billingCountryCode = this.getCountryCodeByName(body.billingCountry)
|
|
273
|
+
// Update the user profile
|
|
274
|
+
await this.update(prisma, body.userProfileId, body.firstName, body.fullName, countryCode);
|
|
275
|
+
// Validate
|
|
276
|
+
if (userProfile == null) {
|
|
277
|
+
throw new CustomError(`${fnName}: userProfile == null`);
|
|
278
|
+
}
|
|
279
|
+
if (userProfile.userId == null) {
|
|
280
|
+
throw new CustomError(`${fnName}: userProfile.userId == null`);
|
|
281
|
+
}
|
|
282
|
+
// Update the User
|
|
283
|
+
await this.userModel.update(prisma, userProfile.userId, undefined, // email
|
|
284
|
+
body.fullName);
|
|
285
|
+
// Respond
|
|
286
|
+
return res.status(200).json({
|
|
287
|
+
status: true,
|
|
288
|
+
msg: 'OK'
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
async validateProfileCompleted(prisma, forAction, userProfileId) {
|
|
292
|
+
const userPreferences = await this.getAll(prisma, userProfileId);
|
|
293
|
+
return this.validateRequiredFields(forAction, userPreferences);
|
|
294
|
+
}
|
|
295
|
+
validateRequiredFields(forAction, userPreferences) {
|
|
296
|
+
// If for a scription, no fields are required (only the email sign-up)
|
|
297
|
+
if (forAction === 'subscription') {
|
|
298
|
+
return {
|
|
299
|
+
status: true
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
// Validate required fields
|
|
303
|
+
if (!userPreferences[this.firstName]) {
|
|
304
|
+
return {
|
|
305
|
+
status: false,
|
|
306
|
+
message: 'First name is missing for the user'
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
if (!userPreferences[this.fullName]) {
|
|
310
|
+
return {
|
|
311
|
+
status: false,
|
|
312
|
+
message: 'Full name is missing for the user'
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (!userPreferences[this.countryCode]) {
|
|
316
|
+
return {
|
|
317
|
+
status: false,
|
|
318
|
+
message: 'Country is missing for the user'
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
/* if (!userPreferences[this.billingNameAsMyName]) {
|
|
322
|
+
return {
|
|
323
|
+
status: false,
|
|
324
|
+
message: 'Billing name as my name checked (or not) is missing for the user'
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (!userPreferences[this.billingCountryAsMyCountry]) {
|
|
329
|
+
return {
|
|
330
|
+
status: false,
|
|
331
|
+
message: 'Billing country as my country checked (or not) is missing for the user'
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (userPreferences[this.billingNameAsMyName] === 'false') {
|
|
336
|
+
if (!userPreferences[this.billingFirstName]) {
|
|
337
|
+
return {
|
|
338
|
+
status: false,
|
|
339
|
+
message: 'Billing first name is missing for the user'
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (!userPreferences[this.billingLastName]) {
|
|
344
|
+
return {
|
|
345
|
+
status: false,
|
|
346
|
+
message: 'Billing last name is missing for the user'
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (userPreferences[this.billingCountryAsMyCountry] === 'false') {
|
|
352
|
+
if (!userPreferences[this.billingCountryCode]) {
|
|
353
|
+
return {
|
|
354
|
+
status: false,
|
|
355
|
+
message: 'Billing country is missing for the user'
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (!userPreferences[this.billingAddressLine1]) {
|
|
361
|
+
return {
|
|
362
|
+
status: false,
|
|
363
|
+
message: 'Billing address line 1 is missing for the user'
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (!userPreferences[this.billingCity]) {
|
|
368
|
+
return {
|
|
369
|
+
status: false,
|
|
370
|
+
message: 'Billing city is missing for the user'
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (!userPreferences[this.billingZip]) {
|
|
375
|
+
return {
|
|
376
|
+
status: false,
|
|
377
|
+
message: 'Billing zip is missing for the user'
|
|
378
|
+
}
|
|
379
|
+
} */
|
|
380
|
+
// Validated OK
|
|
381
|
+
return {
|
|
382
|
+
status: true
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { PrismaClient } from '@/prisma/client';
|
|
2
|
+
import { UserProfileModel } from '../../models/users/user-profile-model';
|
|
3
|
+
import { UserModel } from '../../models/users/user-model';
|
|
4
|
+
import { UserPreferenceService } from '../user-preference/service';
|
|
5
|
+
export declare class UsersService {
|
|
6
|
+
clName: string;
|
|
7
|
+
userModel: UserModel;
|
|
8
|
+
userProfileModel: UserProfileModel;
|
|
9
|
+
userPreferenceService: UserPreferenceService;
|
|
10
|
+
createBlankUser(prisma: PrismaClient): Promise<{
|
|
11
|
+
id: string;
|
|
12
|
+
userId: string | null;
|
|
13
|
+
created: Date;
|
|
14
|
+
updated: Date;
|
|
15
|
+
isAdmin: boolean;
|
|
16
|
+
ownerType: string | null;
|
|
17
|
+
roles: string[];
|
|
18
|
+
deletePending: Date | null;
|
|
19
|
+
}>;
|
|
20
|
+
createDefaultUserPreferences(prisma: PrismaClient, userProfileId: string, defaultUserPreferences: string | undefined): Promise<void>;
|
|
21
|
+
createUserByEmail(prisma: PrismaClient, email: string): Promise<string>;
|
|
22
|
+
getById(prisma: PrismaClient, userProfileId: string): Promise<{
|
|
23
|
+
id: string;
|
|
24
|
+
userId: string | null;
|
|
25
|
+
created: Date;
|
|
26
|
+
updated: Date;
|
|
27
|
+
isAdmin: boolean;
|
|
28
|
+
ownerType: string | null;
|
|
29
|
+
roles: string[];
|
|
30
|
+
deletePending: Date | null;
|
|
31
|
+
} | null | undefined>;
|
|
32
|
+
getUserByUserProfileId(prisma: PrismaClient, userProfileId: string): Promise<{
|
|
33
|
+
name: string | null;
|
|
34
|
+
id: string;
|
|
35
|
+
image: string | null;
|
|
36
|
+
email: string | null;
|
|
37
|
+
emailVerified: Date | null;
|
|
38
|
+
} | null | undefined>;
|
|
39
|
+
getOrCreateSignedOutUser(prisma: PrismaClient, signedOutId: string, defaultUserPreferences: string): Promise<{
|
|
40
|
+
id: string;
|
|
41
|
+
}>;
|
|
42
|
+
getOrCreateUserByEmail(prisma: PrismaClient, email: string, defaultUserPreferences: string | undefined): Promise<{
|
|
43
|
+
id: string;
|
|
44
|
+
userId: string | null;
|
|
45
|
+
created: Date;
|
|
46
|
+
updated: Date;
|
|
47
|
+
isAdmin: boolean;
|
|
48
|
+
ownerType: string | null;
|
|
49
|
+
roles: string[];
|
|
50
|
+
deletePending: Date | null;
|
|
51
|
+
}>;
|
|
52
|
+
getUserProfileByEmail(prisma: PrismaClient, email: string): Promise<{
|
|
53
|
+
id: string;
|
|
54
|
+
userId: string | null;
|
|
55
|
+
created: Date;
|
|
56
|
+
updated: Date;
|
|
57
|
+
isAdmin: boolean;
|
|
58
|
+
ownerType: string | null;
|
|
59
|
+
roles: string[];
|
|
60
|
+
deletePending: Date | null;
|
|
61
|
+
} | null | undefined>;
|
|
62
|
+
verifyHumanUserProfile(prisma: PrismaClient, userProfileId: string): Promise<void>;
|
|
63
|
+
verifySignedInUserProfileId(prisma: PrismaClient, userProfileId: string): Promise<boolean>;
|
|
64
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { CustomError } from '../../types/errors';
|
|
2
|
+
import { UserProfileModel } from '../../models/users/user-profile-model';
|
|
3
|
+
import { UserModel } from '../../models/users/user-model';
|
|
4
|
+
import { UserPreferenceService } from '../user-preference/service';
|
|
5
|
+
export class UsersService {
|
|
6
|
+
// Consts
|
|
7
|
+
clName = 'UsersService';
|
|
8
|
+
// Models
|
|
9
|
+
userModel = new UserModel();
|
|
10
|
+
userProfileModel = new UserProfileModel();
|
|
11
|
+
// Services
|
|
12
|
+
userPreferenceService = new UserPreferenceService();
|
|
13
|
+
// Code
|
|
14
|
+
async createBlankUser(prisma) {
|
|
15
|
+
// console.log('UsersService.createBlankUser(): start')
|
|
16
|
+
return await this.userProfileModel.create(prisma, null, // userId
|
|
17
|
+
false, // isAdmin
|
|
18
|
+
null); // deletePending
|
|
19
|
+
}
|
|
20
|
+
async createDefaultUserPreferences(prisma, userProfileId, defaultUserPreferences) {
|
|
21
|
+
// console.log('createDefaultUserPreferences()')
|
|
22
|
+
if (defaultUserPreferences == null ||
|
|
23
|
+
defaultUserPreferences === '') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const jsonArray = JSON.parse(defaultUserPreferences);
|
|
27
|
+
for (const json of jsonArray) {
|
|
28
|
+
await this.userPreferenceService.createIfNotExists(prisma, userProfileId, json.category, json.key, json.value, null);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async createUserByEmail(prisma, email) {
|
|
32
|
+
const user = await this.userModel.create(prisma, email, undefined); // name
|
|
33
|
+
const userProfile = await this.userProfileModel.create(prisma, user.id, false, // isAdmin
|
|
34
|
+
null); // deletePending
|
|
35
|
+
return userProfile.id;
|
|
36
|
+
}
|
|
37
|
+
async getById(prisma, userProfileId) {
|
|
38
|
+
return await this.userProfileModel.getById(prisma, userProfileId);
|
|
39
|
+
}
|
|
40
|
+
async getUserByUserProfileId(prisma, userProfileId) {
|
|
41
|
+
// Debug
|
|
42
|
+
const fnName = `${this.clName}.getUserByUserProfileId()`;
|
|
43
|
+
// Get userProfile
|
|
44
|
+
const userProfile = await this.getById(prisma, userProfileId);
|
|
45
|
+
// Validate
|
|
46
|
+
if (userProfile == null) {
|
|
47
|
+
throw new CustomError(`${fnName}: userProfile == null`);
|
|
48
|
+
}
|
|
49
|
+
// Get user record
|
|
50
|
+
if (userProfile.userId == null) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return await this.userModel.getById(prisma, userProfile.userId);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async getOrCreateSignedOutUser(prisma, signedOutId, defaultUserPreferences) {
|
|
58
|
+
// Debug
|
|
59
|
+
const fnName = `${this.clName}.getOrCreateSignedOutUser()`;
|
|
60
|
+
// User id exists, use it
|
|
61
|
+
var userProfile = null;
|
|
62
|
+
var signedOutUserProfile = {
|
|
63
|
+
id: signedOutId
|
|
64
|
+
};
|
|
65
|
+
if (signedOutId != null) {
|
|
66
|
+
// console.log(`${fnName}: getting user..`)
|
|
67
|
+
userProfile = await this.getById(prisma, signedOutId);
|
|
68
|
+
if (userProfile) {
|
|
69
|
+
if (userProfile.id) {
|
|
70
|
+
signedOutUserProfile = userProfile;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (userProfile == null) {
|
|
75
|
+
// Create user record
|
|
76
|
+
// console.log(`${fnName}: creating user..`)
|
|
77
|
+
const userProfile = await this.createBlankUser(prisma);
|
|
78
|
+
// console.log(`${fnName}: userProfileId: ${userProfile.id}`)
|
|
79
|
+
signedOutUserProfile = userProfile;
|
|
80
|
+
signedOutId = userProfile.id;
|
|
81
|
+
}
|
|
82
|
+
// Create default user preferences
|
|
83
|
+
await this.createDefaultUserPreferences(prisma, signedOutId, defaultUserPreferences);
|
|
84
|
+
// Return signedOutId
|
|
85
|
+
return signedOutUserProfile;
|
|
86
|
+
}
|
|
87
|
+
async getOrCreateUserByEmail(prisma, email, defaultUserPreferences) {
|
|
88
|
+
// Debug
|
|
89
|
+
const fnName = `${this.clName}.getOrCreateUserByEmail()`;
|
|
90
|
+
// console.log(`UsersService.getOrCreateUserByEmail(): email: ${email}`)
|
|
91
|
+
// Get/create user record
|
|
92
|
+
var signedInUser = await this.userModel.getByEmail(prisma, email);
|
|
93
|
+
if (signedInUser == null) {
|
|
94
|
+
signedInUser = await this.userModel.create(prisma, email, undefined); // name
|
|
95
|
+
}
|
|
96
|
+
// Get/create userProfile record
|
|
97
|
+
// console.log(`UsersService.getOrCreateUserByEmail(): get userProfile ` +
|
|
98
|
+
// `records where signedInUser.id = ${signedInUser.id}`)
|
|
99
|
+
var signedInUserProfile = await this.userProfileModel.getByUserId(prisma, signedInUser.id);
|
|
100
|
+
// console.log(`signedInUserProfile: ` + JSON.stringify(signedInUserProfile))
|
|
101
|
+
if (signedInUserProfile == null) {
|
|
102
|
+
// Create userProfile record
|
|
103
|
+
signedInUserProfile = await this.userProfileModel.create(prisma, signedInUser.id, // userId
|
|
104
|
+
false, // isAdmin
|
|
105
|
+
null); // deletePending
|
|
106
|
+
}
|
|
107
|
+
// Create default user preferences
|
|
108
|
+
await this.createDefaultUserPreferences(prisma, signedInUserProfile.id, defaultUserPreferences);
|
|
109
|
+
return signedInUserProfile;
|
|
110
|
+
}
|
|
111
|
+
async getUserProfileByEmail(prisma, email) {
|
|
112
|
+
// console.log(`UsersService.getUserProfileByEmail(): emailLower: ${emailLower}`)
|
|
113
|
+
const user = await this.userModel.getByEmail(prisma, email);
|
|
114
|
+
if (user == null) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return await this.userProfileModel.getByUserId(prisma, user.id);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async verifyHumanUserProfile(prisma, userProfileId) {
|
|
122
|
+
// Debug
|
|
123
|
+
const fnName = `${this.clName}.verifyHumanUserProfile()`;
|
|
124
|
+
// Get UserProfile record
|
|
125
|
+
const userProfile = await this.getById(prisma, userProfileId);
|
|
126
|
+
// Validate
|
|
127
|
+
if (userProfile == null) {
|
|
128
|
+
throw new CustomError(`${fnName}: userProfile == null`);
|
|
129
|
+
}
|
|
130
|
+
// Verify human roleOwnerType, or set if none
|
|
131
|
+
if (userProfile.ownerType == null) {
|
|
132
|
+
await this.userProfileModel.setOwnerType(prisma, userProfile);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async verifySignedInUserProfileId(prisma, userProfileId) {
|
|
136
|
+
// Debug
|
|
137
|
+
const fnName = `${this.clName}.verifySignedInUserProfileId()`;
|
|
138
|
+
// Get UserProfile
|
|
139
|
+
const userProfile = await this.userProfileModel.getById(prisma, userProfileId);
|
|
140
|
+
// Validate
|
|
141
|
+
if (userProfile == null) {
|
|
142
|
+
throw new CustomError(`${fnName}: userProfile == null`);
|
|
143
|
+
}
|
|
144
|
+
// Return
|
|
145
|
+
if (userProfile.userId == null) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PrismaClient } from '@/prisma/client';
|
|
2
|
+
export declare class UserErrorService {
|
|
3
|
+
upsert(prisma: PrismaClient, userProfileId: string, endUserProfileId: string | null, instanceId: string | null, summaryMessage: string | undefined, origin: string, message: string, techMessage: string | null): Promise<void>;
|
|
4
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { UserErrorModel } from '../../models/users/user-error-model';
|
|
2
|
+
import { UserErrorSummaryModel } from '../../models/users/user-error-summary-model';
|
|
3
|
+
// Models
|
|
4
|
+
const userErrorModel = new UserErrorModel();
|
|
5
|
+
const userErrorSummaryModel = new UserErrorSummaryModel();
|
|
6
|
+
// Class
|
|
7
|
+
export class UserErrorService {
|
|
8
|
+
async upsert(prisma, userProfileId, endUserProfileId, instanceId, summaryMessage, origin, message, techMessage) {
|
|
9
|
+
// If the summaryMessage isn't specified, set it to the message
|
|
10
|
+
if (summaryMessage == null) {
|
|
11
|
+
summaryMessage = message;
|
|
12
|
+
}
|
|
13
|
+
// Get the existing UserErrorSummary if it exists
|
|
14
|
+
var userErrorSummary = await userErrorSummaryModel.getByUniqueKey(prisma, userProfileId, instanceId, origin, summaryMessage);
|
|
15
|
+
// Create/update UserErrorSummary
|
|
16
|
+
if (userErrorSummary == null) {
|
|
17
|
+
// Create
|
|
18
|
+
userErrorSummary = await userErrorSummaryModel.create(prisma, userProfileId, instanceId, origin, summaryMessage, 1); // count
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// Inc count
|
|
22
|
+
userErrorSummary = await userErrorSummaryModel.update(prisma, userErrorSummary.id, undefined, undefined, undefined, undefined, userErrorSummary.count + 1);
|
|
23
|
+
}
|
|
24
|
+
// Create UserError
|
|
25
|
+
const userError = await userErrorModel.create(prisma, userErrorSummary.id, userProfileId, endUserProfileId, instanceId, origin, message, techMessage);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PrismaClient } from '@/prisma/client';
|
|
2
|
+
import { UserGroupMemberModel } from '../../models/users/user-group-member-model';
|
|
3
|
+
import { UserGroupModel } from '../../models/users/user-group-model';
|
|
4
|
+
export declare class UsersGroupService {
|
|
5
|
+
clName: string;
|
|
6
|
+
externalUsersGroupName: string;
|
|
7
|
+
userGroupMemberModel: UserGroupMemberModel;
|
|
8
|
+
userGroupModel: UserGroupModel;
|
|
9
|
+
verifyGroupMemberByOwner(prisma: PrismaClient, memberUserProfileId: string, ownerUserProfileId: string, groupName: string): Promise<{
|
|
10
|
+
status: boolean;
|
|
11
|
+
message: string;
|
|
12
|
+
} | {
|
|
13
|
+
status: boolean;
|
|
14
|
+
message?: undefined;
|
|
15
|
+
}>;
|
|
16
|
+
}
|