@winible/winible-typed 2.0.1 → 2.1.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 (63) hide show
  1. package/dist/migrations/20230412190423-migrate_purchased_contents.js +10 -0
  2. package/dist/migrations/20230412190423-migrate_purchased_contents.js.map +1 -0
  3. package/dist/migrations/20230412202031-migrate_other_fields.js +27 -0
  4. package/dist/migrations/20230412202031-migrate_other_fields.js.map +1 -0
  5. package/dist/migrations/20230412213952-deprecate_phone_users_and_phone_owners.js +27 -0
  6. package/dist/migrations/20230412213952-deprecate_phone_users_and_phone_owners.js.map +1 -0
  7. package/dist/scripts/deleteMalformedImages.js +2 -2
  8. package/dist/scripts/deleteMalformedImages.js.map +1 -1
  9. package/dist/typed-model/content-like.js +27 -15
  10. package/dist/typed-model/content-like.js.map +1 -1
  11. package/dist/typed-model/credit-payment.js +35 -371
  12. package/dist/typed-model/credit-payment.js.map +1 -1
  13. package/dist/typed-model/index.js +13 -15
  14. package/dist/typed-model/index.js.map +1 -1
  15. package/dist/typed-model/league-user.js +3 -3
  16. package/dist/typed-model/league-user.js.map +1 -1
  17. package/dist/typed-model/media.js +2 -6
  18. package/dist/typed-model/media.js.map +1 -1
  19. package/dist/typed-model/pb-sequelize.js +3 -1
  20. package/dist/typed-model/pb-sequelize.js.map +1 -1
  21. package/dist/typed-model/phone-owner.js +3 -3
  22. package/dist/typed-model/phone-owner.js.map +1 -1
  23. package/dist/typed-model/post.js +126 -0
  24. package/dist/typed-model/post.js.map +1 -0
  25. package/dist/typed-model/posts-on-users.js +92 -0
  26. package/dist/typed-model/posts-on-users.js.map +1 -0
  27. package/dist/typed-model/premium-content.js +9 -4
  28. package/dist/typed-model/premium-content.js.map +1 -1
  29. package/dist/typed-model/purchased-content.js +13 -13
  30. package/dist/typed-model/purchased-content.js.map +1 -1
  31. package/dist/typed-model/recurly-account.js.map +1 -1
  32. package/dist/typed-model/subscription-plan-on-post.js +55 -0
  33. package/dist/typed-model/subscription-plan-on-post.js.map +1 -0
  34. package/dist/typed-model/subscription-plan-on-users.js +111 -0
  35. package/dist/typed-model/subscription-plan-on-users.js.map +1 -0
  36. package/dist/typed-model/subscription-plan.js +22 -32
  37. package/dist/typed-model/subscription-plan.js.map +1 -1
  38. package/dist/typed-model/subscription.js +32 -40
  39. package/dist/typed-model/subscription.js.map +1 -1
  40. package/dist/typed-model/transaction.js +108 -0
  41. package/dist/typed-model/transaction.js.map +1 -0
  42. package/dist/typed-model/withdrawal.js +33 -0
  43. package/dist/typed-model/withdrawal.js.map +1 -0
  44. package/dist/webhooks/index.js.map +1 -1
  45. package/dist/webhooks/payment/refund.js +11 -11
  46. package/dist/webhooks/payment/refund.js.map +1 -1
  47. package/package.json +1 -1
  48. package/typed-model/content-like.ts +33 -17
  49. package/typed-model/index.ts +6 -7
  50. package/typed-model/league-user.ts +5 -3
  51. package/typed-model/media.ts +3 -9
  52. package/typed-model/pb-sequelize.ts +5 -1
  53. package/typed-model/{premium-content.ts → post.ts} +44 -42
  54. package/typed-model/{purchased-content.ts → posts-on-users.ts} +46 -25
  55. package/typed-model/recurly-account.ts +0 -1
  56. package/typed-model/subscription-plan-on-post.ts +77 -0
  57. package/typed-model/{subscription.ts → subscription-plan-on-users.ts} +43 -59
  58. package/typed-model/subscription-plan.ts +29 -46
  59. package/typed-model/transaction.ts +154 -0
  60. package/typed-model/{credit-payout.ts → withdrawal.ts} +9 -21
  61. package/typed-model/credit-payment.ts +0 -681
  62. package/typed-model/phone-owner.ts +0 -341
  63. package/typed-model/phone-user.ts +0 -146
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ async up(queryInterface, sequelize) {
5
+ await queryInterface.renameColumn("purchased_contents", "content_id", "post_id");
6
+ await queryInterface.renameTable("purchased_contents", "posts_on_users");
7
+ },
8
+ async down(queryInterface, sequelize) { },
9
+ };
10
+ //# sourceMappingURL=20230412190423-migrate_purchased_contents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20230412190423-migrate_purchased_contents.js","sourceRoot":"","sources":["../../migrations/20230412190423-migrate_purchased_contents.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,KAAK,CAAC,EAAE,CAAC,cAA8B,EAAE,SAAoB;QAC3D,MAAM,cAAc,CAAC,YAAY,CAC/B,oBAAoB,EACpB,YAAY,EACZ,SAAS,CACV,CAAC;QACF,MAAM,cAAc,CAAC,WAAW,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,CAAC;IAC3E,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,cAA8B,EAAE,SAAoB,IAAG,CAAC;CACpE,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const sequelize_1 = require("sequelize");
4
+ exports.default = {
5
+ async up(queryInterface, sequelize) {
6
+ await queryInterface.dropTable("phone_users");
7
+ await queryInterface.dropTable("phone_owners");
8
+ await queryInterface.dropTable("owner_host_statuses");
9
+ await queryInterface.dropTable("parlays");
10
+ await queryInterface.renameColumn("subscription_plan_on_premium_content", "content_id", "post_id");
11
+ await queryInterface.renameColumn("subscription_plans", "owner_id", "user_id");
12
+ await queryInterface.removeColumn("subscription_plans", "product_description_list");
13
+ await queryInterface.addColumn("subscription_plans", "plan_description", {
14
+ type: sequelize_1.DataTypes.STRING,
15
+ });
16
+ await queryInterface.removeColumn("subscription_plans", "paypal_plan_id");
17
+ await queryInterface.removeColumn("subscription_plans", "paypal_product_id");
18
+ await queryInterface.removeColumn("subscriptions", "paypal_subscription_id");
19
+ await queryInterface.removeColumn("subscriptions", "paypal_order_id");
20
+ await queryInterface.removeColumn("subscriptions", "paypal_billing_token");
21
+ await queryInterface.removeColumn("subscriptions", "pk_subscription_id");
22
+ await queryInterface.removeColumn("subscriptions", "subscription_promotion_id");
23
+ await queryInterface.renameTable("subscriptions", "subscription_plan_on_users");
24
+ },
25
+ async down(queryInterface, sequelize) { },
26
+ };
27
+ //# sourceMappingURL=20230412202031-migrate_other_fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20230412202031-migrate_other_fields.js","sourceRoot":"","sources":["../../migrations/20230412202031-migrate_other_fields.ts"],"names":[],"mappings":";;AAAA,yCAAiE;AAEjE,kBAAe;IACb,KAAK,CAAC,EAAE,CAAC,cAA8B,EAAE,SAAoB;QAC3D,MAAM,cAAc,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;QAC9C,MAAM,cAAc,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;QAC/C,MAAM,cAAc,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;QACtD,MAAM,cAAc,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC1C,MAAM,cAAc,CAAC,YAAY,CAC/B,sCAAsC,EACtC,YAAY,EACZ,SAAS,CACV,CAAC;QACF,MAAM,cAAc,CAAC,YAAY,CAC/B,oBAAoB,EACpB,UAAU,EACV,SAAS,CACV,CAAC;QACF,MAAM,cAAc,CAAC,YAAY,CAC/B,oBAAoB,EACpB,0BAA0B,CAC3B,CAAC;QACF,MAAM,cAAc,CAAC,SAAS,CAAC,oBAAoB,EAAE,kBAAkB,EAAE;YACvE,IAAI,EAAE,qBAAS,CAAC,MAAM;SACvB,CAAC,CAAC;QACH,MAAM,cAAc,CAAC,YAAY,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,CAAC;QAC1E,MAAM,cAAc,CAAC,YAAY,CAC/B,oBAAoB,EACpB,mBAAmB,CACpB,CAAC;QACF,MAAM,cAAc,CAAC,YAAY,CAC/B,eAAe,EACf,wBAAwB,CACzB,CAAC;QACF,MAAM,cAAc,CAAC,YAAY,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;QACtE,MAAM,cAAc,CAAC,YAAY,CAAC,eAAe,EAAE,sBAAsB,CAAC,CAAC;QAC3E,MAAM,cAAc,CAAC,YAAY,CAAC,eAAe,EAAE,oBAAoB,CAAC,CAAC;QACzE,MAAM,cAAc,CAAC,YAAY,CAC/B,eAAe,EACf,2BAA2B,CAC5B,CAAC;QACF,MAAM,cAAc,CAAC,WAAW,CAC9B,eAAe,EACf,4BAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,cAA8B,EAAE,SAAoB,IAAG,CAAC;CACpE,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const sequelize_1 = require("sequelize");
4
+ exports.default = {
5
+ async up(queryInterface, sequelize) {
6
+ await queryInterface.dropTable("phone_users", { force: true });
7
+ await queryInterface.dropTable("phone_owners", { force: true });
8
+ await queryInterface.dropTable("owner_host_statuses");
9
+ await queryInterface.dropTable("parlays");
10
+ await queryInterface.renameColumn("subscription_plan_on_premium_content", "content_id", "post_id");
11
+ await queryInterface.renameColumn("subscription_plans", "owner_id", "user_id");
12
+ await queryInterface.removeColumn("subscription_plans", "product_description_list");
13
+ await queryInterface.addColumn("subscription_plans", "plan_description", {
14
+ type: sequelize_1.DataTypes.STRING,
15
+ });
16
+ await queryInterface.removeColumn("subscription_plans", "paypal_plan_id");
17
+ await queryInterface.removeColumn("subscription_plans", "paypal_product_id");
18
+ await queryInterface.removeColumn("subscriptions", "paypal_subscription_id");
19
+ await queryInterface.removeColumn("subscriptions", "paypal_order_id");
20
+ await queryInterface.removeColumn("subscriptions", "paypal_billing_token");
21
+ await queryInterface.removeColumn("subscriptions", "pk_subscription_id");
22
+ await queryInterface.removeColumn("subscriptions", "subscription_promotion_id");
23
+ await queryInterface.renameTable("subscriptions", "subscription_plan_on_users");
24
+ },
25
+ async down(queryInterface, sequelize) { },
26
+ };
27
+ //# sourceMappingURL=20230412213952-deprecate_phone_users_and_phone_owners.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20230412213952-deprecate_phone_users_and_phone_owners.js","sourceRoot":"","sources":["../../migrations/20230412213952-deprecate_phone_users_and_phone_owners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F,MAAM,cAAc,CAAC,WAAW,CAC9B,eAAe,EACf,4BAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,cAA8B,EAAE,SAAoB,IAAG,CAAC;CACpE,CAAC"}
@@ -16,13 +16,13 @@ const run = async () => {
16
16
  const objects = await listAllKeys({ Bucket: BUCKET });
17
17
  const objectKeys = objects.map((o) => o.Key);
18
18
  for (let key of objectKeys) {
19
- let owner = await __1.PhoneOwner.findOne({
19
+ let owner = await __1.User.findOne({
20
20
  where: {
21
21
  [sequelize_1.Op.or]: {
22
22
  bannerImageUrl: {
23
23
  [sequelize_1.Op.like]: `%${key}%`,
24
24
  },
25
- welcomeMediaUrl: {
25
+ avatarUrl: {
26
26
  [sequelize_1.Op.like]: `%${key}%`,
27
27
  },
28
28
  },
@@ -1 +1 @@
1
- {"version":3,"file":"deleteMalformedImages.js","sourceRoot":"","sources":["../../scripts/deleteMalformedImages.ts"],"names":[],"mappings":";;AAAA,iCAAkC;AAClC,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,qCAAqC;AACrC,0BAAgC;AAChC,yCAA+B;AAC/B,gDAA4C;AAE5C,MAAM,EAAE,GAAG,IAAI,YAAE,EAAE,CAAC;AACpB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;IACvC,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;CAC/C,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,gBAAgB,CAAC;AAEhC,MAAM,GAAG,GAAG,KAAK,IAAI,EAAE;IACrB,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAEtD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC7C,KAAK,IAAI,GAAG,IAAI,U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C,GAAG,CAAC,eAAe,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,UAAU;IACpE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;IAC3B,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;QACpB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ"}
@@ -5,7 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const sequelize_1 = require("sequelize");
7
7
  const pb_sequelize_1 = __importDefault(require("./pb-sequelize"));
8
- const phone_user_1 = __importDefault(require("./phone-user"));
8
+ const post_1 = __importDefault(require("./post"));
9
+ const user_1 = __importDefault(require("./user"));
9
10
  // order of InferAttributes & InferCreationAttributes is important.
10
11
  class ContentLike extends sequelize_1.Model {
11
12
  }
@@ -16,9 +17,9 @@ ContentLike.init({
16
17
  allowNull: false,
17
18
  defaultValue: pb_sequelize_1.default.fn("next_id"),
18
19
  },
19
- contentId: {
20
+ postId: {
20
21
  type: sequelize_1.DataTypes.INTEGER,
21
- field: "content_id",
22
+ field: "post_id",
22
23
  },
23
24
  userId: {
24
25
  type: sequelize_1.DataTypes.STRING,
@@ -29,18 +30,6 @@ ContentLike.init({
29
30
  }, {
30
31
  sequelize: pb_sequelize_1.default,
31
32
  tableName: "content_likes",
32
- // Other model options go here
33
- });
34
- phone_user_1.default.hasMany(ContentLike, {
35
- foreignKey: "user_id",
36
- onDelete: "NO ACTION",
37
- constraints: false,
38
- });
39
- ContentLike.hasOne(phone_user_1.default, {
40
- foreignKey: "id",
41
- sourceKey: "user_id",
42
- onDelete: "NO ACTION",
43
- constraints: false,
44
33
  });
45
34
  /*
46
35
  ====================================================================
@@ -54,5 +43,28 @@ ContentLike.getById = async (id) => {
54
43
  },
55
44
  });
56
45
  };
46
+ post_1.default.hasMany(ContentLike, {
47
+ foreignKey: "postId",
48
+ sourceKey: "id",
49
+ onDelete: "NO ACTION",
50
+ constraints: false,
51
+ });
52
+ ContentLike.hasOne(post_1.default, {
53
+ foreignKey: "id",
54
+ sourceKey: "postId",
55
+ onDelete: "NO ACTION",
56
+ constraints: false,
57
+ });
58
+ user_1.default.hasMany(ContentLike, {
59
+ foreignKey: "userId",
60
+ onDelete: "NO ACTION",
61
+ constraints: false,
62
+ });
63
+ ContentLike.hasOne(user_1.default, {
64
+ foreignKey: "id",
65
+ sourceKey: "userId",
66
+ onDelete: "NO ACTION",
67
+ constraints: false,
68
+ });
57
69
  exports.default = ContentLike;
58
70
  //# sourceMappingURL=content-like.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"content-like.js","sourceRoot":"","sources":["../../typed-model/content-like.ts"],"names":[],"mappings":";;;;;AAAA,yCAOmB;AAEnB,kEAAuC;AACvC,8DAAqC;AAErC,mEAAmE;AACnE,MAAM,WAAY,SAAQ,iBAGzB;CASA;AAED,WAAW,CAAC,IAAI,CACd;IACE,EAAE,EAAE;QACF,IAAI,EAAE,qBAAS,CAAC,MAAM;QACtB,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE,KAAK;QAChB,YAAY,EAAE,sBAAS,CAAC,EAAE,CAAC,SAAS,CAAC;KACtC;IACD,SAAS,EAAE;QACT,IAAI,EAAE,qBAAS,CAAC,OAAO;QACvB,KAAK,EAAE,YAAY;KACpB;IACD,MAAM,EAAE;QACN,IAAI,EAAE,qBAAS,CAAC,MAAM;QACtB,KAAK,EAAE,SAAS;KACjB;IACD,SAAS,EAAE,qBAAS,CAAC,IAAI;IACzB,SAAS,EAAE,qBAAS,CAAC,IAAI;CAC1B,EACD;IACE,SAAS,EAAT,sBAAS;IACT,SAAS,EAAE,eAAe;IAC1B,8BAA8B;CAC/B,CACF,CAAC;AAEF,oBAAS,CAAC,OAAO,CAAC,WAAW,EAAE;IAC7B,UAAU,EAAE,SAAS;IACrB,QAAQ,EAAE,WAAW;IACrB,WAAW,EAAE,KAAK;CACnB,CAAC,CAAC;AACH,WAAW,CAAC,MAAM,CAAC,oBAAS,EAAE;IAC5B,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,SAAS;IACpB,QAAQ,EAAE,WAAW;IACrB,WAAW,EAAE,KAAK;CACnB,CAAC,CAAC;AACH;;;;EAIE;AAEF,WAAW,CAAC,OAAO,GAAG,KAAK,EAAE,EAAU,EAAE,EAAE;IACzC,OAAO,MAAM,WAAW,CAAC,OAAO,CAAC;QAC/B,KAAK,EAAE;YACL,EAAE;SACH;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,kBAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"content-like.js","sourceRoot":"","sources":["../../typed-model/content-like.ts"],"names":[],"mappings":";;;;;AAAA,yCAMmB;AAEnB,kEAAuC;AACvC,kDAA0B;AAC1B,kDAA0B;AAE1B,mEAAmE;AACnE,MAAM,WAAY,SAAQ,iBAGzB;CAUA;AAED,WAAW,CAAC,IAAI,CACd;IACE,EAAE,EAAE;QACF,IAAI,EAAE,qBAAS,CAAC,MAAM;QACtB,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE,KAAK;QAChB,YAAY,EAAE,sBAAS,CAAC,EAAE,CAAC,SAAS,CAAC;KACtC;IACD,MAAM,EAAE;QACN,IAAI,EAAE,qBAAS,CAAC,OAAO;QACvB,KAAK,EAAE,SAAS;KACjB;IACD,MAAM,EAAE;QACN,IAAI,EAAE,qBAAS,CAAC,MAAM;QACtB,KAAK,EAAE,SAAS;KACjB;IACD,SAAS,EAAE,qBAAS,CAAC,IAAI;IACzB,SAAS,EAAE,qBAAS,CAAC,IAAI;CAC1B,EACD;IACE,SAAS,EAAT,sBAAS;IACT,SAAS,EAAE,eAAe;CAC3B,CACF,CAAC;AAEF;;;;EAIE;AAEF,WAAW,CAAC,OAAO,GAAG,KAAK,EAAE,EAAU,EAAE,EAAE;IACzC,OAAO,MAAM,WAAW,CAAC,OAAO,CAAC;QAC/B,KAAK,EAAE;YACL,EAAE;SACH;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE;IACxB,UAAU,EAAE,QAAQ;IACpB,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,WAAW;IACrB,WAAW,EAAE,KAAK;CACnB,CAAC,CAAC;AAEH,WAAW,CAAC,MAAM,CAAC,cAAI,EAAE;IACvB,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,QAAQ;IACnB,QAAQ,EAAE,WAAW;IACrB,WAAW,EAAE,KAAK;CACnB,CAAC,CAAC;AAEH,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE;IACxB,UAAU,EAAE,QAAQ;IACpB,QAAQ,EAAE,WAAW;IACrB,WAAW,EAAE,KAAK;CACnB,CAAC,CAAC;AAEH,WAAW,CAAC,MAAM,CAAC,cAAI,EAAE;IACvB,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,QAAQ;IACnB,QAAQ,EAAE,WAAW;IACrB,WAAW,EAAE,KAAK;CACnB,CAAC,CAAC;AAEH,kBAAe,WAAW,CAAC"}
@@ -1,79 +1,45 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
6
  const sequelize_1 = require("sequelize");
30
7
  const pb_sequelize_1 = __importDefault(require("./pb-sequelize"));
31
- const phone_owner_1 = __importDefault(require("./phone-owner"));
32
- const phone_user_1 = __importDefault(require("./phone-user"));
33
- const premium_content_1 = __importDefault(require("./premium-content"));
34
- const purchased_content_1 = __importDefault(require("./purchased-content"));
35
- const notification_1 = __importStar(require("./notification"));
36
- const INTERACTION_TYPES = {
37
- CONTENT: "content",
38
- AUDIO: "audio",
39
- TEXT: "text",
40
- VIDEO: "video",
41
- TIP: "tip",
42
- UNLOCK: "unlock",
43
- UNLOCK_MESSAGE: "unlock_message",
44
- REFERRAL: "referral",
45
- SUBSCRIPTION: "subscription",
46
- };
8
+ const user_1 = __importDefault(require("./user"));
9
+ const notification_1 = __importDefault(require("./notification"));
47
10
  // order of InferAttributes & InferCreationAttributes is important.
48
- class CreditPayments extends sequelize_1.Model {
11
+ class Transaction extends sequelize_1.Model {
49
12
  }
50
- CreditPayments.init({
13
+ Transaction.init({
51
14
  id: {
52
15
  type: sequelize_1.DataTypes.BIGINT,
53
16
  primaryKey: true,
54
17
  allowNull: false,
55
18
  defaultValue: pb_sequelize_1.default.fn("next_id"),
56
19
  },
57
- userId: {
20
+ payerId: {
58
21
  type: sequelize_1.DataTypes.BIGINT,
59
- field: "user_id",
22
+ field: "payer_id",
60
23
  },
61
- ownerId: {
24
+ recipientId: {
62
25
  type: sequelize_1.DataTypes.BIGINT,
63
- allowNull: false,
64
- field: "owner_id",
26
+ field: "recipient_id",
65
27
  },
66
- creditAmountInCents: {
28
+ transactionAmountInCents: {
67
29
  type: sequelize_1.DataTypes.INTEGER,
68
- field: "credit_amount_in_cents",
30
+ field: "transaction_amount_in_cents",
69
31
  },
70
- interactionType: {
32
+ transactionType: {
71
33
  type: sequelize_1.DataTypes.STRING,
72
- field: "interaction_type",
34
+ field: "transaction_type",
73
35
  },
74
- payoutDate: {
36
+ withdrawalId: {
37
+ type: sequelize_1.DataTypes.BIGINT,
38
+ field: "withdrawal_id",
39
+ },
40
+ withdrawalDate: {
75
41
  type: sequelize_1.DataTypes.DATE,
76
- field: "payout_date",
42
+ field: "withdrawal_date",
77
43
  },
78
44
  metadata: {
79
45
  type: sequelize_1.DataTypes.STRING,
@@ -83,26 +49,17 @@ CreditPayments.init({
83
49
  type: sequelize_1.DataTypes.INTEGER,
84
50
  field: "earning_amount_in_cents",
85
51
  },
86
- payoutId: {
52
+ referredTransactionId: {
87
53
  type: sequelize_1.DataTypes.BIGINT,
88
- field: "payout_id",
54
+ field: "referred_transaction_id",
89
55
  },
90
- referredCreditPaymentId: {
91
- type: sequelize_1.DataTypes.BIGINT,
92
- field: "referred_credit_payment_id",
93
- },
94
- transId: {
95
- type: sequelize_1.DataTypes.BIGINT,
96
- field: "trans_id",
97
- },
98
- invoiceId: {
56
+ recurlyInvoiceId: {
99
57
  type: sequelize_1.DataTypes.STRING,
100
- field: "invoice_id",
58
+ field: "recurly_invoice_id",
101
59
  },
102
60
  createdAt: sequelize_1.DataTypes.DATE,
103
61
  updatedAt: sequelize_1.DataTypes.DATE,
104
62
  }, {
105
- // Other model options go here
106
63
  tableName: "credit_payments",
107
64
  sequelize: pb_sequelize_1.default,
108
65
  });
@@ -112,333 +69,40 @@ const REFERRAL_PERCENTAGE = 0.03;
112
69
  Class functions
113
70
  ====================================================================
114
71
  */
115
- CreditPayments.getById = async (id) => {
116
- return await CreditPayments.findOne({
72
+ Transaction.getById = async (id) => {
73
+ return await Transaction.findOne({
117
74
  where: {
118
75
  id,
119
76
  },
120
77
  });
121
78
  };
122
- CreditPayments.logContentPurchase = async (user, contentId, owner, alreadyPaid, transaction, invoiceId) => {
123
- const content = await premium_content_1.default.getById(contentId);
124
- if (!content) {
125
- throw new Error("No such content for id: " + contentId);
126
- }
127
- if (user.creditsInCents < content.amountInCents && !alreadyPaid) {
128
- throw new Error("Not enough credits");
129
- }
130
- if (content.amountInCents < 0) {
131
- throw new Error("Cannot be less than 0");
132
- }
133
- let purchasedContent = await purchased_content_1.default.create({
134
- userId: user.id,
135
- contentId: content.id,
136
- }, { transaction });
137
- if (!alreadyPaid) {
138
- user.creditsInCents = user.creditsInCents - content.amountInCents;
139
- await user.save({ transaction });
140
- }
141
- let creditPayment = await CreditPayments.create({
142
- userId: user.id,
143
- ownerId: content.ownerId,
144
- creditAmountInCents: content.amountInCents,
145
- earningAmountInCents: earningsAmount(content.amountInCents, owner && owner.serviceFeePercentage),
146
- interactionType: INTERACTION_TYPES.CONTENT,
147
- metadata: JSON.stringify({ contentId }),
148
- invoiceId,
149
- }, { transaction });
150
- try {
151
- await notification_1.default.create({
152
- recipientId: user.id,
153
- senderId: content.ownerId,
154
- transactionId: creditPayment.id,
155
- type: notification_1.NotificationType.PURCHASED_POST,
156
- purchasedPostId: purchasedContent.id,
157
- }, { transaction });
158
- }
159
- catch (err) {
160
- console.log(err);
161
- }
162
- if (owner && owner.referringOwnerId) {
163
- await createReferralPayment(owner, creditPayment, content.amountInCents, transaction);
164
- }
165
- if (user.referringOwnerId) {
166
- await createUserReferralPayment(user, creditPayment, content.amountInCents, transaction);
167
- }
168
- return creditPayment;
169
- };
170
- // CreditPayments.logTip = async (
171
- // user: PhoneUser,
172
- // owner: PhoneOwner,
173
- // tipAmountInCents: number
174
- // ) => {
175
- // if (tipAmountInCents > user.creditsInCents!) {
176
- // let url = await getPaymentUrl(user, owner);
177
- // throw new Error(
178
- // `Sorry, it looks like you've run out of credits. To send a tip, add more credits here: ${url}`
179
- // );
180
- // }
181
- // if (tipAmountInCents < 0) {
182
- // throw new Error("Cannot be less than 0");
183
- // }
184
- // user.creditsInCents = user.creditsInCents! - tipAmountInCents;
185
- // await user.save();
186
- // let creditPayment = await CreditPayments.create({
187
- // userId: user.id,
188
- // ownerId: owner.id,
189
- // creditAmountInCents: tipAmountInCents,
190
- // earningAmountInCents: earningsAmount(
191
- // tipAmountInCents,
192
- // owner.serviceFeePercentage
193
- // ),
194
- // interactionType: INTERACTION_TYPES.TIP,
195
- // });
196
- // if (owner.referringOwnerId) {
197
- // await createReferralPayment(owner, creditPayment, tipAmountInCents);
198
- // }
199
- // if (user.referringOwnerId) {
200
- // await createUserReferralPayment(user, creditPayment, tipAmountInCents);
201
- // }
202
- // try {
203
- // await Notification.create({
204
- // ownerId: owner.id,
205
- // userId: user.id,
206
- // creditPaymentId: creditPayment.id,
207
- // type: "tip",
208
- // });
209
- // } catch (err) {
210
- // console.log(err);
211
- // }
212
- // return creditPayment;
213
- // };
214
- CreditPayments.logMessage = async (user, owner, chatRateInCents) => {
215
- if (chatRateInCents > user.creditsInCents) {
216
- let url = await getPaymentUrl(user, owner);
217
- throw new Error(`Sorry, it looks like you've run out of credits. To keep texting, add more credits here: ${url}`);
218
- }
219
- if (chatRateInCents < 0) {
220
- throw new Error("Cannot be less than 0");
221
- }
222
- user.creditsInCents = user.creditsInCents - chatRateInCents;
223
- await user.save();
224
- let creditPayment = await CreditPayments.create({
225
- userId: user.id,
226
- ownerId: owner.id,
227
- creditAmountInCents: chatRateInCents,
228
- earningAmountInCents: earningsAmount(chatRateInCents),
229
- interactionType: INTERACTION_TYPES.TEXT,
230
- });
231
- if (owner.referringOwnerId) {
232
- await createReferralPayment(owner, creditPayment, chatRateInCents);
233
- }
234
- if (user.referringOwnerId) {
235
- await createUserReferralPayment(user, creditPayment, chatRateInCents);
236
- }
237
- return creditPayment;
238
- };
239
- CreditPayments.logAudioCall = async (user, owner, callAmountInCents) => {
240
- if (callAmountInCents < 0) {
241
- throw new Error("Cannot be less than 0");
242
- }
243
- user.creditsInCents = user.creditsInCents - callAmountInCents;
244
- await user.save();
245
- let creditPayment = await CreditPayments.create({
246
- userId: user.id,
247
- ownerId: owner.id,
248
- creditAmountInCents: callAmountInCents,
249
- earningAmountInCents: earningsAmount(callAmountInCents, owner.serviceFeePercentage),
250
- interactionType: INTERACTION_TYPES.AUDIO,
251
- });
252
- if (owner.referringOwnerId) {
253
- await createReferralPayment(owner, creditPayment, callAmountInCents);
254
- }
255
- if (user.referringOwnerId) {
256
- await createUserReferralPayment(user, creditPayment, callAmountInCents);
257
- }
258
- return creditPayment;
259
- };
260
- CreditPayments.logVideoCall = async (user, owner, callAmountInCents) => {
261
- if (callAmountInCents < 0) {
262
- throw new Error("Cannot be less than 0");
263
- }
264
- user.creditsInCents = user.creditsInCents - callAmountInCents;
265
- await user.save();
266
- let creditPayment = await CreditPayments.create({
267
- userId: user.id,
268
- ownerId: owner.id,
269
- creditAmountInCents: callAmountInCents,
270
- earningAmountInCents: earningsAmount(callAmountInCents, owner.serviceFeePercentage),
271
- interactionType: INTERACTION_TYPES.VIDEO,
272
- });
273
- if (owner.referringOwnerId) {
274
- await createReferralPayment(owner, creditPayment, callAmountInCents);
275
- }
276
- if (user.referringOwnerId) {
277
- await createUserReferralPayment(user, creditPayment, callAmountInCents);
278
- }
279
- return creditPayment;
280
- };
281
- // CreditPayments.logUnlockMessage = async (
282
- // user: PhoneUser,
283
- // owner: PhoneOwner,
284
- // message: Message,
285
- // alreadyPaid?: boolean,
286
- // transaction?: Transaction,
287
- // invoiceId?: string
288
- // ) => {
289
- // if (message.amountInCents! > user.creditsInCents! && !alreadyPaid) {
290
- // throw new Error(`Sorry, it looks like you've run out of credits`);
291
- // }
292
- // if (!message.amountInCents) {
293
- // throw new Error("Must contain message amount");
294
- // }
295
- // if (message.amountInCents! < 0) {
296
- // throw new Error("Cannot be less than 0");
297
- // }
298
- // if (!alreadyPaid) {
299
- // user.creditsInCents = user.creditsInCents! - message.amountInCents!;
300
- // await user.save({ transaction });
301
- // }
302
- // let creditPayment = await CreditPayments.create(
303
- // {
304
- // userId: user.id,
305
- // ownerId: owner.id,
306
- // creditAmountInCents: message.amountInCents!,
307
- // earningAmountInCents: earningsAmount(
308
- // message.amountInCents!,
309
- // owner.serviceFeePercentage
310
- // ),
311
- // invoiceId,
312
- // interactionType: INTERACTION_TYPES.UNLOCK_MESSAGE,
313
- // },
314
- // { transaction }
315
- // );
316
- // try {
317
- // await Notification.create(
318
- // {
319
- // ownerId: owner.id,
320
- // userId: user.id,
321
- // creditPaymentId: creditPayment.id,
322
- // type: "unlock_message",
323
- // messageId: message.id,
324
- // },
325
- // { transaction }
326
- // );
327
- // } catch (err) {
328
- // console.log(err);
329
- // }
330
- // if (owner.referringOwnerId) {
331
- // await createReferralPayment(
332
- // owner,
333
- // creditPayment,
334
- // message.amountInCents!,
335
- // transaction
336
- // );
337
- // }
338
- // return creditPayment;
339
- // };
340
- CreditPayments.logUnlockedContent = async (user, owner, lockedContent) => {
341
- if (lockedContent.amountInCents < 0) {
342
- throw new Error("Cannot be less than 0");
343
- }
344
- if (lockedContent.amountInCents > user.creditsInCents) {
345
- let url = await getPaymentUrl(user, owner);
346
- throw new Error(`Sorry, it looks like you've run out of credits. To unlock this content, add more credits here: ${url}`);
347
- }
348
- user.creditsInCents = user.creditsInCents - lockedContent.amountInCents;
349
- await user.save();
350
- let creditPayment = await CreditPayments.create({
351
- userId: user.id,
352
- ownerId: owner.id,
353
- creditAmountInCents: lockedContent.amountInCents,
354
- earningAmountInCents: earningsAmount(lockedContent.amountInCents, owner.serviceFeePercentage),
355
- interactionType: INTERACTION_TYPES.UNLOCK,
356
- });
357
- if (owner.referringOwnerId) {
358
- await createReferralPayment(owner, creditPayment, lockedContent.amountInCents);
359
- }
360
- if (user.referringOwnerId) {
361
- await createUserReferralPayment(user, creditPayment, lockedContent.amountInCents);
362
- }
363
- return creditPayment;
364
- };
365
- CreditPayments.logSubscriptionPayment = async (userId, owner, subscriptionAmountInCents, subscription, transaction, invoiceId) => {
366
- let creditPayment = await CreditPayments.create({
367
- userId: userId,
368
- ownerId: owner.id,
369
- creditAmountInCents: subscriptionAmountInCents,
370
- earningAmountInCents: earningsAmount(subscriptionAmountInCents, owner.serviceFeePercentage),
371
- interactionType: INTERACTION_TYPES.SUBSCRIPTION,
372
- metadata: JSON.stringify({ subscription_id: subscription.id }),
373
- invoiceId,
374
- }, { transaction });
375
- try {
376
- if (owner.referringOwnerId) {
377
- await createReferralPayment(owner, creditPayment, subscriptionAmountInCents, transaction);
378
- }
379
- const user = await phone_user_1.default.getById(userId);
380
- if (user && user.referringOwnerId) {
381
- await createUserReferralPayment(user, creditPayment, subscriptionAmountInCents, transaction);
382
- }
383
- }
384
- catch (err) {
385
- console.log(err);
386
- console.log("Issue creating referral payment");
387
- }
388
- return creditPayment;
389
- };
390
- const earningsAmount = (amount, serviceFeePercentage) => {
391
- return Math.floor(amount * (1 - (serviceFeePercentage || 0.2)));
392
- };
393
- const createReferralPayment = async (owner, creditPayment, creditAmount, transaction) => {
394
- return await CreditPayments.create({
395
- ownerId: owner.referringOwnerId,
396
- creditAmountInCents: creditAmount,
397
- earningAmountInCents: Math.floor(creditAmount * (owner.referralPercentage || REFERRAL_PERCENTAGE)),
398
- interactionType: INTERACTION_TYPES.REFERRAL,
399
- referredCreditPaymentId: creditPayment.id,
400
- }, { transaction });
401
- };
402
- const createUserReferralPayment = async (user, creditPayment, creditAmount, transaction) => {
403
- return await CreditPayments.create({
404
- ownerId: user.referringOwnerId,
405
- creditAmountInCents: creditAmount,
406
- earningAmountInCents: Math.floor(creditAmount * 0.04),
407
- interactionType: INTERACTION_TYPES.REFERRAL,
408
- referredCreditPaymentId: creditPayment.id,
409
- }, { transaction });
410
- };
411
- const getPaymentUrl = async (user, owner) => {
412
- let name = owner.name && owner.name.toLowerCase().replace(/\s+/g, "-");
413
- return `https://${process.env.SITE_DOMAIN}/${name}`;
414
- };
415
- phone_owner_1.default.hasMany(CreditPayments, {
416
- foreignKey: "owner_id",
79
+ user_1.default.hasMany(Transaction, {
80
+ foreignKey: "payer_id",
417
81
  onDelete: "NO ACTION",
418
82
  constraints: false,
419
83
  });
420
- phone_user_1.default.hasMany(CreditPayments, {
421
- foreignKey: "user_id",
84
+ Transaction.hasOne(user_1.default, {
85
+ foreignKey: "id",
86
+ sourceKey: "payer_id",
422
87
  onDelete: "NO ACTION",
423
88
  constraints: false,
424
89
  });
425
- CreditPayments.hasOne(phone_owner_1.default, {
426
- foreignKey: "id",
427
- sourceKey: "owner_id",
90
+ user_1.default.hasMany(Transaction, {
91
+ foreignKey: "recipient_id",
428
92
  onDelete: "NO ACTION",
429
93
  constraints: false,
430
94
  });
431
- CreditPayments.hasOne(phone_user_1.default, {
95
+ Transaction.hasOne(user_1.default, {
432
96
  foreignKey: "id",
433
- sourceKey: "user_id",
97
+ sourceKey: "recipient_id",
434
98
  onDelete: "NO ACTION",
435
99
  constraints: false,
436
100
  });
437
- notification_1.default.hasOne(CreditPayments, {
101
+ notification_1.default.hasOne(Transaction, {
438
102
  foreignKey: "id",
439
103
  sourceKey: "transactionId",
440
104
  constraints: false,
441
105
  onDelete: "NO ACTION",
442
106
  });
443
- exports.default = CreditPayments;
107
+ exports.default = Transaction;
444
108
  //# sourceMappingURL=credit-payment.js.map