agrs-sequelize-sdk 1.1.40 → 1.1.42

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 +48 -19
  2. package/package.json +1 -1
package/models/Channel.js CHANGED
@@ -1,40 +1,69 @@
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), // הגדרה מפורשת של VARCHAR(255)
11
12
  allowNull: false,
12
- unique: true,
13
+ unique: true, // חזרה להגדרת unique בשדה עצמו
14
+ comment: "Channel ID (e.g., ch123+ch456)",
13
15
  },
14
16
  styleId: {
15
- type: Sequelize.STRING,
17
+ type: DataTypes.STRING,
16
18
  allowNull: true,
17
19
  defaultValue: "3544685732",
20
+ comment: "Style ID (stid)",
18
21
  },
19
22
  connectedCampaigns: {
20
- type: Sequelize.JSON,
23
+ type: DataTypes.JSON,
21
24
  allowNull: true,
22
25
  defaultValue: [],
26
+ comment: "List of connected campaign AGRS_CID values",
23
27
  },
24
28
  createdAt: {
25
- type: Sequelize.DATE,
26
- allowNull: false,
27
- defaultValue: Sequelize.NOW,
29
+ type: DataTypes.DATE,
30
+ defaultValue: DataTypes.NOW,
28
31
  },
29
32
  updatedAt: {
30
- type: Sequelize.DATE,
31
- allowNull: false,
32
- defaultValue: Sequelize.NOW,
33
+ type: DataTypes.DATE,
34
+ defaultValue: DataTypes.NOW,
33
35
  },
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 },
34
63
  });
35
- await queryInterface.addIndex("channels", ["channelId"], { unique: true });
36
- },
37
- down: async (queryInterface) => {
38
- await queryInterface.dropTable("channels");
39
- },
64
+ const campaignIds = campaigns.map((campaign) => campaign.AGRS_CID);
65
+ await channel.update({ connectedCampaigns: campaignIds });
66
+ });
67
+
68
+ return Channel;
40
69
  };
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.42",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",