agrs-sequelize-sdk 1.1.39 → 1.1.40

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