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.
- package/models/Channel.js +53 -19
- package/package.json +1 -1
package/models/Channel.js
CHANGED
|
@@ -1,40 +1,74 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
module.exports = (sequelize, DataTypes) => {
|
|
2
|
+
const Channel = sequelize.define(
|
|
3
|
+
"Channel",
|
|
4
|
+
{
|
|
4
5
|
id: {
|
|
5
|
-
type:
|
|
6
|
+
type: DataTypes.INTEGER,
|
|
6
7
|
primaryKey: true,
|
|
7
8
|
autoIncrement: true,
|
|
8
9
|
},
|
|
9
10
|
channelId: {
|
|
10
|
-
type:
|
|
11
|
+
type: DataTypes.STRING(255), // Explicitly define length for VARCHAR(255)
|
|
11
12
|
allowNull: false,
|
|
12
|
-
|
|
13
|
+
comment: "Channel ID (e.g., ch123+ch456)",
|
|
13
14
|
},
|
|
14
15
|
styleId: {
|
|
15
|
-
type:
|
|
16
|
+
type: DataTypes.STRING,
|
|
16
17
|
allowNull: true,
|
|
17
18
|
defaultValue: "3544685732",
|
|
19
|
+
comment: "Style ID (stid)",
|
|
18
20
|
},
|
|
19
21
|
connectedCampaigns: {
|
|
20
|
-
type:
|
|
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:
|
|
26
|
-
|
|
27
|
-
defaultValue: Sequelize.NOW,
|
|
28
|
+
type: DataTypes.DATE,
|
|
29
|
+
defaultValue: DataTypes.NOW,
|
|
28
30
|
},
|
|
29
31
|
updatedAt: {
|
|
30
|
-
type:
|
|
31
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
69
|
+
const campaignIds = campaigns.map((campaign) => campaign.AGRS_CID);
|
|
70
|
+
await channel.update({ connectedCampaigns: campaignIds });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return Channel;
|
|
40
74
|
};
|