feat: Implement Phase 2 cross-cutting services with email and notification enhancements

- Refactor email verification and password reset utilities to use new email service.
- Introduce email delivery queue and notification delivery model for better tracking.
- Enhance file validation and storage services for improved security and ownership management.
- Add cron job for cleaning inactive notifications with retention policy.
- Update document worker to handle document generation and storage more efficiently.
- Implement logging improvements in activity and log workers.
- Create comprehensive documentation for new API endpoints and services.
- Add unit tests for file validation and notification policies to ensure robustness.
This commit is contained in:
Sathira Sri Sathara
2026-09-03 14:22:34 +05:30
parent 9d3d431416
commit b6b345f245
54 changed files with 593 additions and 1248 deletions
@@ -18,9 +18,10 @@ module.exports = (sequelize, DataTypes) => {
autoIncrement: true,
primaryKey: true,
},
event_id: { type: DataTypes.STRING, allowNull: true, unique: true },
user_id: {
type: DataTypes.STRING,
allowNull: false,
allowNull: true,
},
username: {
type: DataTypes.STRING,
@@ -45,13 +46,17 @@ module.exports = (sequelize, DataTypes) => {
activity_date:{
type: DataTypes.DATEONLY,
allowNull: false,
}
},
target_type: DataTypes.STRING, target_id: DataTypes.STRING,
ip_address: DataTypes.STRING, user_agent: DataTypes.STRING, request_id: DataTypes.STRING,
metadata: DataTypes.JSON, occurred_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
},
{
tableName: "UserActivity",
timestamps: true,
},
);
UserActivity.associate = (models) => UserActivity.belongsTo(models.User, { foreignKey: "user_id", as: "actor", constraints: false });
return UserActivity;
};
+10 -2
View File
@@ -14,7 +14,7 @@ module.exports = (sequelize, DataTypes) => {
"Document",
{
doc_id:{
type: DataTypes.STRING,
type: DataTypes.ENUM("DRAFT", "QUEUED", "PROCESSING", "COMPLETED", "FAILED"),
primaryKey: true,
},
reference_no: {
@@ -34,13 +34,21 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.STRING,
allowNull: false,
defaultValue: "DRAFT",
}
},
created_by: { type: DataTypes.STRING, allowNull: false },
owner_type: { type: DataTypes.STRING, allowNull: false, defaultValue: "USER" },
owner_id: { type: DataTypes.STRING, allowNull: false },
storage_upload_id: { type: DataTypes.INTEGER, allowNull: true },
job_id: { type: DataTypes.STRING, allowNull: true, unique: true },
generated_at: DataTypes.DATE, failed_at: DataTypes.DATE, failure_code: DataTypes.STRING,
version: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 1 },
},
{
tableName: "Document",
timestamps: true,
},
);
document.associate = (models) => { document.belongsTo(models.User, { foreignKey: "created_by", as: "creator", constraints: false }); document.belongsTo(models.Upload, { foreignKey: "storage_upload_id", as: "storageUpload", constraints: false }); };
return document;
};
+2 -2
View File
@@ -20,8 +20,8 @@ module.exports = (sequelize, DataTypes) => {
},
doc_type_name: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: "N/A"
allowNull: false,
unique: true,
},
description: {
type: DataTypes.JSON,
+1
View File
@@ -64,6 +64,7 @@ db.referenceNumber = require("./referenceNumbers/referenceNumber.model")(sequeli
// Notifications
db.notification = require("./notification/notification.model")(sequelize, DataTypes);
db.userNotification = require("./notification/userNotification.model")(sequelize, DataTypes);
db.NotificationDelivery = require("./notification/notificationDelivery.model")(sequelize, DataTypes);
/* Associations */
Object.keys(db).forEach(model => {
@@ -0,0 +1,11 @@
module.exports = (sequelize, DataTypes) => sequelize.define("NotificationDelivery", {
id: { type: DataTypes.STRING, primaryKey: true },
notificationId: { type: DataTypes.STRING, allowNull: true },
userId: { type: DataTypes.STRING, allowNull: true },
channel: { type: DataTypes.ENUM("EMAIL", "PUSH"), allowNull: false },
recipient: { type: DataTypes.STRING, allowNull: false },
templateKey: { type: DataTypes.STRING, allowNull: false },
status: { type: DataTypes.ENUM("QUEUED", "PROCESSING", "SENT", "FAILED"), allowNull: false, defaultValue: "QUEUED" },
attemptCount: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 },
lastAttemptAt: DataTypes.DATE, sentAt: DataTypes.DATE, failedAt: DataTypes.DATE, failureCode: DataTypes.STRING,
}, { tableName: "notification_deliveries", timestamps: true });
@@ -41,11 +41,13 @@ module.exports = (sequelize, DataTypes) => {
userNotification.associate = (models) => {
userNotification.belongsTo(models.User, {
foreignKey: "user_id",
as: "user",
constraints: false,
});
userNotification.belongsTo(models.notification, {
foreignKey: "notification_id",
as: "notification",
constraints: false,
});
};
+9
View File
@@ -43,12 +43,21 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.STRING,
allowNull: false,
},
storage_provider: { type: DataTypes.STRING, allowNull: false, defaultValue: "S3" },
safe_name: { type: DataTypes.STRING, allowNull: true },
checksum: { type: DataTypes.STRING(64), allowNull: true },
owner_type: { type: DataTypes.STRING, allowNull: false, defaultValue: "USER" },
owner_id: { type: DataTypes.STRING, allowNull: false },
visibility: { type: DataTypes.ENUM("PRIVATE", "PUBLIC"), allowNull: false, defaultValue: "PRIVATE" },
status: { type: DataTypes.ENUM("PENDING", "AVAILABLE", "FAILED", "DELETED"), allowNull: false, defaultValue: "PENDING" },
deletedAt: { type: DataTypes.DATE, allowNull: true },
},
{
tableName: "uploads",
timestamps: true,
},
);
upload.associate = (models) => upload.belongsTo(models.User, { foreignKey: "uploaded_by", as: "uploader", constraints: false });
return upload;
};