agrs-sequelize-sdk 1.1.50 → 1.1.51

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 +9 -47
  2. package/package.json +1 -1
package/models/Channel.js CHANGED
@@ -1,35 +1,28 @@
1
- // models/Channel.js (partial)
2
1
  module.exports = (sequelize, DataTypes) => {
3
2
  const Channel = sequelize.define(
4
3
  "Channel",
5
4
  {
6
- id: {
7
- type: DataTypes.INTEGER,
8
- primaryKey: true,
9
- autoIncrement: true,
10
- },
11
5
  channelId: {
12
- type: DataTypes.STRING(255),
6
+ type: DataTypes.STRING,
13
7
  allowNull: false,
14
- unique: "channel_style_unique",
8
+ // Remove unique: true here if it exists
15
9
  },
16
10
  styleId: {
17
11
  type: DataTypes.STRING,
18
- allowNull: false, // Ensure this is not null if part of the unique constraint
19
- unique: "channel_style_unique",
12
+ allowNull: false,
20
13
  },
21
14
  status: {
22
15
  type: DataTypes.STRING,
23
16
  allowNull: false,
24
17
  defaultValue: "free",
25
18
  validate: {
26
- isIn: [["free", "used"]],
19
+ isIn: [["free", "used", "archived"]],
27
20
  },
28
21
  },
29
22
  connectedCampaigns: {
30
- type: DataTypes.JSON,
31
- allowNull: true,
32
- defaultValue: [], // Must be a valid array
23
+ type: DataTypes.JSONB,
24
+ allowNull: false,
25
+ defaultValue: [],
33
26
  },
34
27
  createdAt: {
35
28
  type: DataTypes.DATE,
@@ -44,10 +37,11 @@ module.exports = (sequelize, DataTypes) => {
44
37
  tableName: "channels",
45
38
  timestamps: true,
46
39
  indexes: [
40
+ // Add a unique index on the combination of channelId and styleId
47
41
  {
48
42
  unique: true,
49
43
  fields: ["channelId", "styleId"],
50
- name: "channel_style_unique",
44
+ name: "channels_channelId_styleId_unique",
51
45
  },
52
46
  ],
53
47
  }
@@ -58,40 +52,8 @@ module.exports = (sequelize, DataTypes) => {
58
52
  foreignKey: "channelId",
59
53
  sourceKey: "channelId",
60
54
  as: "RSOCFeedCampaigns",
61
- constraints: false,
62
55
  });
63
56
  };
64
57
 
65
- // Hook to update status and history when a channel is created or updated
66
- Channel.afterCreate(async (channel, options) => {
67
- const campaigns = await sequelize.models.RSOCFeedCampaign.findAll({
68
- where: { channelId: channel.channelId },
69
- });
70
- const campaignIds = campaigns.map((campaign) => ({
71
- campaignId: campaign.AGRS_CID,
72
- assignedAt: new Date(),
73
- releasedAt: null,
74
- }));
75
- if (campaignIds.length > 0) {
76
- await channel.update({ status: "used", connectedCampaigns: campaignIds });
77
- }
78
- });
79
-
80
- Channel.afterUpdate(async (channel, options) => {
81
- const campaigns = await sequelize.models.RSOCFeedCampaign.findAll({
82
- where: { channelId: channel.channelId },
83
- });
84
- const campaignIds = campaigns.map((campaign) => ({
85
- campaignId: campaign.AGRS_CID,
86
- assignedAt: new Date(),
87
- releasedAt: null,
88
- }));
89
- if (campaignIds.length > 0) {
90
- await channel.update({ status: "used", connectedCampaigns: campaignIds });
91
- } else {
92
- await channel.update({ status: "free", connectedCampaigns: [] });
93
- }
94
- });
95
-
96
58
  return Channel;
97
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.1.50",
3
+ "version": "1.1.51",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",