agrs-sequelize-sdk 1.1.40 → 1.1.41

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 (2) hide show
  1. package/models/Channel.js +53 -19
  2. package/package.json +1 -1
package/models/Channel.js CHANGED
@@ -1,40 +1,74 @@
1
- module.exports = {
2
- up: async (queryInterface, Sequelize) => {
3
- await queryInterface.createTable("channels", {
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const Channel = sequelize.define(
3
+ "Channel",
4
+ {
4
5
  id: {
5
- type: Sequelize.INTEGER,
6
+ type: DataTypes.INTEGER,
6
7
  primaryKey: true,
7
8
  autoIncrement: true,
8
9
  },
9
10
  channelId: {
10
- type: Sequelize.STRING(255),
11
+ type: DataTypes.STRING(255), // Explicitly define length for VARCHAR(255)
11
12
  allowNull: false,
12
- unique: true,
13
+ comment: "Channel ID (e.g., ch123+ch456)",
13
14
  },
14
15
  styleId: {
15
- type: Sequelize.STRING,
16
+ type: DataTypes.STRING,
16
17
  allowNull: true,
17
18
  defaultValue: "3544685732",
19
+ comment: "Style ID (stid)",
18
20
  },
19
21
  connectedCampaigns: {
20
- type: Sequelize.JSON,
22
+ type: DataTypes.JSON,
21
23
  allowNull: true,
22
24
  defaultValue: [],
25
+ comment: "List of connected campaign AGRS_CID values",
23
26
  },
24
27
  createdAt: {
25
- type: Sequelize.DATE,
26
- allowNull: false,
27
- defaultValue: Sequelize.NOW,
28
+ type: DataTypes.DATE,
29
+ defaultValue: DataTypes.NOW,
28
30
  },
29
31
  updatedAt: {
30
- type: Sequelize.DATE,
31
- allowNull: false,
32
- defaultValue: Sequelize.NOW,
32
+ type: DataTypes.DATE,
33
+ defaultValue: DataTypes.NOW,
33
34
  },
35
+ },
36
+ {
37
+ tableName: "channels",
38
+ timestamps: true,
39
+ indexes: [
40
+ {
41
+ unique: true,
42
+ fields: ["channelId"], // Define UNIQUE constraint here instead of in the field
43
+ },
44
+ ],
45
+ }
46
+ );
47
+
48
+ Channel.associate = (models) => {
49
+ Channel.hasMany(models.RSOCFeedCampaign, {
50
+ foreignKey: "channelId",
51
+ sourceKey: "channelId",
52
+ as: "RSOCFeedCampaigns",
53
+ constraints: false,
54
+ });
55
+ };
56
+
57
+ Channel.afterCreate(async (channel, options) => {
58
+ const campaigns = await sequelize.models.RSOCFeedCampaign.findAll({
59
+ where: { channelId: channel.channelId },
60
+ });
61
+ const campaignIds = campaigns.map((campaign) => campaign.AGRS_CID);
62
+ await channel.update({ connectedCampaigns: campaignIds });
63
+ });
64
+
65
+ Channel.afterUpdate(async (channel, options) => {
66
+ const campaigns = await sequelize.models.RSOCFeedCampaign.findAll({
67
+ where: { channelId: channel.channelId },
34
68
  });
35
- await queryInterface.addIndex("channels", ["channelId"], { unique: true });
36
- },
37
- down: async (queryInterface) => {
38
- await queryInterface.dropTable("channels");
39
- },
69
+ const campaignIds = campaigns.map((campaign) => campaign.AGRS_CID);
70
+ await channel.update({ connectedCampaigns: campaignIds });
71
+ });
72
+
73
+ return Channel;
40
74
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.1.40",
3
+ "version": "1.1.41",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",