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.
Files changed (315) hide show
  1. package/dist/apollo/resolvers/mutations/mailing-lists.d.ts +11 -0
  2. package/dist/apollo/resolvers/mutations/mailing-lists.js +30 -0
  3. package/dist/apollo/resolvers/mutations/user-preferences.d.ts +13 -0
  4. package/dist/apollo/resolvers/mutations/user-preferences.js +31 -0
  5. package/dist/apollo/resolvers/mutations/users.d.ts +28 -0
  6. package/dist/apollo/resolvers/mutations/users.js +44 -0
  7. package/dist/apollo/resolvers/queries/access.d.ts +11 -0
  8. package/dist/apollo/resolvers/queries/access.js +25 -0
  9. package/dist/apollo/resolvers/queries/profile.d.ts +11 -0
  10. package/dist/apollo/resolvers/queries/profile.js +25 -0
  11. package/dist/apollo/resolvers/queries/quotas.d.ts +21 -0
  12. package/dist/apollo/resolvers/queries/quotas.js +25 -0
  13. package/dist/apollo/resolvers/queries/tech.d.ts +5 -0
  14. package/dist/apollo/resolvers/queries/tech.js +35 -0
  15. package/dist/apollo/resolvers/queries/user-preferences.d.ts +5 -0
  16. package/dist/apollo/resolvers/queries/user-preferences.js +33 -0
  17. package/dist/apollo/resolvers/queries/users.d.ts +15 -0
  18. package/dist/apollo/resolvers/queries/users.js +28 -0
  19. package/dist/apollo/resolvers/resolvers.d.ts +20 -0
  20. package/dist/apollo/resolvers/resolvers.js +38 -0
  21. package/dist/apollo/typedefs/typedefs.d.ts +1 -0
  22. package/dist/apollo/typedefs/typedefs.js +142 -0
  23. package/dist/index.d.ts +52 -0
  24. package/dist/index.js +68 -0
  25. package/dist/models/chat/chat-message-created-model.d.ts +17 -0
  26. package/dist/models/chat/chat-message-created-model.js +113 -0
  27. package/dist/models/chat/chat-message-model.d.ts +44 -0
  28. package/dist/models/chat/chat-message-model.js +523 -0
  29. package/dist/models/chat/chat-participant-model.d.ts +39 -0
  30. package/dist/models/chat/chat-participant-model.js +211 -0
  31. package/dist/models/chat/chat-session-model.d.ts +92 -0
  32. package/dist/models/chat/chat-session-model.js +301 -0
  33. package/dist/models/chat/chat-settings-model.d.ts +87 -0
  34. package/dist/models/chat/chat-settings-model.js +261 -0
  35. package/dist/models/feature-flags/feature-flag-model.d.ts +40 -0
  36. package/dist/models/feature-flags/feature-flag-model.js +164 -0
  37. package/dist/models/instances/instance-model.d.ts +93 -0
  38. package/dist/models/instances/instance-model.js +432 -0
  39. package/dist/models/instances/instance-setting-model.d.ts +39 -0
  40. package/dist/models/instances/instance-setting-model.js +193 -0
  41. package/dist/models/mailing-lists/mailing-list-model.d.ts +34 -0
  42. package/dist/models/mailing-lists/mailing-list-model.js +154 -0
  43. package/dist/models/mailing-lists/mailing-list-subscriber-model.d.ts +36 -0
  44. package/dist/models/mailing-lists/mailing-list-subscriber-model.js +152 -0
  45. package/dist/models/quotas/resource-quota-total-model.d.ts +46 -0
  46. package/dist/models/quotas/resource-quota-total-model.js +200 -0
  47. package/dist/models/quotas/resource-quota-usage-model.d.ts +51 -0
  48. package/dist/models/quotas/resource-quota-usage-model.js +181 -0
  49. package/dist/models/tech/rate-limited-api-event-model.d.ts +25 -0
  50. package/dist/models/tech/rate-limited-api-event-model.js +161 -0
  51. package/dist/models/tech/rate-limited-api-model.d.ts +21 -0
  52. package/dist/models/tech/rate-limited-api-model.js +141 -0
  53. package/dist/models/tech/tech-model.d.ts +44 -0
  54. package/dist/models/tech/tech-model.js +268 -0
  55. package/dist/models/tech/tech-provider-api-key-model.d.ts +43 -0
  56. package/dist/models/tech/tech-provider-api-key-model.js +224 -0
  57. package/dist/models/tech/tech-provider-model.d.ts +28 -0
  58. package/dist/models/tech/tech-provider-model.js +197 -0
  59. package/dist/models/users/external-user-integration-model.d.ts +36 -0
  60. package/dist/models/users/external-user-integration-model.js +196 -0
  61. package/dist/models/users/user-error-model.d.ts +54 -0
  62. package/dist/models/users/user-error-model.js +173 -0
  63. package/dist/models/users/user-error-summary-model.d.ts +45 -0
  64. package/dist/models/users/user-error-summary-model.js +172 -0
  65. package/dist/models/users/user-group-member-model.d.ts +41 -0
  66. package/dist/models/users/user-group-member-model.js +193 -0
  67. package/dist/models/users/user-group-model.d.ts +27 -0
  68. package/dist/models/users/user-group-model.js +146 -0
  69. package/dist/models/users/user-model.d.ts +46 -0
  70. package/dist/models/users/user-model.js +153 -0
  71. package/dist/models/users/user-preference-model.d.ts +60 -0
  72. package/dist/models/users/user-preference-model.js +228 -0
  73. package/dist/models/users/user-profile-model.d.ts +58 -0
  74. package/dist/models/users/user-profile-model.js +173 -0
  75. package/dist/prisma.config.d.ts +3 -0
  76. package/dist/prisma.config.js +13 -0
  77. package/dist/services/access/access-service.d.ts +12 -0
  78. package/dist/services/access/access-service.js +44 -0
  79. package/dist/services/access/encrypt-service.d.ts +13 -0
  80. package/dist/services/access/encrypt-service.js +84 -0
  81. package/dist/services/api-usage/api-usage-base-service.d.ts +15 -0
  82. package/dist/services/api-usage/api-usage-base-service.js +75 -0
  83. package/dist/services/console/service.d.ts +7 -0
  84. package/dist/services/console/service.js +70 -0
  85. package/dist/services/db/pg/pg-estimate-size-service.d.ts +16 -0
  86. package/dist/services/db/pg/pg-estimate-size-service.js +90 -0
  87. package/dist/services/files/types.d.ts +6 -0
  88. package/dist/services/files/types.js +2 -0
  89. package/dist/services/files/walk-dir-service.d.ts +8 -0
  90. package/dist/services/files/walk-dir-service.js +94 -0
  91. package/dist/services/locale/countries.d.ts +6 -0
  92. package/dist/services/locale/countries.js +484 -0
  93. package/dist/services/mailing-lists/mailing-list-subscriber-service.d.ts +14 -0
  94. package/dist/services/mailing-lists/mailing-list-subscriber-service.js +45 -0
  95. package/dist/services/process/sleep.d.ts +2 -0
  96. package/dist/services/process/sleep.js +10 -0
  97. package/dist/services/quotas/mutate-service.d.ts +5 -0
  98. package/dist/services/quotas/mutate-service.js +54 -0
  99. package/dist/services/quotas/query-service.d.ts +27 -0
  100. package/dist/services/quotas/query-service.js +137 -0
  101. package/dist/services/quotas/utils-service.d.ts +4 -0
  102. package/dist/services/quotas/utils-service.js +28 -0
  103. package/dist/services/tech/tech-provider-mutate-service.d.ts +7 -0
  104. package/dist/services/tech/tech-provider-mutate-service.js +142 -0
  105. package/dist/services/tech/tech-query-service.d.ts +9 -0
  106. package/dist/services/tech/tech-query-service.js +77 -0
  107. package/dist/services/user-preference/service.d.ts +10 -0
  108. package/dist/services/user-preference/service.js +70 -0
  109. package/dist/services/users/external-user-integration-service.d.ts +9 -0
  110. package/dist/services/users/external-user-integration-service.js +42 -0
  111. package/dist/services/users/profile-service.d.ts +40 -0
  112. package/dist/services/users/profile-service.js +408 -0
  113. package/dist/services/users/service.d.ts +64 -0
  114. package/dist/services/users/service.js +187 -0
  115. package/dist/services/users/user-error-service.d.ts +4 -0
  116. package/dist/services/users/user-error-service.js +42 -0
  117. package/dist/services/users/users-group-service.d.ts +16 -0
  118. package/dist/services/users/users-group-service.js +68 -0
  119. package/dist/services/utils/string-utils-service.d.ts +5 -0
  120. package/dist/services/utils/string-utils-service.js +41 -0
  121. package/dist/src/apollo/resolvers/mutations/mailing-lists.d.ts +11 -0
  122. package/dist/src/apollo/resolvers/mutations/mailing-lists.js +19 -0
  123. package/dist/src/apollo/resolvers/mutations/user-preferences.d.ts +13 -0
  124. package/dist/src/apollo/resolvers/mutations/user-preferences.js +20 -0
  125. package/dist/src/apollo/resolvers/mutations/users.d.ts +28 -0
  126. package/dist/src/apollo/resolvers/mutations/users.js +33 -0
  127. package/dist/src/apollo/resolvers/queries/access.d.ts +11 -0
  128. package/dist/src/apollo/resolvers/queries/access.js +14 -0
  129. package/dist/src/apollo/resolvers/queries/profile.d.ts +11 -0
  130. package/dist/src/apollo/resolvers/queries/profile.js +14 -0
  131. package/dist/src/apollo/resolvers/queries/quotas.d.ts +21 -0
  132. package/dist/src/apollo/resolvers/queries/quotas.js +14 -0
  133. package/dist/src/apollo/resolvers/queries/tech.d.ts +5 -0
  134. package/dist/src/apollo/resolvers/queries/tech.js +24 -0
  135. package/dist/src/apollo/resolvers/queries/user-preferences.d.ts +5 -0
  136. package/dist/src/apollo/resolvers/queries/user-preferences.js +22 -0
  137. package/dist/src/apollo/resolvers/queries/users.d.ts +15 -0
  138. package/dist/src/apollo/resolvers/queries/users.js +17 -0
  139. package/dist/src/apollo/typedefs/typedefs.d.ts +1 -0
  140. package/dist/src/apollo/typedefs/typedefs.js +139 -0
  141. package/dist/src/db.d.ts +3 -0
  142. package/dist/src/db.js +11 -0
  143. package/dist/src/index.d.ts +52 -0
  144. package/dist/src/index.js +52 -0
  145. package/dist/src/models/chat/chat-message-created-model.d.ts +17 -0
  146. package/dist/src/models/chat/chat-message-created-model.js +92 -0
  147. package/dist/src/models/chat/chat-message-model.d.ts +44 -0
  148. package/dist/src/models/chat/chat-message-model.js +484 -0
  149. package/dist/src/models/chat/chat-participant-model.d.ts +39 -0
  150. package/dist/src/models/chat/chat-participant-model.js +178 -0
  151. package/dist/src/models/chat/chat-session-model.d.ts +92 -0
  152. package/dist/src/models/chat/chat-session-model.js +266 -0
  153. package/dist/src/models/chat/chat-settings-model.d.ts +87 -0
  154. package/dist/src/models/chat/chat-settings-model.js +230 -0
  155. package/dist/src/models/feature-flags/feature-flag-model.d.ts +40 -0
  156. package/dist/src/models/feature-flags/feature-flag-model.js +137 -0
  157. package/dist/src/models/instances/instance-model.d.ts +100 -0
  158. package/dist/src/models/instances/instance-model.js +466 -0
  159. package/dist/src/models/instances/instance-setting-model.d.ts +39 -0
  160. package/dist/src/models/instances/instance-setting-model.js +164 -0
  161. package/dist/src/models/mailing-lists/mailing-list-model.d.ts +34 -0
  162. package/dist/src/models/mailing-lists/mailing-list-model.js +127 -0
  163. package/dist/src/models/mailing-lists/mailing-list-subscriber-model.d.ts +36 -0
  164. package/dist/src/models/mailing-lists/mailing-list-subscriber-model.js +127 -0
  165. package/dist/src/models/quotas/resource-quota-total-model.d.ts +46 -0
  166. package/dist/src/models/quotas/resource-quota-total-model.js +170 -0
  167. package/dist/src/models/quotas/resource-quota-usage-model.d.ts +51 -0
  168. package/dist/src/models/quotas/resource-quota-usage-model.js +151 -0
  169. package/dist/src/models/tech/rate-limited-api-event-model.d.ts +25 -0
  170. package/dist/src/models/tech/rate-limited-api-event-model.js +134 -0
  171. package/dist/src/models/tech/rate-limited-api-model.d.ts +21 -0
  172. package/dist/src/models/tech/rate-limited-api-model.js +116 -0
  173. package/dist/src/models/tech/tech-model.d.ts +44 -0
  174. package/dist/src/models/tech/tech-model.js +239 -0
  175. package/dist/src/models/tech/tech-provider-api-key-model.d.ts +43 -0
  176. package/dist/src/models/tech/tech-provider-api-key-model.js +195 -0
  177. package/dist/src/models/tech/tech-provider-model.d.ts +28 -0
  178. package/dist/src/models/tech/tech-provider-model.js +170 -0
  179. package/dist/src/models/users/external-user-integration-model.d.ts +36 -0
  180. package/dist/src/models/users/external-user-integration-model.js +167 -0
  181. package/dist/src/models/users/user-error-model.d.ts +54 -0
  182. package/dist/src/models/users/user-error-model.js +146 -0
  183. package/dist/src/models/users/user-error-summary-model.d.ts +45 -0
  184. package/dist/src/models/users/user-error-summary-model.js +145 -0
  185. package/dist/src/models/users/user-group-member-model.d.ts +41 -0
  186. package/dist/src/models/users/user-group-member-model.js +164 -0
  187. package/dist/src/models/users/user-group-model.d.ts +27 -0
  188. package/dist/src/models/users/user-group-model.js +121 -0
  189. package/dist/src/models/users/user-model.d.ts +46 -0
  190. package/dist/src/models/users/user-model.js +126 -0
  191. package/dist/src/models/users/user-preference-model.d.ts +60 -0
  192. package/dist/src/models/users/user-preference-model.js +197 -0
  193. package/dist/src/models/users/user-profile-model.d.ts +58 -0
  194. package/dist/src/models/users/user-profile-model.js +146 -0
  195. package/dist/src/services/access/access-service.d.ts +12 -0
  196. package/dist/src/services/access/access-service.js +27 -0
  197. package/dist/src/services/access/encrypt-service.d.ts +13 -0
  198. package/dist/src/services/access/encrypt-service.js +79 -0
  199. package/dist/src/services/api-usage/api-usage-base-service.d.ts +15 -0
  200. package/dist/src/services/api-usage/api-usage-base-service.js +58 -0
  201. package/dist/src/services/console/service.d.ts +7 -0
  202. package/dist/src/services/console/service.js +18 -0
  203. package/dist/src/services/db/pg/pg-estimate-size-service.d.ts +16 -0
  204. package/dist/src/services/db/pg/pg-estimate-size-service.js +83 -0
  205. package/dist/src/services/files/types.d.ts +6 -0
  206. package/dist/src/services/files/types.js +1 -0
  207. package/dist/src/services/files/walk-dir-service.d.ts +8 -0
  208. package/dist/src/services/files/walk-dir-service.js +77 -0
  209. package/dist/src/services/locale/countries.d.ts +6 -0
  210. package/dist/src/services/locale/countries.js +481 -0
  211. package/dist/src/services/mailing-lists/mailing-list-subscriber-service.d.ts +14 -0
  212. package/dist/src/services/mailing-lists/mailing-list-subscriber-service.js +28 -0
  213. package/dist/src/services/process/sleep.d.ts +2 -0
  214. package/dist/src/services/process/sleep.js +6 -0
  215. package/dist/src/services/quotas/mutate-service.d.ts +5 -0
  216. package/dist/src/services/quotas/mutate-service.js +37 -0
  217. package/dist/src/services/quotas/query-service.d.ts +27 -0
  218. package/dist/src/services/quotas/query-service.js +116 -0
  219. package/dist/src/services/quotas/utils-service.d.ts +4 -0
  220. package/dist/src/services/quotas/utils-service.js +22 -0
  221. package/dist/src/services/tech/tech-provider-mutate-service.d.ts +7 -0
  222. package/dist/src/services/tech/tech-provider-mutate-service.js +85 -0
  223. package/dist/src/services/tech/tech-query-service.d.ts +9 -0
  224. package/dist/src/services/tech/tech-query-service.js +58 -0
  225. package/dist/src/services/user-preference/service.d.ts +10 -0
  226. package/dist/src/services/user-preference/service.js +49 -0
  227. package/dist/src/services/users/external-user-integration-service.d.ts +9 -0
  228. package/dist/src/services/users/external-user-integration-service.js +25 -0
  229. package/dist/src/services/users/profile-service.d.ts +40 -0
  230. package/dist/src/services/users/profile-service.js +385 -0
  231. package/dist/src/services/users/service.d.ts +64 -0
  232. package/dist/src/services/users/service.js +152 -0
  233. package/dist/src/services/users/user-error-service.d.ts +4 -0
  234. package/dist/src/services/users/user-error-service.js +27 -0
  235. package/dist/src/services/users/users-group-service.d.ts +16 -0
  236. package/dist/src/services/users/users-group-service.js +51 -0
  237. package/dist/src/services/utils/field-naming-service.d.ts +20 -0
  238. package/dist/src/services/utils/field-naming-service.js +59 -0
  239. package/dist/src/services/utils/string-utils-service.d.ts +5 -0
  240. package/dist/src/services/utils/string-utils-service.js +37 -0
  241. package/dist/src/types/errors.d.ts +9 -0
  242. package/dist/src/types/errors.js +15 -0
  243. package/dist/src/types/user-types.d.ts +11 -0
  244. package/dist/src/types/user-types.js +14 -0
  245. package/dist/types/errors.d.ts +9 -0
  246. package/dist/types/errors.js +20 -0
  247. package/dist/types/user-types.d.ts +11 -0
  248. package/dist/types/user-types.js +19 -0
  249. package/package.json +21 -0
  250. package/prisma/schema.prisma +572 -0
  251. package/prisma.config.ts +14 -0
  252. package/src/apollo/README.md +4 -0
  253. package/src/apollo/resolvers/mutations/mailing-lists.ts +30 -0
  254. package/src/apollo/resolvers/mutations/user-preferences.ts +33 -0
  255. package/src/apollo/resolvers/mutations/users.ts +61 -0
  256. package/src/apollo/resolvers/queries/access.ts +23 -0
  257. package/src/apollo/resolvers/queries/profile.ts +24 -0
  258. package/src/apollo/resolvers/queries/quotas.ts +25 -0
  259. package/src/apollo/resolvers/queries/tech.ts +42 -0
  260. package/src/apollo/resolvers/queries/user-preferences.ts +34 -0
  261. package/src/apollo/resolvers/queries/users.ts +33 -0
  262. package/src/apollo/typedefs/typedefs.ts +139 -0
  263. package/src/db.ts +19 -0
  264. package/src/index.ts +52 -0
  265. package/src/models/chat/chat-message-created-model.ts +126 -0
  266. package/src/models/chat/chat-message-model.ts +678 -0
  267. package/src/models/chat/chat-participant-model.ts +248 -0
  268. package/src/models/chat/chat-session-model.ts +397 -0
  269. package/src/models/chat/chat-settings-model.ts +336 -0
  270. package/src/models/feature-flags/feature-flag-model.ts +198 -0
  271. package/src/models/instances/instance-model.ts +673 -0
  272. package/src/models/instances/instance-setting-model.ts +235 -0
  273. package/src/models/mailing-lists/mailing-list-model.ts +177 -0
  274. package/src/models/mailing-lists/mailing-list-subscriber-model.ts +194 -0
  275. package/src/models/quotas/resource-quota-total-model.ts +243 -0
  276. package/src/models/quotas/resource-quota-usage-model.ts +219 -0
  277. package/src/models/tech/rate-limited-api-event-model.ts +190 -0
  278. package/src/models/tech/rate-limited-api-model.ts +171 -0
  279. package/src/models/tech/tech-model.ts +360 -0
  280. package/src/models/tech/tech-provider-api-key-model.ts +289 -0
  281. package/src/models/tech/tech-provider-model.ts +247 -0
  282. package/src/models/users/external-user-integration-model.ts +236 -0
  283. package/src/models/users/user-error-model.ts +219 -0
  284. package/src/models/users/user-error-summary-model.ts +216 -0
  285. package/src/models/users/user-group-member-model.ts +233 -0
  286. package/src/models/users/user-group-model.ts +174 -0
  287. package/src/models/users/user-model.ts +172 -0
  288. package/src/models/users/user-preference-model.ts +285 -0
  289. package/src/models/users/user-profile-model.ts +207 -0
  290. package/src/services/access/access-service.ts +36 -0
  291. package/src/services/access/encrypt-service.ts +122 -0
  292. package/src/services/api-usage/api-usage-base-service.ts +95 -0
  293. package/src/services/console/service.ts +24 -0
  294. package/src/services/db/pg/pg-estimate-size-service.ts +119 -0
  295. package/src/services/files/types.ts +7 -0
  296. package/src/services/files/walk-dir-service.ts +135 -0
  297. package/src/services/locale/countries.ts +483 -0
  298. package/src/services/mailing-lists/mailing-list-subscriber-service.ts +54 -0
  299. package/src/services/process/sleep.ts +7 -0
  300. package/src/services/quotas/mutate-service.ts +66 -0
  301. package/src/services/quotas/query-service.ts +197 -0
  302. package/src/services/quotas/utils-service.ts +29 -0
  303. package/src/services/tech/tech-provider-mutate-service.ts +136 -0
  304. package/src/services/tech/tech-query-service.ts +93 -0
  305. package/src/services/user-preference/service.ts +110 -0
  306. package/src/services/users/external-user-integration-service.ts +51 -0
  307. package/src/services/users/profile-service.ts +513 -0
  308. package/src/services/users/service.ts +293 -0
  309. package/src/services/users/user-error-service.ts +74 -0
  310. package/src/services/users/users-group-service.ts +85 -0
  311. package/src/services/utils/field-naming-service.ts +78 -0
  312. package/src/services/utils/string-utils-service.ts +48 -0
  313. package/src/types/errors.ts +18 -0
  314. package/src/types/user-types.ts +19 -0
  315. package/tsconfig.json +25 -0
@@ -0,0 +1,513 @@
1
+ import { PrismaClient } from '@/prisma/client'
2
+ import { CustomError } from '../../types/errors'
3
+ import { UserModel } from '../../models/users/user-model'
4
+ import { UserPreferenceModel } from '../../models/users/user-preference-model'
5
+ import { UserProfileModel } from '../../models/users/user-profile-model'
6
+ import { countries } from '../locale/countries'
7
+ import { UserPreferenceService } from '../user-preference/service'
8
+
9
+ interface ReqRes {
10
+ req: any
11
+ res: any
12
+ }
13
+
14
+ export class ProfileService {
15
+
16
+ // Consts
17
+ clName = 'ProfileService'
18
+
19
+ // billingAddress = 'billing address'
20
+ personalDetails = 'personal details'
21
+
22
+ firstName = 'first name'
23
+ fullName = 'full name'
24
+ lastName = 'last name' // For legacy compatibility with old Chargebee code in Serene Store
25
+ countryCode = 'country code'
26
+ /* billingNameAsMyName = 'billing name as my name'
27
+ billingCountryAsMyCountry = 'billing country as my country'
28
+ billingCountryCode = 'billing country code'
29
+ billingFirstName = 'billing first name'
30
+ billingLastName = 'billing last name'
31
+ billingAddressLine1 = 'billing address line 1'
32
+ billingAddressLine2 = 'billing address line 2'
33
+ billingCity = 'billing city'
34
+ billingState = 'billing state'
35
+ billingZip = 'billing zip' */
36
+
37
+ // Models
38
+ userModel = new UserModel()
39
+ userProfileModel = new UserProfileModel()
40
+ userPreferenceModel = new UserPreferenceModel()
41
+
42
+ // Code
43
+ userPreferenceService = new UserPreferenceService()
44
+
45
+ // Code
46
+ async getAll(
47
+ prisma: PrismaClient,
48
+ userProfileId: string) {
49
+
50
+ // Get userPreference records
51
+ const userPreferences = await
52
+ this.userPreferenceService.getUserPreferences(
53
+ prisma,
54
+ userProfileId,
55
+ this.personalDetails,
56
+ [ this.firstName,
57
+ this.fullName,
58
+ this.countryCode ])
59
+
60
+ /* const userPreferences = await
61
+ this.userPreferenceService.getUserPreferences(
62
+ prisma,
63
+ userProfileId,
64
+ this.billingAddress,
65
+ [ this.firstName,
66
+ this.lastName,
67
+ this.countryCode,
68
+ this.billingNameAsMyName,
69
+ this.billingCountryAsMyCountry,
70
+ this.billingCountryCode,
71
+ this.billingFirstName,
72
+ this.billingLastName,
73
+ this.billingAddressLine1,
74
+ this.billingAddressLine2,
75
+ this.billingCity,
76
+ this.billingState,
77
+ this.billingZip ]) */
78
+
79
+ var userPreferenceMap: any[] = []
80
+
81
+ for (const userPreference of userPreferences) {
82
+ userPreferenceMap[userPreference.key] = userPreference
83
+ }
84
+
85
+ return userPreferenceMap
86
+ }
87
+
88
+ getCountryCodeByName(country: string): string | null {
89
+ for (const countryIter of countries) {
90
+ if (countryIter.name === country) {
91
+ return countryIter.code
92
+ }
93
+ }
94
+
95
+ return null
96
+ }
97
+
98
+ async update(
99
+ prisma: PrismaClient,
100
+ userProfileId: string,
101
+ firstName: string,
102
+ fullName: string,
103
+ countryCode: string | null,
104
+ /* billingNameAsMyName: string,
105
+ billingCountryAsMyCountry: string,
106
+ billingCountryCode: string,
107
+ billingFirstName: string,
108
+ billingLastName: string,
109
+ billingAddressLine1: string,
110
+ billingAddressLine2: string,
111
+ billingCity: string,
112
+ billingState: string,
113
+ billingZip: string */) {
114
+
115
+ // Get userPreference records
116
+ const userPreferenceService: UserPreferenceService = new UserPreferenceService()
117
+
118
+ // Upsert all records
119
+ await this.userPreferenceModel.upsert(
120
+ prisma,
121
+ undefined, // id
122
+ userProfileId,
123
+ this.personalDetails,
124
+ this.firstName,
125
+ firstName,
126
+ null)
127
+
128
+ await this.userPreferenceModel.upsert(
129
+ prisma,
130
+ undefined, // id
131
+ userProfileId,
132
+ this.personalDetails,
133
+ this.fullName,
134
+ fullName,
135
+ null)
136
+
137
+ await this.userPreferenceModel.upsert(
138
+ prisma,
139
+ undefined, // id
140
+ userProfileId,
141
+ this.personalDetails,
142
+ this.countryCode,
143
+ countryCode,
144
+ null)
145
+
146
+ /* await this.userPreferenceModel.upsert(
147
+ prisma,
148
+ undefined, // id
149
+ userProfileId,
150
+ this.billingAddress,
151
+ this.billingNameAsMyName,
152
+ billingNameAsMyName.toString(),
153
+ null)
154
+
155
+ await this.userPreferenceModel.upsert(
156
+ prisma,
157
+ undefined, // id
158
+ userProfileId,
159
+ this.billingAddress,
160
+ this.billingCountryAsMyCountry,
161
+ billingCountryAsMyCountry.toString(),
162
+ null)
163
+
164
+ await this.userPreferenceModel.upsert(
165
+ prisma,
166
+ undefined, // id
167
+ userProfileId,
168
+ this.billingAddress,
169
+ this.billingCountryCode,
170
+ billingCountryCode,
171
+ null)
172
+
173
+ await this.userPreferenceModel.upsert(
174
+ prisma,
175
+ undefined, // id
176
+ userProfileId,
177
+ this.billingAddress,
178
+ this.billingFirstName,
179
+ billingFirstName,
180
+ null)
181
+
182
+ await this.userPreferenceModel.upsert(
183
+ prisma,
184
+ undefined, // id
185
+ userProfileId,
186
+ this.billingAddress,
187
+ this.billingLastName,
188
+ billingLastName,
189
+ null)
190
+
191
+ await this.userPreferenceModel.upsert(
192
+ prisma,
193
+ undefined, // id
194
+ userProfileId,
195
+ this.billingAddress,
196
+ this.billingAddressLine1,
197
+ billingAddressLine1,
198
+ null)
199
+
200
+ await this.userPreferenceModel.upsert(
201
+ prisma,
202
+ undefined, // id
203
+ userProfileId,
204
+ this.billingAddress,
205
+ this.billingAddressLine2,
206
+ billingAddressLine2,
207
+ null)
208
+
209
+ await this.userPreferenceModel.upsert(
210
+ prisma,
211
+ undefined, // id
212
+ userProfileId,
213
+ this.billingAddress,
214
+ this.billingCity,
215
+ billingCity,
216
+ null)
217
+
218
+ await this.userPreferenceModel.upsert(
219
+ prisma,
220
+ undefined, // id
221
+ userProfileId,
222
+ this.billingAddress,
223
+ this.billingState,
224
+ billingState,
225
+ null)
226
+
227
+ await this.userPreferenceModel.upsert(
228
+ prisma,
229
+ undefined, // id
230
+ userProfileId,
231
+ this.billingAddress,
232
+ this.billingZip,
233
+ billingZip,
234
+ null) */
235
+ }
236
+
237
+ async updateViaRestApi(
238
+ { req, res }: ReqRes,
239
+ prisma: PrismaClient) {
240
+
241
+ // Debug
242
+ const fnName = `${this.clName}.updateViaRestApi()`
243
+
244
+ // Get body
245
+ const body = req.body
246
+
247
+ // Validate
248
+ if (!body.userProfileId) {
249
+ return res.status(200).json(
250
+ {
251
+ status: false,
252
+ msg: 'UserProfileId was not found'
253
+ })
254
+ }
255
+
256
+ if (!body.firstName) {
257
+ return res.status(200).json(
258
+ {
259
+ status: false,
260
+ msg: 'First name not specified'
261
+ })
262
+ }
263
+
264
+ if (!body.fullName) {
265
+ return res.status(200).json(
266
+ {
267
+ status: false,
268
+ msg: 'Full name not specified'
269
+ })
270
+ }
271
+
272
+ if (!body.country) {
273
+ return res.status(200).json(
274
+ {
275
+ status: false,
276
+ msg: 'Country not specified'
277
+ })
278
+ }
279
+
280
+ /* if (!body.billingNameAsMyName) {
281
+ return res.status(200).json(
282
+ {
283
+ status: false,
284
+ msg: 'Billing name as my name not specified'
285
+ })
286
+ }
287
+
288
+ if (!body.billingCountryAsMyCountry) {
289
+ return res.status(200).json(
290
+ {
291
+ status: false,
292
+ msg: 'Billing country as my country not specified'
293
+ })
294
+ }
295
+
296
+ if (body.billingNameAsMyName === 'false' &&
297
+ !body.billingFirstName) {
298
+ return res.status(200).json(
299
+ {
300
+ status: false,
301
+ msg: 'Billing first name not specified'
302
+ })
303
+ }
304
+
305
+ if (body.billingNameAsMyName === 'false' &&
306
+ !body.billingLastName) {
307
+ return res.status(200).json(
308
+ {
309
+ status: false,
310
+ msg: 'Billing last name not specified'
311
+ })
312
+ }
313
+
314
+ if (body.billingCountryAsMyCountry === 'false' &&
315
+ !body.billingCountry) {
316
+ return res.status(200).json(
317
+ {
318
+ status: false,
319
+ msg: 'Billing country not specified'
320
+ })
321
+ }
322
+
323
+ if (!body.billingAddressLine1) {
324
+ return res.status(200).json(
325
+ {
326
+ status: false,
327
+ msg: 'Billing address line 1 not specified'
328
+ })
329
+ }
330
+
331
+ if (!body.billingCity) {
332
+ return res.status(200).json(
333
+ {
334
+ status: false,
335
+ msg: 'Billing city not specified'
336
+ })
337
+ }
338
+
339
+ if (!body.billingZip) {
340
+ return res.status(200).json(
341
+ {
342
+ status: false,
343
+ msg: 'Billing zip not specified'
344
+ })
345
+ }
346
+
347
+ console.log(`. body.zip: ${body.zip}`) */
348
+
349
+ // Get UserProfile record
350
+ const userProfile = await
351
+ this.userProfileModel.getById(
352
+ prisma,
353
+ body.userProfileId)
354
+
355
+ // Get country codes for countries
356
+ const countryCode = this.getCountryCodeByName(body.country)
357
+ // const billingCountryCode = this.getCountryCodeByName(body.billingCountry)
358
+
359
+ // Update the user profile
360
+ await this.update(
361
+ prisma,
362
+ body.userProfileId,
363
+ body.firstName,
364
+ body.fullName,
365
+ countryCode,
366
+ /* body.billingNameAsMyName,
367
+ body.billingCountryAsMyCountry,
368
+ billingCountryCode,
369
+ body.billingFirstName,
370
+ body.billingLastName,
371
+ body.billingAddressLine1,
372
+ body.billingAddressLine2,
373
+ body.billingCity,
374
+ body.billingState,
375
+ body.billingZip */)
376
+
377
+ // Validate
378
+ if (userProfile == null) {
379
+ throw new CustomError(`${fnName}: userProfile == null`)
380
+ }
381
+
382
+ if (userProfile.userId == null) {
383
+ throw new CustomError(`${fnName}: userProfile.userId == null`)
384
+ }
385
+
386
+ // Update the User
387
+ await this.userModel.update(
388
+ prisma,
389
+ userProfile.userId,
390
+ undefined, // email
391
+ body.fullName)
392
+
393
+ // Respond
394
+ return res.status(200).json({
395
+ status: true,
396
+ msg: 'OK'
397
+ })
398
+ }
399
+
400
+ async validateProfileCompleted(
401
+ prisma: PrismaClient,
402
+ forAction: string,
403
+ userProfileId: string) {
404
+
405
+ const userPreferences = await
406
+ this.getAll(
407
+ prisma,
408
+ userProfileId)
409
+
410
+ return this.validateRequiredFields(
411
+ forAction,
412
+ userPreferences)
413
+ }
414
+
415
+ validateRequiredFields(
416
+ forAction: string,
417
+ userPreferences: any) {
418
+
419
+ // If for a scription, no fields are required (only the email sign-up)
420
+ if (forAction === 'subscription') {
421
+ return {
422
+ status: true
423
+ }
424
+ }
425
+
426
+ // Validate required fields
427
+ if (!userPreferences[this.firstName]) {
428
+ return {
429
+ status: false,
430
+ message: 'First name is missing for the user'
431
+ }
432
+ }
433
+
434
+ if (!userPreferences[this.fullName]) {
435
+ return {
436
+ status: false,
437
+ message: 'Full name is missing for the user'
438
+ }
439
+ }
440
+
441
+ if (!userPreferences[this.countryCode]) {
442
+ return {
443
+ status: false,
444
+ message: 'Country is missing for the user'
445
+ }
446
+ }
447
+
448
+ /* if (!userPreferences[this.billingNameAsMyName]) {
449
+ return {
450
+ status: false,
451
+ message: 'Billing name as my name checked (or not) is missing for the user'
452
+ }
453
+ }
454
+
455
+ if (!userPreferences[this.billingCountryAsMyCountry]) {
456
+ return {
457
+ status: false,
458
+ message: 'Billing country as my country checked (or not) is missing for the user'
459
+ }
460
+ }
461
+
462
+ if (userPreferences[this.billingNameAsMyName] === 'false') {
463
+ if (!userPreferences[this.billingFirstName]) {
464
+ return {
465
+ status: false,
466
+ message: 'Billing first name is missing for the user'
467
+ }
468
+ }
469
+
470
+ if (!userPreferences[this.billingLastName]) {
471
+ return {
472
+ status: false,
473
+ message: 'Billing last name is missing for the user'
474
+ }
475
+ }
476
+ }
477
+
478
+ if (userPreferences[this.billingCountryAsMyCountry] === 'false') {
479
+ if (!userPreferences[this.billingCountryCode]) {
480
+ return {
481
+ status: false,
482
+ message: 'Billing country is missing for the user'
483
+ }
484
+ }
485
+ }
486
+
487
+ if (!userPreferences[this.billingAddressLine1]) {
488
+ return {
489
+ status: false,
490
+ message: 'Billing address line 1 is missing for the user'
491
+ }
492
+ }
493
+
494
+ if (!userPreferences[this.billingCity]) {
495
+ return {
496
+ status: false,
497
+ message: 'Billing city is missing for the user'
498
+ }
499
+ }
500
+
501
+ if (!userPreferences[this.billingZip]) {
502
+ return {
503
+ status: false,
504
+ message: 'Billing zip is missing for the user'
505
+ }
506
+ } */
507
+
508
+ // Validated OK
509
+ return {
510
+ status: true
511
+ }
512
+ }
513
+ }