@winible/winible-typed 2.35.2 → 2.35.3

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 (174) hide show
  1. package/README.md +9 -9
  2. package/dist/index.js +19 -19
  3. package/dist/migrations/20230104055346-oddsjam.js +500 -500
  4. package/dist/migrations/20230104233909-markets.js +27 -27
  5. package/dist/migrations/20230105005418-sportsbook.js +23 -23
  6. package/dist/migrations/20230106044910-player-result.js +58 -58
  7. package/dist/migrations/20230206061925-stale.js +12 -12
  8. package/dist/migrations/20230313175015-league-user.js +28 -28
  9. package/dist/migrations/20230405141245-deprecate-agencies.js +8 -8
  10. package/dist/migrations/20230405142440-deprecate-unused-tables.js +22 -22
  11. package/dist/migrations/20230410144940-deprecate-consent-people.js +8 -8
  12. package/dist/migrations/20230410174328-deprecate-consent-people-table.js +8 -8
  13. package/dist/migrations/20230410181920-migrate-credit-payments-to-transactions.js +8 -8
  14. package/dist/migrations/20230410202433-migrate-credit-payments-fields.js +11 -11
  15. package/dist/migrations/20230410211059-deprecate-credit-purchases.js +8 -8
  16. package/dist/migrations/20230410212035-deprecate-dashboard_user_permissions.js +9 -9
  17. package/dist/migrations/20230410212324-deprecate-non-breaking-tables.js +33 -33
  18. package/dist/migrations/20230411054826-create-users-table.js +140 -140
  19. package/dist/migrations/20230411202848-migrate_transactions_table.js +23 -23
  20. package/dist/migrations/20230411203543-migrate_league_users.js +8 -8
  21. package/dist/migrations/20230411205324-migrate_league.js +12 -12
  22. package/dist/migrations/20230411221159-migrate_media.js +8 -8
  23. package/dist/migrations/20230411221327-migrate_media_asset.js +9 -9
  24. package/dist/migrations/20230411221842-migrate_media_asset_fields.js +9 -9
  25. package/dist/migrations/20230411222018-migrate_notifications.js +24 -24
  26. package/dist/migrations/20230412190423-migrate_purchased_contents.js +9 -9
  27. package/dist/migrations/20230412202031-migrate_other_fields.js +26 -26
  28. package/dist/migrations/20230412213952-deprecate_phone_users_and_phone_owners.js +26 -26
  29. package/dist/migrations/20241123184623-whitelist.js +36 -36
  30. package/dist/migrations/20241204220824-pumping-risk-score-monitoring-table.js +47 -47
  31. package/dist/migrations/20241205003230-failed-transactions.js +67 -67
  32. package/dist/migrations/20241216145328-password-tokens.js +34 -0
  33. package/dist/migrations/20241216145328-password-tokens.js.map +1 -0
  34. package/dist/scripts/cleanupRecurlyPlans.js +49 -49
  35. package/dist/scripts/deleteMalformedImages.js +86 -86
  36. package/dist/scripts/test.js +17 -17
  37. package/dist/src/index.js +8 -8
  38. package/dist/src/recurlyInstance.js +32 -32
  39. package/dist/src/types.js +60 -60
  40. package/dist/support/index.js +18 -18
  41. package/dist/support/slack-client.js +50 -50
  42. package/dist/support/uploadcare.js +142 -142
  43. package/dist/support/utils.js +68 -68
  44. package/dist/typed-model/affiliate-code.js +97 -97
  45. package/dist/typed-model/affiliate-links-types.js +28 -28
  46. package/dist/typed-model/application.js +89 -89
  47. package/dist/typed-model/bet.js +111 -111
  48. package/dist/typed-model/cancellation_offer.js +70 -70
  49. package/dist/typed-model/cancellation_reason.js +98 -98
  50. package/dist/typed-model/content-like.js +69 -69
  51. package/dist/typed-model/discord-integration-log.js +62 -62
  52. package/dist/typed-model/discord-integration.js +128 -128
  53. package/dist/typed-model/failed-transactions.js +95 -95
  54. package/dist/typed-model/featured-creator.js +51 -51
  55. package/dist/typed-model/free-subscription-plan.js +66 -66
  56. package/dist/typed-model/index.js +119 -117
  57. package/dist/typed-model/index.js.map +1 -1
  58. package/dist/typed-model/integration.js +58 -58
  59. package/dist/typed-model/league-on-users.js +59 -59
  60. package/dist/typed-model/league.js +34 -34
  61. package/dist/typed-model/limited-offer.js +58 -58
  62. package/dist/typed-model/media-asset.js +63 -63
  63. package/dist/typed-model/media.js +54 -54
  64. package/dist/typed-model/migration-token.js +52 -52
  65. package/dist/typed-model/notification-preference.js +58 -58
  66. package/dist/typed-model/notification.js +89 -89
  67. package/dist/typed-model/organization.js +57 -57
  68. package/dist/typed-model/{featured-capper.js → password-tokens.js} +37 -51
  69. package/dist/typed-model/password-tokens.js.map +1 -0
  70. package/dist/typed-model/pb-sequelize.js +43 -43
  71. package/dist/typed-model/permission.js +36 -36
  72. package/dist/typed-model/post.js +128 -128
  73. package/dist/typed-model/post_on_integrations.js +81 -81
  74. package/dist/typed-model/posts-on-users.js +92 -92
  75. package/dist/typed-model/private-feed-users.js +42 -42
  76. package/dist/typed-model/pumping-risk-score-monitoring.js +54 -54
  77. package/dist/typed-model/recurly-account.js +33 -33
  78. package/dist/typed-model/sample.js +24 -24
  79. package/dist/typed-model/sms-custom-message.js +46 -46
  80. package/dist/typed-model/sport-on-posts.js +58 -58
  81. package/dist/typed-model/sport.js +29 -29
  82. package/dist/typed-model/store.js +148 -148
  83. package/dist/typed-model/stores_on_organizations.js +55 -55
  84. package/dist/typed-model/subscriber-discord-integration.js +82 -82
  85. package/dist/typed-model/subscriber-telegram-integration.js +82 -82
  86. package/dist/typed-model/subscribers-on-creators.js +80 -80
  87. package/dist/typed-model/subscription-coupon.js +92 -92
  88. package/dist/typed-model/subscription-plan-on-post.js +54 -54
  89. package/dist/typed-model/subscription-plan-on-users.js +138 -138
  90. package/dist/typed-model/subscription-plan.js +116 -116
  91. package/dist/typed-model/subscription-pricing-option-on-coupons.js +54 -54
  92. package/dist/typed-model/subscription-pricing-option.js +77 -77
  93. package/dist/typed-model/telegram-integration-code.js +38 -38
  94. package/dist/typed-model/telegram-integration-invite-link.js +38 -38
  95. package/dist/typed-model/telegram-integration-log.js +62 -62
  96. package/dist/typed-model/telegram-integration.js +109 -109
  97. package/dist/typed-model/transaction.js +109 -109
  98. package/dist/typed-model/user.js +210 -210
  99. package/dist/typed-model/users-on-permissions.js +71 -71
  100. package/dist/typed-model/users_on_creators.js +70 -70
  101. package/dist/typed-model/users_on_organizations.js +55 -55
  102. package/dist/typed-model/whitelist.js +48 -48
  103. package/dist/typed-model/withdrawal.js +32 -32
  104. package/dist/webhooks/index.js +47 -47
  105. package/dist/webhooks/payment/index.js +8 -8
  106. package/dist/webhooks/payment/refund.js +38 -38
  107. package/index.ts +3 -3
  108. package/package.json +78 -78
  109. package/src/index.ts +1 -1
  110. package/src/recurlyInstance.ts +6 -6
  111. package/src/types.ts +97 -97
  112. package/support/index.ts +2 -2
  113. package/support/slack-client.ts +43 -43
  114. package/support/uploadcare.ts +191 -191
  115. package/support/utils.ts +72 -72
  116. package/typed-model/affiliate-code.ts +133 -133
  117. package/typed-model/affiliate-links-types.ts +45 -45
  118. package/typed-model/application.ts +124 -124
  119. package/typed-model/bet.ts +149 -149
  120. package/typed-model/cancellation_offer.ts +94 -94
  121. package/typed-model/cancellation_reason.ts +135 -135
  122. package/typed-model/content-like.ts +95 -95
  123. package/typed-model/discord-integration-log.ts +87 -87
  124. package/typed-model/discord-integration.ts +164 -164
  125. package/typed-model/failed-transactions.ts +123 -123
  126. package/typed-model/featured-creator.ts +75 -75
  127. package/typed-model/free-subscription-plan.ts +97 -97
  128. package/typed-model/index.ts +56 -55
  129. package/typed-model/integration.ts +83 -83
  130. package/typed-model/league-on-users.ts +81 -81
  131. package/typed-model/league.ts +53 -53
  132. package/typed-model/limited-offer.ts +80 -80
  133. package/typed-model/media-asset.ts +87 -87
  134. package/typed-model/media.ts +80 -80
  135. package/typed-model/migration-token.ts +75 -75
  136. package/typed-model/notification-preference.ts +85 -85
  137. package/typed-model/notification.ts +135 -135
  138. package/typed-model/organization.ts +80 -80
  139. package/typed-model/password-tokens.ts +55 -0
  140. package/typed-model/pb-sequelize.ts +44 -44
  141. package/typed-model/permission.ts +62 -62
  142. package/typed-model/post.ts +170 -170
  143. package/typed-model/post_on_integrations.ts +104 -104
  144. package/typed-model/posts-on-users.ts +122 -122
  145. package/typed-model/private-feed-users.ts +63 -63
  146. package/typed-model/pumping-risk-score-monitoring.ts +73 -73
  147. package/typed-model/recurly-account.ts +51 -51
  148. package/typed-model/sample.ts +41 -41
  149. package/typed-model/sms-custom-message.ts +66 -66
  150. package/typed-model/sport-on-posts.ts +80 -80
  151. package/typed-model/sport.ts +46 -46
  152. package/typed-model/store.ts +198 -198
  153. package/typed-model/stores_on_organizations.ts +78 -78
  154. package/typed-model/subscriber-discord-integration.ts +109 -109
  155. package/typed-model/subscriber-telegram-integration.ts +109 -109
  156. package/typed-model/subscribers-on-creators.ts +107 -107
  157. package/typed-model/subscription-coupon.ts +128 -128
  158. package/typed-model/subscription-plan-on-post.ts +77 -77
  159. package/typed-model/subscription-plan-on-users.ts +194 -194
  160. package/typed-model/subscription-plan.ts +167 -167
  161. package/typed-model/subscription-pricing-option-on-coupons.ts +78 -78
  162. package/typed-model/subscription-pricing-option.ts +106 -106
  163. package/typed-model/telegram-integration-code.ts +60 -60
  164. package/typed-model/telegram-integration-invite-link.ts +59 -59
  165. package/typed-model/telegram-integration-log.ts +86 -86
  166. package/typed-model/telegram-integration.ts +141 -141
  167. package/typed-model/transaction.ts +159 -159
  168. package/typed-model/user.ts +273 -273
  169. package/typed-model/users-on-permissions.ts +96 -96
  170. package/typed-model/users_on_creators.ts +95 -95
  171. package/typed-model/users_on_organizations.ts +78 -78
  172. package/typed-model/whitelist.ts +66 -66
  173. package/typed-model/withdrawal.ts +50 -50
  174. package/dist/typed-model/featured-capper.js.map +0 -1
@@ -1,141 +1,141 @@
1
- import {
2
- Model,
3
- InferAttributes,
4
- InferCreationAttributes,
5
- CreationOptional,
6
- DataTypes,
7
- } from "sequelize";
8
-
9
- import sequelize from "./pb-sequelize";
10
- import SubscriptionPlan from "./subscription-plan";
11
- import FreeSubscriptionPlan from "./free-subscription-plan";
12
- import { ShouldRemoveSubscriberStatus } from "../src/types";
13
-
14
- // order of InferAttributes & InferCreationAttributes is important.
15
- class TelegramIntegration extends Model<
16
- InferAttributes<TelegramIntegration>,
17
- InferCreationAttributes<TelegramIntegration>
18
- > {
19
- // 'CreationOptional' is a special type that marks the field as optional
20
- // when creating an instance of the model (such as using Model.create()).
21
- declare id: CreationOptional<string>;
22
- declare planId: string;
23
- declare freePlanId: string;
24
- declare chatId: string;
25
- declare chatTitle: string;
26
- declare metadata: string;
27
- declare archived: boolean;
28
- declare shouldRemoveSubscriber: ShouldRemoveSubscriberStatus;
29
- declare autoPost: boolean;
30
- declare isDeleted?: boolean;
31
- declare deletedAt?: Date;
32
- declare archivedAt?: Date;
33
-
34
- declare createdAt: CreationOptional<Date>;
35
- declare updatedAt: CreationOptional<Date>;
36
- }
37
-
38
- TelegramIntegration.init(
39
- {
40
- id: {
41
- type: DataTypes.BIGINT,
42
- primaryKey: true,
43
- allowNull: false,
44
- defaultValue: sequelize.fn("next_id"),
45
- },
46
- planId: {
47
- type: DataTypes.BIGINT,
48
- allowNull: true,
49
- field: "plan_id",
50
- references: {
51
- model: SubscriptionPlan,
52
- },
53
- },
54
- freePlanId: {
55
- type: DataTypes.BIGINT,
56
- allowNull: true,
57
- field: "free_plan_id",
58
- references: {
59
- model: FreeSubscriptionPlan,
60
- },
61
- },
62
- chatId: {
63
- type: DataTypes.STRING,
64
- allowNull: true,
65
- field: "chat_id",
66
- },
67
- chatTitle: {
68
- type: DataTypes.STRING,
69
- allowNull: true,
70
- field: "chat_title",
71
- },
72
- metadata: {
73
- type: DataTypes.JSON,
74
- allowNull: true,
75
- field: "metadata",
76
- },
77
- archived: {
78
- type: DataTypes.BOOLEAN,
79
- allowNull: false,
80
- defaultValue: false,
81
- field: "archived",
82
- },
83
- shouldRemoveSubscriber: {
84
- type: DataTypes.ENUM(...Object.values(ShouldRemoveSubscriberStatus)),
85
- allowNull: false,
86
- defaultValue: ShouldRemoveSubscriberStatus.TRUE,
87
- field: "should_remove_subscriber",
88
- },
89
- autoPost: {
90
- type: DataTypes.BOOLEAN,
91
- allowNull: false,
92
- defaultValue: false,
93
- field: "auto_post",
94
- },
95
- isDeleted: {
96
- type: DataTypes.BOOLEAN,
97
- allowNull: true,
98
- field: "is_deleted",
99
- },
100
- deletedAt: {
101
- type: DataTypes.DATE,
102
- allowNull: true,
103
- },
104
- archivedAt: {
105
- type: DataTypes.DATE,
106
- allowNull: true,
107
- },
108
- createdAt: DataTypes.DATE,
109
- updatedAt: DataTypes.DATE,
110
- },
111
- {
112
- tableName: "telegram_integrations",
113
- sequelize,
114
- }
115
- );
116
-
117
- SubscriptionPlan.hasMany(TelegramIntegration, {
118
- foreignKey: "planId",
119
- sourceKey: "id",
120
- onDelete: "NO ACTION",
121
- constraints: false,
122
- });
123
-
124
- TelegramIntegration.hasOne(SubscriptionPlan, {
125
- foreignKey: "id",
126
- sourceKey: "planId",
127
- });
128
-
129
- FreeSubscriptionPlan.hasMany(TelegramIntegration, {
130
- foreignKey: "freePlanId",
131
- sourceKey: "id",
132
- onDelete: "NO ACTION",
133
- constraints: false,
134
- });
135
-
136
- TelegramIntegration.hasOne(FreeSubscriptionPlan, {
137
- foreignKey: "id",
138
- sourceKey: "freePlanId",
139
- });
140
-
141
- export default TelegramIntegration;
1
+ import {
2
+ Model,
3
+ InferAttributes,
4
+ InferCreationAttributes,
5
+ CreationOptional,
6
+ DataTypes,
7
+ } from "sequelize";
8
+
9
+ import sequelize from "./pb-sequelize";
10
+ import SubscriptionPlan from "./subscription-plan";
11
+ import FreeSubscriptionPlan from "./free-subscription-plan";
12
+ import { ShouldRemoveSubscriberStatus } from "../src/types";
13
+
14
+ // order of InferAttributes & InferCreationAttributes is important.
15
+ class TelegramIntegration extends Model<
16
+ InferAttributes<TelegramIntegration>,
17
+ InferCreationAttributes<TelegramIntegration>
18
+ > {
19
+ // 'CreationOptional' is a special type that marks the field as optional
20
+ // when creating an instance of the model (such as using Model.create()).
21
+ declare id: CreationOptional<string>;
22
+ declare planId: string;
23
+ declare freePlanId: string;
24
+ declare chatId: string;
25
+ declare chatTitle: string;
26
+ declare metadata: string;
27
+ declare archived: boolean;
28
+ declare shouldRemoveSubscriber: ShouldRemoveSubscriberStatus;
29
+ declare autoPost: boolean;
30
+ declare isDeleted?: boolean;
31
+ declare deletedAt?: Date;
32
+ declare archivedAt?: Date;
33
+
34
+ declare createdAt: CreationOptional<Date>;
35
+ declare updatedAt: CreationOptional<Date>;
36
+ }
37
+
38
+ TelegramIntegration.init(
39
+ {
40
+ id: {
41
+ type: DataTypes.BIGINT,
42
+ primaryKey: true,
43
+ allowNull: false,
44
+ defaultValue: sequelize.fn("next_id"),
45
+ },
46
+ planId: {
47
+ type: DataTypes.BIGINT,
48
+ allowNull: true,
49
+ field: "plan_id",
50
+ references: {
51
+ model: SubscriptionPlan,
52
+ },
53
+ },
54
+ freePlanId: {
55
+ type: DataTypes.BIGINT,
56
+ allowNull: true,
57
+ field: "free_plan_id",
58
+ references: {
59
+ model: FreeSubscriptionPlan,
60
+ },
61
+ },
62
+ chatId: {
63
+ type: DataTypes.STRING,
64
+ allowNull: true,
65
+ field: "chat_id",
66
+ },
67
+ chatTitle: {
68
+ type: DataTypes.STRING,
69
+ allowNull: true,
70
+ field: "chat_title",
71
+ },
72
+ metadata: {
73
+ type: DataTypes.JSON,
74
+ allowNull: true,
75
+ field: "metadata",
76
+ },
77
+ archived: {
78
+ type: DataTypes.BOOLEAN,
79
+ allowNull: false,
80
+ defaultValue: false,
81
+ field: "archived",
82
+ },
83
+ shouldRemoveSubscriber: {
84
+ type: DataTypes.ENUM(...Object.values(ShouldRemoveSubscriberStatus)),
85
+ allowNull: false,
86
+ defaultValue: ShouldRemoveSubscriberStatus.TRUE,
87
+ field: "should_remove_subscriber",
88
+ },
89
+ autoPost: {
90
+ type: DataTypes.BOOLEAN,
91
+ allowNull: false,
92
+ defaultValue: false,
93
+ field: "auto_post",
94
+ },
95
+ isDeleted: {
96
+ type: DataTypes.BOOLEAN,
97
+ allowNull: true,
98
+ field: "is_deleted",
99
+ },
100
+ deletedAt: {
101
+ type: DataTypes.DATE,
102
+ allowNull: true,
103
+ },
104
+ archivedAt: {
105
+ type: DataTypes.DATE,
106
+ allowNull: true,
107
+ },
108
+ createdAt: DataTypes.DATE,
109
+ updatedAt: DataTypes.DATE,
110
+ },
111
+ {
112
+ tableName: "telegram_integrations",
113
+ sequelize,
114
+ }
115
+ );
116
+
117
+ SubscriptionPlan.hasMany(TelegramIntegration, {
118
+ foreignKey: "planId",
119
+ sourceKey: "id",
120
+ onDelete: "NO ACTION",
121
+ constraints: false,
122
+ });
123
+
124
+ TelegramIntegration.hasOne(SubscriptionPlan, {
125
+ foreignKey: "id",
126
+ sourceKey: "planId",
127
+ });
128
+
129
+ FreeSubscriptionPlan.hasMany(TelegramIntegration, {
130
+ foreignKey: "freePlanId",
131
+ sourceKey: "id",
132
+ onDelete: "NO ACTION",
133
+ constraints: false,
134
+ });
135
+
136
+ TelegramIntegration.hasOne(FreeSubscriptionPlan, {
137
+ foreignKey: "id",
138
+ sourceKey: "freePlanId",
139
+ });
140
+
141
+ export default TelegramIntegration;
@@ -1,159 +1,159 @@
1
- import {
2
- Model,
3
- InferAttributes,
4
- InferCreationAttributes,
5
- CreationOptional,
6
- DataTypes,
7
- } from "sequelize";
8
-
9
- import sequelize from "./pb-sequelize";
10
- import User from "./user";
11
- import Notification from "./notification";
12
-
13
- type TransactionType =
14
- | "subscription"
15
- | "recurring"
16
- | "tip"
17
- | "text"
18
- | "unlock_message"
19
- | "content"
20
- | "unlock"
21
- | "audio"
22
- | "referral"
23
- | "video"
24
- | "refund"
25
- | "management_fee";
26
-
27
- // order of InferAttributes & InferCreationAttributes is important.
28
- class Transaction extends Model<
29
- InferAttributes<Transaction>,
30
- InferCreationAttributes<Transaction>
31
- > {
32
- // 'CreationOptional' is a special type that marks the field as optional
33
- // when creating an instance of the model (such as using Model.create()).
34
- declare id: CreationOptional<string>;
35
- declare payerId?: string;
36
- declare recipientId?: string;
37
- declare transactionAmountInCents: number;
38
- declare transactionType: TransactionType;
39
- declare withdrawalId?: string;
40
- declare withdrawalDate?: Date;
41
- declare metadata?: string;
42
- declare earningAmountInCents: number;
43
- declare referredTransactionId?: string;
44
- declare recurlyInvoiceId?: string;
45
- declare createdAt: CreationOptional<Date>;
46
- declare updatedAt: CreationOptional<Date>;
47
-
48
- static getById: (id: string) => Promise<Transaction | null>;
49
- }
50
-
51
- Transaction.init(
52
- {
53
- id: {
54
- type: DataTypes.BIGINT,
55
- primaryKey: true,
56
- allowNull: false,
57
- defaultValue: sequelize.fn("next_id"),
58
- },
59
- payerId: {
60
- type: DataTypes.BIGINT,
61
- field: "payer_id",
62
- },
63
- recipientId: {
64
- type: DataTypes.BIGINT,
65
- field: "recipient_id",
66
- },
67
- transactionAmountInCents: {
68
- type: DataTypes.INTEGER,
69
- field: "transaction_amount_in_cents",
70
- },
71
- transactionType: {
72
- type: DataTypes.STRING,
73
- field: "transaction_type",
74
- },
75
- withdrawalId: {
76
- type: DataTypes.BIGINT,
77
- field: "withdrawal_id",
78
- },
79
- withdrawalDate: {
80
- type: DataTypes.DATE,
81
- field: "withdrawal_date",
82
- },
83
- metadata: {
84
- type: DataTypes.STRING,
85
- field: "metadata",
86
- },
87
- earningAmountInCents: {
88
- type: DataTypes.INTEGER,
89
- field: "earning_amount_in_cents",
90
- },
91
- referredTransactionId: {
92
- type: DataTypes.BIGINT,
93
- field: "referred_transaction_id",
94
- },
95
- recurlyInvoiceId: {
96
- type: DataTypes.STRING,
97
- field: "recurly_invoice_id",
98
- },
99
- createdAt: DataTypes.DATE,
100
- updatedAt: DataTypes.DATE,
101
- },
102
- {
103
- tableName: "transactions",
104
- sequelize,
105
- }
106
- );
107
-
108
- const REFERRAL_PERCENTAGE = 0.03;
109
-
110
- /*
111
- ====================================================================
112
- Class functions
113
- ====================================================================
114
- */
115
-
116
- Transaction.getById = async (id: string) => {
117
- return await Transaction.findOne({
118
- where: {
119
- id,
120
- },
121
- });
122
- };
123
-
124
- User.hasMany(Transaction, {
125
- foreignKey: "payerId",
126
- onDelete: "NO ACTION",
127
- constraints: false,
128
- });
129
-
130
- Transaction.hasOne(User, {
131
- as: "payer",
132
- foreignKey: "id",
133
- sourceKey: "payerId",
134
- onDelete: "NO ACTION",
135
- constraints: false,
136
- });
137
-
138
- User.hasMany(Transaction, {
139
- foreignKey: "recipientId",
140
- onDelete: "NO ACTION",
141
- constraints: false,
142
- });
143
-
144
- Transaction.hasOne(User, {
145
- as: "recipient",
146
- foreignKey: "id",
147
- sourceKey: "recipientId",
148
- onDelete: "NO ACTION",
149
- constraints: false,
150
- });
151
-
152
- Notification.hasOne(Transaction, {
153
- foreignKey: "id",
154
- sourceKey: "transactionId",
155
- constraints: false,
156
- onDelete: "NO ACTION",
157
- });
158
-
159
- export default Transaction;
1
+ import {
2
+ Model,
3
+ InferAttributes,
4
+ InferCreationAttributes,
5
+ CreationOptional,
6
+ DataTypes,
7
+ } from "sequelize";
8
+
9
+ import sequelize from "./pb-sequelize";
10
+ import User from "./user";
11
+ import Notification from "./notification";
12
+
13
+ type TransactionType =
14
+ | "subscription"
15
+ | "recurring"
16
+ | "tip"
17
+ | "text"
18
+ | "unlock_message"
19
+ | "content"
20
+ | "unlock"
21
+ | "audio"
22
+ | "referral"
23
+ | "video"
24
+ | "refund"
25
+ | "management_fee";
26
+
27
+ // order of InferAttributes & InferCreationAttributes is important.
28
+ class Transaction extends Model<
29
+ InferAttributes<Transaction>,
30
+ InferCreationAttributes<Transaction>
31
+ > {
32
+ // 'CreationOptional' is a special type that marks the field as optional
33
+ // when creating an instance of the model (such as using Model.create()).
34
+ declare id: CreationOptional<string>;
35
+ declare payerId?: string;
36
+ declare recipientId?: string;
37
+ declare transactionAmountInCents: number;
38
+ declare transactionType: TransactionType;
39
+ declare withdrawalId?: string;
40
+ declare withdrawalDate?: Date;
41
+ declare metadata?: string;
42
+ declare earningAmountInCents: number;
43
+ declare referredTransactionId?: string;
44
+ declare recurlyInvoiceId?: string;
45
+ declare createdAt: CreationOptional<Date>;
46
+ declare updatedAt: CreationOptional<Date>;
47
+
48
+ static getById: (id: string) => Promise<Transaction | null>;
49
+ }
50
+
51
+ Transaction.init(
52
+ {
53
+ id: {
54
+ type: DataTypes.BIGINT,
55
+ primaryKey: true,
56
+ allowNull: false,
57
+ defaultValue: sequelize.fn("next_id"),
58
+ },
59
+ payerId: {
60
+ type: DataTypes.BIGINT,
61
+ field: "payer_id",
62
+ },
63
+ recipientId: {
64
+ type: DataTypes.BIGINT,
65
+ field: "recipient_id",
66
+ },
67
+ transactionAmountInCents: {
68
+ type: DataTypes.INTEGER,
69
+ field: "transaction_amount_in_cents",
70
+ },
71
+ transactionType: {
72
+ type: DataTypes.STRING,
73
+ field: "transaction_type",
74
+ },
75
+ withdrawalId: {
76
+ type: DataTypes.BIGINT,
77
+ field: "withdrawal_id",
78
+ },
79
+ withdrawalDate: {
80
+ type: DataTypes.DATE,
81
+ field: "withdrawal_date",
82
+ },
83
+ metadata: {
84
+ type: DataTypes.STRING,
85
+ field: "metadata",
86
+ },
87
+ earningAmountInCents: {
88
+ type: DataTypes.INTEGER,
89
+ field: "earning_amount_in_cents",
90
+ },
91
+ referredTransactionId: {
92
+ type: DataTypes.BIGINT,
93
+ field: "referred_transaction_id",
94
+ },
95
+ recurlyInvoiceId: {
96
+ type: DataTypes.STRING,
97
+ field: "recurly_invoice_id",
98
+ },
99
+ createdAt: DataTypes.DATE,
100
+ updatedAt: DataTypes.DATE,
101
+ },
102
+ {
103
+ tableName: "transactions",
104
+ sequelize,
105
+ }
106
+ );
107
+
108
+ const REFERRAL_PERCENTAGE = 0.03;
109
+
110
+ /*
111
+ ====================================================================
112
+ Class functions
113
+ ====================================================================
114
+ */
115
+
116
+ Transaction.getById = async (id: string) => {
117
+ return await Transaction.findOne({
118
+ where: {
119
+ id,
120
+ },
121
+ });
122
+ };
123
+
124
+ User.hasMany(Transaction, {
125
+ foreignKey: "payerId",
126
+ onDelete: "NO ACTION",
127
+ constraints: false,
128
+ });
129
+
130
+ Transaction.hasOne(User, {
131
+ as: "payer",
132
+ foreignKey: "id",
133
+ sourceKey: "payerId",
134
+ onDelete: "NO ACTION",
135
+ constraints: false,
136
+ });
137
+
138
+ User.hasMany(Transaction, {
139
+ foreignKey: "recipientId",
140
+ onDelete: "NO ACTION",
141
+ constraints: false,
142
+ });
143
+
144
+ Transaction.hasOne(User, {
145
+ as: "recipient",
146
+ foreignKey: "id",
147
+ sourceKey: "recipientId",
148
+ onDelete: "NO ACTION",
149
+ constraints: false,
150
+ });
151
+
152
+ Notification.hasOne(Transaction, {
153
+ foreignKey: "id",
154
+ sourceKey: "transactionId",
155
+ constraints: false,
156
+ onDelete: "NO ACTION",
157
+ });
158
+
159
+ export default Transaction;