@winible/winible-typed 1.0.9 → 2.0.0

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 (236) hide show
  1. package/dist/migrations/20230206061925-stale.js +13 -0
  2. package/dist/migrations/20230206061925-stale.js.map +1 -0
  3. package/dist/migrations/20230313175015-league-user.js +29 -0
  4. package/dist/migrations/20230313175015-league-user.js.map +1 -0
  5. package/dist/migrations/20230330174702-extend-premium-content.js +35 -0
  6. package/dist/migrations/20230330174702-extend-premium-content.js.map +1 -0
  7. package/dist/migrations/20230405141245-deprecate-agencies.js +9 -0
  8. package/dist/migrations/20230405141245-deprecate-agencies.js.map +1 -0
  9. package/dist/migrations/20230405142440-deprecate-unused-tables.js +23 -0
  10. package/dist/migrations/20230405142440-deprecate-unused-tables.js.map +1 -0
  11. package/dist/migrations/20230410144940-deprecate-consent-people.js +9 -0
  12. package/dist/migrations/20230410144940-deprecate-consent-people.js.map +1 -0
  13. package/dist/migrations/20230410174328-deprecate-consent-people-table.js +9 -0
  14. package/dist/migrations/20230410174328-deprecate-consent-people-table.js.map +1 -0
  15. package/dist/migrations/20230410181920-migrate-credit-payments-to-transactions.js +9 -0
  16. package/dist/migrations/20230410181920-migrate-credit-payments-to-transactions.js.map +1 -0
  17. package/dist/migrations/20230410202433-migrate-credit-payments-fields.js +12 -0
  18. package/dist/migrations/20230410202433-migrate-credit-payments-fields.js.map +1 -0
  19. package/dist/migrations/20230410211059-deprecate-credit-purchases.js +9 -0
  20. package/dist/migrations/20230410211059-deprecate-credit-purchases.js.map +1 -0
  21. package/dist/migrations/20230410212035-deprecate-dashboard_user_permissions.js +10 -0
  22. package/dist/migrations/20230410212035-deprecate-dashboard_user_permissions.js.map +1 -0
  23. package/dist/migrations/20230410212324-deprecate-non-breaking-tables.js +34 -0
  24. package/dist/migrations/20230410212324-deprecate-non-breaking-tables.js.map +1 -0
  25. package/dist/migrations/20230411054826-create-users-table.js +141 -0
  26. package/dist/migrations/20230411054826-create-users-table.js.map +1 -0
  27. package/dist/migrations/20230411202848-migrate_transactions_table.js +24 -0
  28. package/dist/migrations/20230411202848-migrate_transactions_table.js.map +1 -0
  29. package/dist/migrations/20230411203543-migrate_league_users.js +9 -0
  30. package/dist/migrations/20230411203543-migrate_league_users.js.map +1 -0
  31. package/dist/migrations/20230411205324-migrate_league.js +13 -0
  32. package/dist/migrations/20230411205324-migrate_league.js.map +1 -0
  33. package/dist/migrations/20230411221159-migrate_media.js +9 -0
  34. package/dist/migrations/20230411221159-migrate_media.js.map +1 -0
  35. package/dist/migrations/20230411221327-migrate_media_asset.js +10 -0
  36. package/dist/migrations/20230411221327-migrate_media_asset.js.map +1 -0
  37. package/dist/migrations/20230411221842-migrate_media_asset_fields.js +10 -0
  38. package/dist/migrations/20230411221842-migrate_media_asset_fields.js.map +1 -0
  39. package/dist/migrations/20230411222018-migrate_notifications.js +25 -0
  40. package/dist/migrations/20230411222018-migrate_notifications.js.map +1 -0
  41. package/dist/scripts/bet-syncing/findGoodBets.js +238 -0
  42. package/dist/scripts/bet-syncing/findGoodBets.js.map +1 -0
  43. package/dist/scripts/bet-syncing/pullOdds.js +21 -8
  44. package/dist/scripts/bet-syncing/pullOdds.js.map +1 -1
  45. package/dist/scripts/bet-syncing/pullPlayerResults.js +47 -21
  46. package/dist/scripts/bet-syncing/pullPlayerResults.js.map +1 -1
  47. package/dist/scripts/bet-syncing/pullPlayers.js +1 -1
  48. package/dist/scripts/bet-syncing/pullPlayers.js.map +1 -1
  49. package/dist/scripts/bet-syncing/updateStaleOdds.js +34 -0
  50. package/dist/scripts/bet-syncing/updateStaleOdds.js.map +1 -0
  51. package/dist/scripts/cleanupRecurlyPlans.js +12 -5
  52. package/dist/scripts/cleanupRecurlyPlans.js.map +1 -1
  53. package/dist/scripts/mapCurrentPaymentsToInvoiceId.js +12 -5
  54. package/dist/scripts/mapCurrentPaymentsToInvoiceId.js.map +1 -1
  55. package/dist/src/index.js +1 -18
  56. package/dist/src/index.js.map +1 -1
  57. package/dist/typed-model/credit-payment.js +133 -82
  58. package/dist/typed-model/credit-payment.js.map +1 -1
  59. package/dist/typed-model/index.js +3 -81
  60. package/dist/typed-model/index.js.map +1 -1
  61. package/dist/typed-model/league-user.js +60 -0
  62. package/dist/typed-model/league-user.js.map +1 -0
  63. package/dist/typed-model/media-asset.js +0 -9
  64. package/dist/typed-model/media-asset.js.map +1 -1
  65. package/dist/typed-model/notification.js +34 -24
  66. package/dist/typed-model/notification.js.map +1 -1
  67. package/dist/typed-model/odds.js +5 -0
  68. package/dist/typed-model/odds.js.map +1 -1
  69. package/dist/typed-model/pb-sequelize.js +18 -4
  70. package/dist/typed-model/pb-sequelize.js.map +1 -1
  71. package/dist/typed-model/subscription-plan-on-premium-content.js +57 -0
  72. package/dist/typed-model/subscription-plan-on-premium-content.js.map +1 -0
  73. package/dist/typed-model/subscription-plan.js +0 -9
  74. package/dist/typed-model/subscription-plan.js.map +1 -1
  75. package/dist/typed-model/subscription.js +0 -14
  76. package/dist/typed-model/subscription.js.map +1 -1
  77. package/dist/typed-model/user.js +194 -0
  78. package/dist/typed-model/user.js.map +1 -0
  79. package/package.json +4 -3
  80. package/src/index.ts +0 -2
  81. package/typed-model/credit-payment.ts +124 -126
  82. package/typed-model/index.ts +1 -51
  83. package/typed-model/{list-member.ts → league-user.ts} +31 -19
  84. package/typed-model/media-asset.ts +0 -10
  85. package/typed-model/notification.ts +39 -44
  86. package/typed-model/pb-sequelize.ts +18 -4
  87. package/typed-model/subscription-plan.ts +0 -10
  88. package/typed-model/subscription.ts +1 -15
  89. package/typed-model/user.ts +248 -0
  90. package/dist/index.d.ts +0 -3
  91. package/dist/migrations/20220601151258-custom_name_describing_your_migration.d.ts +0 -6
  92. package/dist/migrations/20220605225655-create-dashboard-user-permissions.d.ts +0 -6
  93. package/dist/migrations/20220606001300-update-dashboard-user-permissions.d.ts +0 -6
  94. package/dist/migrations/20220607091109-add-read-date-for-message.d.ts +0 -6
  95. package/dist/migrations/20220616225456-add-delete-columns.d.ts +0 -6
  96. package/dist/migrations/20220709202211-disable-feed.d.ts +0 -6
  97. package/dist/migrations/20220723215213-limit-promotion-claims.d.ts +0 -6
  98. package/dist/migrations/20220723220233-num_claims.d.ts +0 -6
  99. package/dist/migrations/20220723221907-default_false_promos.d.ts +0 -6
  100. package/dist/migrations/20220724172559-default_zero_claims.d.ts +0 -6
  101. package/dist/migrations/20220724201419-pinned_post.d.ts +0 -6
  102. package/dist/migrations/20220729164625-unsend_mass.d.ts +0 -6
  103. package/dist/migrations/20220823033002-interval-unit.d.ts +0 -6
  104. package/dist/migrations/20220830193530-processorId.d.ts +0 -6
  105. package/dist/migrations/20220907121932-add-processor-to-sub.d.ts +0 -6
  106. package/dist/migrations/20220907212232-add-trans-id.d.ts +0 -6
  107. package/dist/migrations/20220907220423-big-int-trans.d.ts +0 -6
  108. package/dist/migrations/20220909161902-add-stale.d.ts +0 -6
  109. package/dist/migrations/20220922000225-verified-spender.d.ts +0 -6
  110. package/dist/migrations/20220922212108-verified-spender-2.d.ts +0 -6
  111. package/dist/migrations/20221013223648-product-subscription-list.d.ts +0 -6
  112. package/dist/migrations/20221014001037-product-subscription-list.d.ts +0 -6
  113. package/dist/migrations/20221026055245-update-type.d.ts +0 -6
  114. package/dist/migrations/20221108060019-recurly-sub.d.ts +0 -6
  115. package/dist/migrations/20221110170148-rename-recurly-account.d.ts +0 -6
  116. package/dist/migrations/20221112212510-archive-promo.d.ts +0 -6
  117. package/dist/migrations/20221117044529-sub-status.d.ts +0 -6
  118. package/dist/migrations/20221122051433-default-plan.d.ts +0 -6
  119. package/dist/migrations/20221128034620-invoice-id.d.ts +0 -6
  120. package/dist/scripts/bet-syncing/pullTeams.d.ts +0 -1
  121. package/dist/scripts/cleanupRecurlyPlans.d.ts +0 -1
  122. package/dist/scripts/createDashboardLink.d.ts +0 -1
  123. package/dist/scripts/createRecurlyPlans.d.ts +0 -1
  124. package/dist/scripts/deleteMalformedImages.d.ts +0 -1
  125. package/dist/scripts/fixSaltedPasswords.js +0 -40
  126. package/dist/scripts/fixSaltedPasswords.js.map +0 -1
  127. package/dist/scripts/mapCurrentPaymentsToInvoiceId.d.ts +0 -1
  128. package/dist/scripts/payoutRecurlySubs.d.ts +0 -1
  129. package/dist/scripts/payoutSubscriptions.d.ts +0 -1
  130. package/dist/scripts/removeUnreferenceSubs.d.ts +0 -1
  131. package/dist/scripts/test.d.ts +0 -1
  132. package/dist/slack/index.d.ts +0 -1
  133. package/dist/slack/v1/bypassCreator.d.ts +0 -8
  134. package/dist/slack/v1/cancelSubscription.d.ts +0 -6
  135. package/dist/slack/v1/changeName.d.ts +0 -8
  136. package/dist/slack/v1/checkAuthSub.d.ts +0 -6
  137. package/dist/slack/v1/dashboardLink.d.ts +0 -8
  138. package/dist/slack/v1/index.d.ts +0 -7
  139. package/dist/slack/v1/refund.d.ts +0 -6
  140. package/dist/slack/v1/searchUser.d.ts +0 -6
  141. package/dist/src/index.d.ts +0 -3
  142. package/dist/src/pk-client.d.ts +0 -151
  143. package/dist/src/pk-sub.d.ts +0 -77
  144. package/dist/src/recurlyInstance.d.ts +0 -3
  145. package/dist/src/types.d.ts +0 -30
  146. package/dist/support/index.d.ts +0 -2
  147. package/dist/support/slack-client.d.ts +0 -3
  148. package/dist/support/uploadcare.d.ts +0 -14
  149. package/dist/support/utils.d.ts +0 -2
  150. package/dist/typed-model/asset-category.d.ts +0 -9
  151. package/dist/typed-model/asset-constent-person.d.ts +0 -13
  152. package/dist/typed-model/bet.d.ts +0 -12
  153. package/dist/typed-model/blocked-ip.d.ts +0 -8
  154. package/dist/typed-model/category-tag.d.ts +0 -9
  155. package/dist/typed-model/consent-person.d.ts +0 -13
  156. package/dist/typed-model/content-category-tag.d.ts +0 -9
  157. package/dist/typed-model/content-like.d.ts +0 -10
  158. package/dist/typed-model/credit-payment.d.ts +0 -34
  159. package/dist/typed-model/credit-payout.d.ts +0 -10
  160. package/dist/typed-model/credit-purchase.d.ts +0 -10
  161. package/dist/typed-model/customer-profile.d.ts +0 -17
  162. package/dist/typed-model/dashboard-user-permissions.d.ts +0 -9
  163. package/dist/typed-model/dashboard-user.d.ts +0 -20
  164. package/dist/typed-model/fan-list.d.ts +0 -10
  165. package/dist/typed-model/fraud.d.ts +0 -9
  166. package/dist/typed-model/game.d.ts +0 -56
  167. package/dist/typed-model/index.d.ts +0 -46
  168. package/dist/typed-model/league.d.ts +0 -9
  169. package/dist/typed-model/list-member.d.ts +0 -9
  170. package/dist/typed-model/mass-message.d.ts +0 -11
  171. package/dist/typed-model/media-asset.d.ts +0 -15
  172. package/dist/typed-model/media-category.d.ts +0 -10
  173. package/dist/typed-model/media.d.ts +0 -14
  174. package/dist/typed-model/message-media.d.ts +0 -9
  175. package/dist/typed-model/message.d.ts +0 -27
  176. package/dist/typed-model/notification.d.ts +0 -18
  177. package/dist/typed-model/odds.d.ts +0 -30
  178. package/dist/typed-model/parlay.d.ts +0 -8
  179. package/dist/typed-model/pb-sequelize.d.ts +0 -3
  180. package/dist/typed-model/phone-chat-participation.d.ts +0 -20
  181. package/dist/typed-model/phone-chat.d.ts +0 -16
  182. package/dist/typed-model/phone-owner.d.ts +0 -53
  183. package/dist/typed-model/phone-user.d.ts +0 -21
  184. package/dist/typed-model/player.d.ts +0 -22
  185. package/dist/typed-model/premium-content.d.ts +0 -23
  186. package/dist/typed-model/purchased-content.d.ts +0 -11
  187. package/dist/typed-model/recurly-account.d.ts +0 -9
  188. package/dist/typed-model/short-url.d.ts +0 -12
  189. package/dist/typed-model/subscription-bundle.d.ts +0 -12
  190. package/dist/typed-model/subscription-category-tags.d.ts +0 -9
  191. package/dist/typed-model/subscription-plan.d.ts +0 -27
  192. package/dist/typed-model/subscription-promotion.d.ts +0 -19
  193. package/dist/typed-model/subscription.d.ts +0 -26
  194. package/dist/typed-model/team.d.ts +0 -16
  195. package/dist/typed-model/twilio-phone.d.ts +0 -17
  196. package/dist/typed-model/user-follow.d.ts +0 -13
  197. package/dist/typed-model/verification-code.d.ts +0 -11
  198. package/dist/webhooks/index.d.ts +0 -1
  199. package/dist/webhooks/payment/index.d.ts +0 -1
  200. package/dist/webhooks/payment/refund.d.ts +0 -2
  201. package/src/pk-client.ts +0 -1650
  202. package/src/pk-sub.ts +0 -455
  203. package/typed-model/asset-category.ts +0 -57
  204. package/typed-model/asset-constent-person.ts +0 -82
  205. package/typed-model/bet.ts +0 -84
  206. package/typed-model/blocked-ip.ts +0 -52
  207. package/typed-model/category-tag.ts +0 -66
  208. package/typed-model/consent-person.ts +0 -78
  209. package/typed-model/content-category-tag.ts +0 -79
  210. package/typed-model/credit-purchase.ts +0 -67
  211. package/typed-model/customer-profile.ts +0 -71
  212. package/typed-model/dashboard-user-permissions.ts +0 -51
  213. package/typed-model/dashboard-user.ts +0 -146
  214. package/typed-model/fan-list.ts +0 -68
  215. package/typed-model/fraud.ts +0 -62
  216. package/typed-model/game.ts +0 -311
  217. package/typed-model/market.ts +0 -54
  218. package/typed-model/mass-message.ts +0 -64
  219. package/typed-model/media-category.ts +0 -70
  220. package/typed-model/message-media.ts +0 -74
  221. package/typed-model/message.ts +0 -258
  222. package/typed-model/odds.ts +0 -232
  223. package/typed-model/parlay.ts +0 -47
  224. package/typed-model/phone-chat-participation.ts +0 -166
  225. package/typed-model/phone-chat.ts +0 -185
  226. package/typed-model/player-result.ts +0 -93
  227. package/typed-model/player.ts +0 -118
  228. package/typed-model/short-url.ts +0 -120
  229. package/typed-model/sportsbook.ts +0 -48
  230. package/typed-model/subscription-bundle.ts +0 -80
  231. package/typed-model/subscription-category-tags.ts +0 -79
  232. package/typed-model/subscription-promotion.ts +0 -134
  233. package/typed-model/team.ts +0 -91
  234. package/typed-model/twilio-phone.ts +0 -149
  235. package/typed-model/user-follow.ts +0 -141
  236. package/typed-model/verification-code.ts +0 -74
@@ -13,10 +13,9 @@ import sequelize from "./pb-sequelize";
13
13
  import PhoneOwner from "./phone-owner";
14
14
  import PhoneUser from "./phone-user";
15
15
  import PremiumContent from "./premium-content";
16
- import Message from "./message";
17
16
  import Subscription from "./subscription";
18
17
  import PurchasedContent from "./purchased-content";
19
- import Notification from "./notification";
18
+ import Notification, { NotificationType } from "./notification";
20
19
 
21
20
  type InteractionType =
22
21
  | "subscription"
@@ -94,7 +93,6 @@ class CreditPayments extends Model<
94
93
  static logUnlockMessage: (
95
94
  user: PhoneUser,
96
95
  owner: PhoneOwner,
97
- message: Message,
98
96
  alreadyPaid?: boolean,
99
97
  transaction?: Transaction,
100
98
  invoiceId?: string
@@ -247,11 +245,11 @@ CreditPayments.logContentPurchase = async (
247
245
  try {
248
246
  await Notification.create(
249
247
  {
250
- ownerId: content.ownerId,
251
- userId: user.id,
252
- creditPaymentId: creditPayment.id,
253
- type: "content",
254
- purchasedContentId: purchasedContent.id,
248
+ recipientId: user.id,
249
+ senderId: content.ownerId,
250
+ transactionId: creditPayment.id,
251
+ type: NotificationType.PURCHASED_POST,
252
+ purchasedPostId: purchasedContent.id,
255
253
  },
256
254
  { transaction }
257
255
  );
@@ -280,57 +278,57 @@ CreditPayments.logContentPurchase = async (
280
278
  return creditPayment;
281
279
  };
282
280
 
283
- CreditPayments.logTip = async (
284
- user: PhoneUser,
285
- owner: PhoneOwner,
286
- tipAmountInCents: number
287
- ) => {
288
- if (tipAmountInCents > user.creditsInCents!) {
289
- let url = await getPaymentUrl(user, owner);
290
- throw new Error(
291
- `Sorry, it looks like you've run out of credits. To send a tip, add more credits here: ${url}`
292
- );
293
- }
294
-
295
- if (tipAmountInCents < 0) {
296
- throw new Error("Cannot be less than 0");
297
- }
298
-
299
- user.creditsInCents = user.creditsInCents! - tipAmountInCents;
300
- await user.save();
301
-
302
- let creditPayment = await CreditPayments.create({
303
- userId: user.id,
304
- ownerId: owner.id,
305
- creditAmountInCents: tipAmountInCents,
306
- earningAmountInCents: earningsAmount(
307
- tipAmountInCents,
308
- owner.serviceFeePercentage
309
- ),
310
- interactionType: INTERACTION_TYPES.TIP,
311
- });
312
-
313
- if (owner.referringOwnerId) {
314
- await createReferralPayment(owner, creditPayment, tipAmountInCents);
315
- }
316
-
317
- if (user.referringOwnerId) {
318
- await createUserReferralPayment(user, creditPayment, tipAmountInCents);
319
- }
320
-
321
- try {
322
- await Notification.create({
323
- ownerId: owner.id,
324
- userId: user.id,
325
- creditPaymentId: creditPayment.id,
326
- type: "tip",
327
- });
328
- } catch (err) {
329
- console.log(err);
330
- }
331
-
332
- return creditPayment;
333
- };
281
+ // CreditPayments.logTip = async (
282
+ // user: PhoneUser,
283
+ // owner: PhoneOwner,
284
+ // tipAmountInCents: number
285
+ // ) => {
286
+ // if (tipAmountInCents > user.creditsInCents!) {
287
+ // let url = await getPaymentUrl(user, owner);
288
+ // throw new Error(
289
+ // `Sorry, it looks like you've run out of credits. To send a tip, add more credits here: ${url}`
290
+ // );
291
+ // }
292
+
293
+ // if (tipAmountInCents < 0) {
294
+ // throw new Error("Cannot be less than 0");
295
+ // }
296
+
297
+ // user.creditsInCents = user.creditsInCents! - tipAmountInCents;
298
+ // await user.save();
299
+
300
+ // let creditPayment = await CreditPayments.create({
301
+ // userId: user.id,
302
+ // ownerId: owner.id,
303
+ // creditAmountInCents: tipAmountInCents,
304
+ // earningAmountInCents: earningsAmount(
305
+ // tipAmountInCents,
306
+ // owner.serviceFeePercentage
307
+ // ),
308
+ // interactionType: INTERACTION_TYPES.TIP,
309
+ // });
310
+
311
+ // if (owner.referringOwnerId) {
312
+ // await createReferralPayment(owner, creditPayment, tipAmountInCents);
313
+ // }
314
+
315
+ // if (user.referringOwnerId) {
316
+ // await createUserReferralPayment(user, creditPayment, tipAmountInCents);
317
+ // }
318
+
319
+ // try {
320
+ // await Notification.create({
321
+ // ownerId: owner.id,
322
+ // userId: user.id,
323
+ // creditPaymentId: creditPayment.id,
324
+ // type: "tip",
325
+ // });
326
+ // } catch (err) {
327
+ // console.log(err);
328
+ // }
329
+
330
+ // return creditPayment;
331
+ // };
334
332
 
335
333
  CreditPayments.logMessage = async (
336
334
  user: PhoneUser,
@@ -438,72 +436,72 @@ CreditPayments.logVideoCall = async (
438
436
  return creditPayment;
439
437
  };
440
438
 
441
- CreditPayments.logUnlockMessage = async (
442
- user: PhoneUser,
443
- owner: PhoneOwner,
444
- message: Message,
445
- alreadyPaid?: boolean,
446
- transaction?: Transaction,
447
- invoiceId?: string
448
- ) => {
449
- if (message.amountInCents! > user.creditsInCents! && !alreadyPaid) {
450
- throw new Error(`Sorry, it looks like you've run out of credits`);
451
- }
452
-
453
- if (!message.amountInCents) {
454
- throw new Error("Must contain message amount");
455
- }
456
-
457
- if (message.amountInCents! < 0) {
458
- throw new Error("Cannot be less than 0");
459
- }
460
-
461
- if (!alreadyPaid) {
462
- user.creditsInCents = user.creditsInCents! - message.amountInCents!;
463
- await user.save({ transaction });
464
- }
465
-
466
- let creditPayment = await CreditPayments.create(
467
- {
468
- userId: user.id,
469
- ownerId: owner.id,
470
- creditAmountInCents: message.amountInCents!,
471
- earningAmountInCents: earningsAmount(
472
- message.amountInCents!,
473
- owner.serviceFeePercentage
474
- ),
475
- invoiceId,
476
- interactionType: INTERACTION_TYPES.UNLOCK_MESSAGE,
477
- },
478
- { transaction }
479
- );
480
-
481
- try {
482
- await Notification.create(
483
- {
484
- ownerId: owner.id,
485
- userId: user.id,
486
- creditPaymentId: creditPayment.id,
487
- type: "unlock_message",
488
- messageId: message.id,
489
- },
490
- { transaction }
491
- );
492
- } catch (err) {
493
- console.log(err);
494
- }
495
-
496
- if (owner.referringOwnerId) {
497
- await createReferralPayment(
498
- owner,
499
- creditPayment,
500
- message.amountInCents!,
501
- transaction
502
- );
503
- }
504
-
505
- return creditPayment;
506
- };
439
+ // CreditPayments.logUnlockMessage = async (
440
+ // user: PhoneUser,
441
+ // owner: PhoneOwner,
442
+ // message: Message,
443
+ // alreadyPaid?: boolean,
444
+ // transaction?: Transaction,
445
+ // invoiceId?: string
446
+ // ) => {
447
+ // if (message.amountInCents! > user.creditsInCents! && !alreadyPaid) {
448
+ // throw new Error(`Sorry, it looks like you've run out of credits`);
449
+ // }
450
+
451
+ // if (!message.amountInCents) {
452
+ // throw new Error("Must contain message amount");
453
+ // }
454
+
455
+ // if (message.amountInCents! < 0) {
456
+ // throw new Error("Cannot be less than 0");
457
+ // }
458
+
459
+ // if (!alreadyPaid) {
460
+ // user.creditsInCents = user.creditsInCents! - message.amountInCents!;
461
+ // await user.save({ transaction });
462
+ // }
463
+
464
+ // let creditPayment = await CreditPayments.create(
465
+ // {
466
+ // userId: user.id,
467
+ // ownerId: owner.id,
468
+ // creditAmountInCents: message.amountInCents!,
469
+ // earningAmountInCents: earningsAmount(
470
+ // message.amountInCents!,
471
+ // owner.serviceFeePercentage
472
+ // ),
473
+ // invoiceId,
474
+ // interactionType: INTERACTION_TYPES.UNLOCK_MESSAGE,
475
+ // },
476
+ // { transaction }
477
+ // );
478
+
479
+ // try {
480
+ // await Notification.create(
481
+ // {
482
+ // ownerId: owner.id,
483
+ // userId: user.id,
484
+ // creditPaymentId: creditPayment.id,
485
+ // type: "unlock_message",
486
+ // messageId: message.id,
487
+ // },
488
+ // { transaction }
489
+ // );
490
+ // } catch (err) {
491
+ // console.log(err);
492
+ // }
493
+
494
+ // if (owner.referringOwnerId) {
495
+ // await createReferralPayment(
496
+ // owner,
497
+ // creditPayment,
498
+ // message.amountInCents!,
499
+ // transaction
500
+ // );
501
+ // }
502
+
503
+ // return creditPayment;
504
+ // };
507
505
 
508
506
  CreditPayments.logUnlockedContent = async (
509
507
  user: PhoneUser,
@@ -675,7 +673,7 @@ CreditPayments.hasOne(PhoneUser, {
675
673
  });
676
674
  Notification.hasOne(CreditPayments, {
677
675
  foreignKey: "id",
678
- sourceKey: "creditPaymentId",
676
+ sourceKey: "transactionId",
679
677
  constraints: false,
680
678
  onDelete: "NO ACTION",
681
679
  });
@@ -1,66 +1,16 @@
1
- // let models = {
2
- // DashboardUserPermissions: require("./dashboard-user-permissions"),
3
- // PhoneUser: require("./phone-user"),
4
- // PhoneOwner: require("./phone-owner"),
5
- // DashboardUser: require("./dashboard-user"),
6
- // };
7
-
8
- // export sequelize from "./pb-sequelize";
9
-
10
- // const sync = async () => {
11
- // console.log("Syncing type models...");
12
- // await sequelize.sync({ alter: true });
13
- // console.log("Sync done");
14
- // };
15
-
16
- // if (process.env.SYNC_TABLES) {
17
- // sync();
18
- // }
19
-
20
- export { default as AssetCategory } from "./asset-category";
21
- export { default as AssetConsentPerson } from "./asset-constent-person";
22
- export { default as PhoneChat } from "./phone-chat";
23
- export { default as PhoneChatParticipant } from "./phone-chat-participation";
24
- export { default as ConsentPerson } from "./consent-person";
25
1
  export { default as ContentLike } from "./content-like";
26
2
  export { default as CreditPayments } from "./credit-payment";
27
- export { default as CreditPurchase } from "./credit-purchase";
28
- export { default as BlockedIP } from "./blocked-ip";
29
- export { default as CustomerProfile, ProcessorId } from "./customer-profile";
30
- export { default as DashboardUserPermissions } from "./dashboard-user-permissions";
31
- export { default as DashboardUser } from "./dashboard-user";
32
- export { default as FanList } from "./fan-list";
33
- export { default as Fraud } from "./fraud";
34
- export { default as ListMember } from "./list-member";
35
- export { default as MassMessage } from "./mass-message";
36
3
  export { default as MediaAsset } from "./media-asset";
37
- export { default as MediaCategory } from "./media-category";
38
4
  export { default as Media } from "./media";
39
- export { default as MessageMedia } from "./message-media";
40
- export { default as Message } from "./message";
41
5
  export { default as Notification } from "./notification";
42
6
  export { default as pbSequelize } from "./pb-sequelize";
43
7
  export { default as PhoneOwner } from "./phone-owner";
44
8
  export { default as PhoneUser } from "./phone-user";
45
9
  export { default as PremiumContent } from "./premium-content";
46
10
  export { default as PurchasedContent } from "./purchased-content";
47
- export { default as SubscriptionBundle } from "./subscription-bundle";
48
11
  export { default as SubscriptionPlan } from "./subscription-plan";
49
- export { default as SubscriptionPromotion } from "./subscription-promotion";
50
12
  export { default as Subscription } from "./subscription";
51
- export { default as UserFollow } from "./user-follow";
52
- export { default as TwilioPhone } from "./twilio-phone";
53
13
  export { default as RecurlyAccount } from "./recurly-account";
54
- export { default as ShortUrl } from "./short-url";
55
14
  export { default as CreditPayout } from "./credit-payout";
56
- export { default as VerificationCode } from "./verification-code";
57
- export { default as CategoryTag } from "./category-tag";
58
- export { default as SubscriptionCategoryTag } from "./subscription-category-tags";
59
- export { default as ContentCategoryTag } from "./content-category-tag";
60
- export { default as Team } from "./team";
61
15
  export { default as League } from "./league";
62
- export { default as Game } from "./game";
63
- export { default as Odds } from "./odds";
64
- export { default as Bet } from "./bet";
65
- export { default as Parlay } from "./parlay";
66
- export { default as Player } from "./player";
16
+ export { default as User } from "./user";
@@ -4,27 +4,27 @@ import {
4
4
  InferCreationAttributes,
5
5
  CreationOptional,
6
6
  DataTypes,
7
- fn,
8
7
  } from "sequelize";
8
+ import League from "./league";
9
9
 
10
10
  import sequelize from "./pb-sequelize";
11
11
  import PhoneUser from "./phone-user";
12
12
 
13
13
  // order of InferAttributes & InferCreationAttributes is important.
14
- class ListMember extends Model<
15
- InferAttributes<ListMember>,
16
- InferCreationAttributes<ListMember>
14
+ class LeagueUser extends Model<
15
+ InferAttributes<LeagueUser>,
16
+ InferCreationAttributes<LeagueUser>
17
17
  > {
18
18
  // 'CreationOptional' is a special type that marks the field as optional
19
19
  // when creating an instance of the model (such as using Model.create()).
20
20
  declare id: CreationOptional<string>;
21
+ declare leagueId: string;
21
22
  declare userId: string;
22
- declare fanListId: string;
23
23
  declare createdAt: CreationOptional<Date>;
24
24
  declare updatedAt: CreationOptional<Date>;
25
25
  }
26
26
 
27
- ListMember.init(
27
+ LeagueUser.init(
28
28
  {
29
29
  id: {
30
30
  type: DataTypes.BIGINT,
@@ -32,36 +32,48 @@ ListMember.init(
32
32
  allowNull: false,
33
33
  defaultValue: sequelize.fn("next_id"),
34
34
  },
35
- userId: {
35
+ leagueId: {
36
36
  type: DataTypes.BIGINT,
37
- field: "user_id",
37
+ field: "league_id",
38
+ allowNull: false,
38
39
  },
39
- fanListId: {
40
+ userId: {
40
41
  type: DataTypes.BIGINT,
41
- field: "fan_list_id",
42
+ field: "user_id",
43
+ allowNull: false,
42
44
  },
43
45
  createdAt: DataTypes.DATE,
44
46
  updatedAt: DataTypes.DATE,
45
47
  },
46
- { tableName: "list_members", sequelize }
48
+ {
49
+ // Other model options go here
50
+ tableName: "league_users",
51
+ sequelize,
52
+ }
47
53
  );
48
54
 
49
- /*
50
- ====================================================================
51
- Class functions
52
- ====================================================================
53
- */
55
+ LeagueUser.hasOne(League, {
56
+ foreignKey: "id",
57
+ sourceKey: "leagueId",
58
+ onDelete: "NO ACTION",
59
+ constraints: false,
60
+ });
61
+ League.hasMany(LeagueUser, {
62
+ foreignKey: "leagueId",
63
+ onDelete: "NO ACTION",
64
+ constraints: false,
65
+ });
54
66
 
55
- ListMember.hasOne(PhoneUser, {
67
+ LeagueUser.hasOne(PhoneUser, {
56
68
  foreignKey: "id",
57
69
  sourceKey: "userId",
58
70
  onDelete: "NO ACTION",
59
71
  constraints: false,
60
72
  });
61
- PhoneUser.hasMany(ListMember, {
73
+ PhoneUser.hasMany(LeagueUser, {
62
74
  foreignKey: "userId",
63
75
  onDelete: "NO ACTION",
64
76
  constraints: false,
65
77
  });
66
78
 
67
- export default ListMember;
79
+ export default LeagueUser;
@@ -8,7 +8,6 @@ import {
8
8
  } from "sequelize";
9
9
 
10
10
  import sequelize from "./pb-sequelize";
11
- import AssetCategory from "./asset-category";
12
11
 
13
12
  // order of InferAttributes & InferCreationAttributes is important.
14
13
  class MediaAsset extends Model<
@@ -87,13 +86,4 @@ Class functions
87
86
  ====================================================================
88
87
  */
89
88
 
90
- AssetCategory.hasOne(MediaAsset, {
91
- foreignKey: "id",
92
- sourceKey: "mediaAssetId",
93
- });
94
- MediaAsset.hasMany(AssetCategory, {
95
- foreignKey: "media_asset_id",
96
- sourceKey: "id",
97
- });
98
-
99
89
  export default MediaAsset;
@@ -5,20 +5,19 @@ import {
5
5
  CreationOptional,
6
6
  DataTypes,
7
7
  fn,
8
- NOW,
9
8
  } from "sequelize";
10
9
 
11
10
  import sequelize from "./pb-sequelize";
12
- import PhoneUser from "./phone-user";
13
11
  import ContentLike from "./content-like";
12
+ import User from "./user";
14
13
 
15
- type NotificationType =
16
- | "unlock_message"
17
- | "follow"
18
- | "like"
19
- | "tip"
20
- | "subscription"
21
- | "content";
14
+ export enum NotificationType {
15
+ VIEWED = "VIEWED",
16
+ PURCHASED_PLAN = "PURCHASED_PLAN",
17
+ PURCHASED_POST = "PURCHASED_POST",
18
+ SUBSCRIBED = "SUBSCRIBED",
19
+ VIEWED_PROFILE = "VIEWED_PROFILE",
20
+ }
22
21
 
23
22
  // order of InferAttributes & InferCreationAttributes is important.
24
23
  class Notification extends Model<
@@ -28,15 +27,14 @@ class Notification extends Model<
28
27
  // 'CreationOptional' is a special type that marks the field as optional
29
28
  // when creating an instance of the model (such as using Model.create()).
30
29
  declare id: CreationOptional<string>;
31
- declare ownerId: string;
32
- declare userId?: string;
30
+ declare recipientId: string;
31
+ declare senderId?: string;
33
32
  declare isRead?: boolean;
34
33
  declare type: NotificationType;
35
- declare creditPaymentId?: string;
36
- declare purchasedContentId?: string;
37
- declare userFollowId?: string;
38
- declare contentLikeId?: string;
39
- declare messageId?: string;
34
+ declare transactionId?: string;
35
+ declare purchasedPostId?: string;
36
+ declare postLikeId?: string;
37
+ declare subscriptionPlanId?: string;
40
38
  declare createdAt: CreationOptional<Date>;
41
39
  declare updatedAt: CreationOptional<Date>;
42
40
  static readNotifications: (
@@ -53,14 +51,14 @@ Notification.init(
53
51
  allowNull: false,
54
52
  primaryKey: true,
55
53
  },
56
- ownerId: {
54
+ recipientId: {
57
55
  type: DataTypes.BIGINT,
58
- field: "owner_id",
56
+ field: "recipient_id",
59
57
  allowNull: false,
60
58
  },
61
- userId: {
59
+ senderId: {
62
60
  type: DataTypes.BIGINT,
63
- field: "user_id",
61
+ field: "sender_id",
64
62
  allowNull: false,
65
63
  },
66
64
  isRead: {
@@ -70,26 +68,22 @@ Notification.init(
70
68
  },
71
69
  type: {
72
70
  field: "type",
73
- type: DataTypes.STRING,
74
- },
75
- creditPaymentId: {
76
- field: "credit_payment_id",
77
- type: DataTypes.BIGINT,
71
+ type: DataTypes.ENUM(...Object.values(NotificationType)),
78
72
  },
79
- purchasedContentId: {
80
- field: "purchased_content_id",
73
+ transactionId: {
74
+ field: "transaction_id",
81
75
  type: DataTypes.BIGINT,
82
76
  },
83
- userFollowId: {
84
- field: "user_follow_id",
77
+ purchasedPostId: {
78
+ field: "purchased_post_id",
85
79
  type: DataTypes.BIGINT,
86
80
  },
87
- contentLikeId: {
88
- field: "content_like_id",
81
+ postLikeId: {
82
+ field: "post_like_id",
89
83
  type: DataTypes.BIGINT,
90
84
  },
91
- messageId: {
92
- field: "messageId",
85
+ subscriptionPlanId: {
86
+ field: "subscription_plan_id",
93
87
  type: DataTypes.BIGINT,
94
88
  },
95
89
  createdAt: DataTypes.DATE,
@@ -107,23 +101,24 @@ Class functions
107
101
  ====================================================================
108
102
  */
109
103
 
110
- Notification.readNotifications = async (
111
- ownerId: string,
112
- type: NotificationType
113
- ) => {
114
- await sequelize.query(
115
- `UPDATE notifications SET is_read=true WHERE owner_id=${ownerId} AND type=${type}`
116
- );
117
- };
104
+ // Notification.readNotifications = async (
105
+ // ownerId: string,
106
+ // type: NotificationType
107
+ // ) => {
108
+ // await sequelize.query(
109
+ // `UPDATE notifications SET is_read=true WHERE owner_id=${ownerId} AND type=${type}`
110
+ // );
111
+ // };
118
112
 
119
- Notification.hasOne(PhoneUser, {
113
+ Notification.hasOne(User, {
120
114
  foreignKey: "id",
121
- sourceKey: "userId",
115
+ sourceKey: "recipientId",
122
116
  constraints: false,
123
117
  });
118
+
124
119
  Notification.hasOne(ContentLike, {
125
120
  foreignKey: "id",
126
- sourceKey: "contentLikeId",
121
+ sourceKey: "postLikeId",
127
122
  constraints: false,
128
123
  });
129
124
 
@@ -13,13 +13,27 @@ const dbUrl =
13
13
  process.env.ENVIRONMENT === "test"
14
14
  ? process.env.TESTING_DATABASE_URL
15
15
  : process.env.DATABASE_URL;
16
- export default new Sequelize(dbUrl!, {
17
- logging: false,
18
- minifyAliases: true,
16
+ // export default new Sequelize(dbUrl!, {
17
+ // logging: false,
18
+ // minifyAliases: true,
19
+ // dialectOptions: {
20
+ // ssl: {
21
+ // require: true,
22
+ // rejectUnauthorized: false, // <<<<<<< YOU NEED THIS
23
+ // },
24
+ // },
25
+ // });
26
+ export default new Sequelize({
27
+ username: "postgres",
28
+ password: "l5WFq6a50%m4",
29
+ database: "winible",
30
+ host: "winible-v2-staging.cd9ez5rrajpu.us-east-1.rds.amazonaws.com",
31
+ dialect: "postgres",
32
+ ssl: false,
19
33
  dialectOptions: {
20
34
  ssl: {
21
35
  require: true,
22
- rejectUnauthorized: false, // <<<<<<< YOU NEED THIS
36
+ rejectUnauthorized: false,
23
37
  },
24
38
  },
25
39
  });
@@ -12,7 +12,6 @@ import {
12
12
  import sequelize from "./pb-sequelize";
13
13
  import PhoneOwner from "./phone-owner";
14
14
  import Subscription from "./subscription";
15
- import SubscriptionPromotion from "./subscription-promotion";
16
15
 
17
16
  // order of InferAttributes & InferCreationAttributes is important.
18
17
  class SubscriptionPlan extends Model<
@@ -170,13 +169,4 @@ PhoneOwner.hasMany(SubscriptionPlan, {
170
169
  constraints: false,
171
170
  });
172
171
 
173
- SubscriptionPromotion.hasOne(SubscriptionPlan, {
174
- foreignKey: "id",
175
- sourceKey: "subscriptionPlanId",
176
- });
177
- SubscriptionPlan.hasMany(SubscriptionPromotion, {
178
- foreignKey: "subscription_plan_id",
179
- sourceKey: "id",
180
- });
181
-
182
172
  export default SubscriptionPlan;