agrs-sequelize-sdk 1.1.18 → 1.1.20

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.
@@ -63,21 +63,28 @@ module.exports = (sequelize, DataTypes) => {
63
63
  ],
64
64
  hooks: {
65
65
  beforeCreate: async (record, options) => {
66
- const existingKeyword =
67
- await sequelize.models.KeywordPerformance.findOne({
68
- where: {
69
- Keyword: sequelize.where(
70
- sequelize.fn("LOWER", sequelize.col("Keyword")),
71
- sequelize.fn("LOWER", record.Keyword)
72
- ),
73
- },
74
- order: [["Date", "ASC"]],
75
- attributes: ["FirstAppearanceDate"],
76
- transaction: options.transaction,
77
- });
66
+ try {
67
+ // Find existing record for this keyword
68
+ const existingKeyword =
69
+ await sequelize.models.KeywordPerformance.findOne({
70
+ where: {
71
+ Keyword: sequelize.where(
72
+ sequelize.fn("LOWER", sequelize.col("Keyword")),
73
+ sequelize.fn("LOWER", record.Keyword)
74
+ ),
75
+ },
76
+ attributes: ["FirstAppearanceDate"],
77
+ transaction: options.transaction,
78
+ });
78
79
 
79
- record.FirstAppearanceDate =
80
- existingKeyword?.FirstAppearanceDate || record.Date;
80
+ // If keyword exists, use its FirstAppearanceDate
81
+ // If not, use the current record's Date
82
+ record.FirstAppearanceDate =
83
+ existingKeyword?.FirstAppearanceDate || record.Date;
84
+ } catch (error) {
85
+ console.error("Error in FirstAppearanceDate hook:", error);
86
+ throw error;
87
+ }
81
88
  },
82
89
  },
83
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.1.18",
3
+ "version": "1.1.20",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",