diff --git a/src/api/controllers/integrationController.js b/src/api/controllers/integrationController.js index 1911e1d..f619a2f 100644 --- a/src/api/controllers/integrationController.js +++ b/src/api/controllers/integrationController.js @@ -908,7 +908,7 @@ async function getPerformanceData(req, res) { const getUserReport = async (req, res) => { try { const { sdate, edate, dateFormat, startIndex } = req.query; - const userId = req.user.id; + const userId = req.user.uuid; const zohoClient = new ZohoClient(userId); const attendanceReport = await zohoClient.getUserReport({ @@ -927,7 +927,7 @@ const getUserReport = async (req, res) => { // Get leave tracker report const getLeaveTrackerReport = async (req, res) => { try { - const userId = req.user.id; + const userId = req.user.uuid; const zohoClient = new ZohoClient(userId); const leaveTrackerReport = await zohoClient.getLeaveTrackerReport(); @@ -941,7 +941,7 @@ const getLeaveTrackerReport = async (req, res) => { // Get holidays const getHolidays = async (req, res) => { try { - const userId = req.user.id; + const userId = req.user.uuid; const zohoClient = new ZohoClient(userId); const holidays = await zohoClient.getHolidays(); diff --git a/src/api/controllers/reportsController.js b/src/api/controllers/reportsController.js index 8b3a149..b079d29 100644 --- a/src/api/controllers/reportsController.js +++ b/src/api/controllers/reportsController.js @@ -20,7 +20,7 @@ class ReportsController { // Base filters const baseFilters = { - user_id: userId, + user_uuid: userId, provider: 'zoho', ...dateFilter, ...ownerFilter diff --git a/src/api/controllers/userController.js b/src/api/controllers/userController.js index b674e88..42594b8 100644 --- a/src/api/controllers/userController.js +++ b/src/api/controllers/userController.js @@ -58,7 +58,7 @@ async function exchangeZohoToken(req, res) { const expiresAt = expires_in ? new Date(Date.now() + expires_in * 1000) : null; await userAuthTokenRepo.upsertToken({ - userId: id, + userUuid: id, serviceName: service_name, accessToken: encrypt(access_token), refreshToken: refresh_token? encrypt(refresh_token) : null, diff --git a/src/data/models/userAuthToken.js b/src/data/models/userAuthToken.js index c31ee7a..c785f4a 100644 --- a/src/data/models/userAuthToken.js +++ b/src/data/models/userAuthToken.js @@ -7,11 +7,11 @@ class UserAuthToken extends Model {} UserAuthToken.init( { id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true }, - userId: { - field: 'user_id', - type: DataTypes.INTEGER, + userUuid: { + field: 'user_uuid', + type: DataTypes.CHAR(36), allowNull: false, - references: { model: 'users', key: 'id' }, + references: { model: 'users', key: 'uuid' }, onDelete: 'CASCADE' }, serviceName: { @@ -32,13 +32,13 @@ UserAuthToken.init( timestamps: true, paranoid: false, indexes: [ - { fields: ['user_id'] }, + { fields: ['user_uuid'] }, { fields: ['service_name'] } ] } ); -UserAuthToken.belongsTo(User, { foreignKey: 'userId', as: 'user' }); +UserAuthToken.belongsTo(User, { foreignKey: 'userUuid', as: 'user' }); module.exports = UserAuthToken; diff --git a/src/data/models/zohoAccountsBulk.js b/src/data/models/zohoAccountsBulk.js index 16ae79f..bc6416e 100644 --- a/src/data/models/zohoAccountsBulk.js +++ b/src/data/models/zohoAccountsBulk.js @@ -12,8 +12,8 @@ const ZohoAccountsBulk = sequelize.define('ZohoAccountsBulk', { type: DataTypes.STRING(255), allowNull: true }, - user_id: { - type: DataTypes.STRING(255), + user_uuid: { + type: DataTypes.CHAR(36), allowNull: false }, provider: { @@ -63,7 +63,7 @@ const ZohoAccountsBulk = sequelize.define('ZohoAccountsBulk', { createdAt: 'created_at', updatedAt: 'updated_at', indexes: [ - { fields: ['user_id', 'provider'] }, + { fields: ['user_uuid', 'provider'] }, { fields: ['bulk_job_id'] }, { fields: ['created_time'] } ] diff --git a/src/data/models/zohoBulkReadJobs.js b/src/data/models/zohoBulkReadJobs.js index 10dda9a..7489bc3 100644 --- a/src/data/models/zohoBulkReadJobs.js +++ b/src/data/models/zohoBulkReadJobs.js @@ -7,8 +7,8 @@ const ZohoBulkReadJobs = sequelize.define('ZohoBulkReadJobs', { primaryKey: true, allowNull: false }, - user_id: { - type: DataTypes.STRING(255), + user_uuid: { + type: DataTypes.CHAR(36), allowNull: false }, provider: { @@ -61,7 +61,7 @@ const ZohoBulkReadJobs = sequelize.define('ZohoBulkReadJobs', { createdAt: 'created_at', updatedAt: 'updated_at', indexes: [ - { fields: ['user_id', 'provider'] }, + { fields: ['user_uuid', 'provider'] }, { fields: ['module'] }, { fields: ['status'] } ] diff --git a/src/data/models/zohoContactsBulk.js b/src/data/models/zohoContactsBulk.js index ee60b2f..dab0fcb 100644 --- a/src/data/models/zohoContactsBulk.js +++ b/src/data/models/zohoContactsBulk.js @@ -12,8 +12,8 @@ const ZohoContactsBulk = sequelize.define('ZohoContactsBulk', { type: DataTypes.STRING(255), allowNull: true }, - user_id: { - type: DataTypes.STRING(255), + user_uuid: { + type: DataTypes.CHAR(36), allowNull: false }, provider: { @@ -71,7 +71,7 @@ const ZohoContactsBulk = sequelize.define('ZohoContactsBulk', { createdAt: 'created_at', updatedAt: 'updated_at', indexes: [ - { fields: ['user_id', 'provider'] }, + { fields: ['user_uuid', 'provider'] }, { fields: ['bulk_job_id'] }, { fields: ['created_time'] } ] diff --git a/src/data/models/zohoInvoicesBulk.js b/src/data/models/zohoInvoicesBulk.js index abd2864..6eef497 100644 --- a/src/data/models/zohoInvoicesBulk.js +++ b/src/data/models/zohoInvoicesBulk.js @@ -12,8 +12,8 @@ const ZohoInvoicesBulk = sequelize.define('ZohoInvoicesBulk', { type: DataTypes.STRING(255), allowNull: true }, - user_id: { - type: DataTypes.STRING(255), + user_uuid: { + type: DataTypes.CHAR(36), allowNull: false }, provider: { @@ -67,7 +67,7 @@ const ZohoInvoicesBulk = sequelize.define('ZohoInvoicesBulk', { createdAt: 'created_at', updatedAt: 'updated_at', indexes: [ - { fields: ['user_id', 'provider'] }, + { fields: ['user_uuid', 'provider'] }, { fields: ['bulk_job_id'] }, { fields: ['created_time'] } ] diff --git a/src/data/models/zohoLeadsBulk.js b/src/data/models/zohoLeadsBulk.js index 4f7e090..1ac830f 100644 --- a/src/data/models/zohoLeadsBulk.js +++ b/src/data/models/zohoLeadsBulk.js @@ -12,8 +12,8 @@ const ZohoLeadsBulk = sequelize.define('ZohoLeadsBulk', { type: DataTypes.STRING(255), allowNull: true }, - user_id: { - type: DataTypes.STRING(255), + user_uuid: { + type: DataTypes.CHAR(36), allowNull: false }, provider: { @@ -67,7 +67,7 @@ const ZohoLeadsBulk = sequelize.define('ZohoLeadsBulk', { createdAt: 'created_at', updatedAt: 'updated_at', indexes: [ - { fields: ['user_id', 'provider'] }, + { fields: ['user_uuid', 'provider'] }, { fields: ['bulk_job_id'] }, { fields: ['created_time'] } ] diff --git a/src/data/models/zohoPurchaseOrdersBulk.js b/src/data/models/zohoPurchaseOrdersBulk.js index a2fe48e..7750794 100644 --- a/src/data/models/zohoPurchaseOrdersBulk.js +++ b/src/data/models/zohoPurchaseOrdersBulk.js @@ -12,8 +12,8 @@ const ZohoPurchaseOrdersBulk = sequelize.define('ZohoPurchaseOrdersBulk', { type: DataTypes.STRING(255), allowNull: true }, - user_id: { - type: DataTypes.STRING(255), + user_uuid: { + type: DataTypes.CHAR(36), allowNull: false }, provider: { @@ -63,7 +63,7 @@ const ZohoPurchaseOrdersBulk = sequelize.define('ZohoPurchaseOrdersBulk', { createdAt: 'created_at', updatedAt: 'updated_at', indexes: [ - { fields: ['user_id', 'provider'] }, + { fields: ['user_uuid', 'provider'] }, { fields: ['bulk_job_id'] }, { fields: ['created_time'] } ] diff --git a/src/data/models/zohoSalesOrdersBulk.js b/src/data/models/zohoSalesOrdersBulk.js index 61d17b1..b1f55a8 100644 --- a/src/data/models/zohoSalesOrdersBulk.js +++ b/src/data/models/zohoSalesOrdersBulk.js @@ -12,8 +12,8 @@ const ZohoSalesOrdersBulk = sequelize.define('ZohoSalesOrdersBulk', { type: DataTypes.STRING(255), allowNull: true }, - user_id: { - type: DataTypes.STRING(255), + user_uuid: { + type: DataTypes.CHAR(36), allowNull: false }, provider: { @@ -63,7 +63,7 @@ const ZohoSalesOrdersBulk = sequelize.define('ZohoSalesOrdersBulk', { createdAt: 'created_at', updatedAt: 'updated_at', indexes: [ - { fields: ['user_id', 'provider'] }, + { fields: ['user_uuid', 'provider'] }, { fields: ['bulk_job_id'] }, { fields: ['created_time'] } ] diff --git a/src/data/models/zohoTasksBulk.js b/src/data/models/zohoTasksBulk.js index ef1e785..29bb31a 100644 --- a/src/data/models/zohoTasksBulk.js +++ b/src/data/models/zohoTasksBulk.js @@ -12,8 +12,8 @@ const ZohoTasksBulk = sequelize.define('ZohoTasksBulk', { type: DataTypes.STRING(255), allowNull: true }, - user_id: { - type: DataTypes.STRING(255), + user_uuid: { + type: DataTypes.CHAR(36), allowNull: false }, provider: { @@ -59,7 +59,7 @@ const ZohoTasksBulk = sequelize.define('ZohoTasksBulk', { createdAt: 'created_at', updatedAt: 'updated_at', indexes: [ - { fields: ['user_id', 'provider'] }, + { fields: ['user_uuid', 'provider'] }, { fields: ['bulk_job_id'] }, { fields: ['created_time'] } ] diff --git a/src/data/models/zohoVendorsBulk.js b/src/data/models/zohoVendorsBulk.js index 4675458..aec7bd4 100644 --- a/src/data/models/zohoVendorsBulk.js +++ b/src/data/models/zohoVendorsBulk.js @@ -12,8 +12,8 @@ const ZohoVendorsBulk = sequelize.define('ZohoVendorsBulk', { type: DataTypes.STRING(255), allowNull: true }, - user_id: { - type: DataTypes.STRING(255), + user_uuid: { + type: DataTypes.CHAR(36), allowNull: false }, provider: { @@ -55,7 +55,7 @@ const ZohoVendorsBulk = sequelize.define('ZohoVendorsBulk', { createdAt: 'created_at', updatedAt: 'updated_at', indexes: [ - { fields: ['user_id', 'provider'] }, + { fields: ['user_uuid', 'provider'] }, { fields: ['bulk_job_id'] }, { fields: ['created_time'] } ] diff --git a/src/data/repositories/userAuthTokenRepository.js b/src/data/repositories/userAuthTokenRepository.js index a709e2e..ff755d2 100644 --- a/src/data/repositories/userAuthTokenRepository.js +++ b/src/data/repositories/userAuthTokenRepository.js @@ -4,14 +4,14 @@ async function createToken(payload) { return UserAuthToken.create(payload); } -async function findByUserAndService(userId, serviceName) { - return UserAuthToken.findOne({ where: { userId, serviceName } }); +async function findByUserAndService(userUuid, serviceName) { + return UserAuthToken.findOne({ where: { userUuid, serviceName } }); } async function upsertToken(payload) { - const { userId, serviceName } = payload; + const { userUuid, serviceName } = payload; const [token, created] = await UserAuthToken.findOrCreate({ - where: { userId, serviceName }, + where: { userUuid, serviceName }, defaults: payload }); if (!created) { diff --git a/src/data/repositories/zohoBulkReadRepository.js b/src/data/repositories/zohoBulkReadRepository.js index 3ce9ead..de5f0ad 100644 --- a/src/data/repositories/zohoBulkReadRepository.js +++ b/src/data/repositories/zohoBulkReadRepository.js @@ -73,7 +73,7 @@ class ZohoBulkReadRepository { const result = await model.destroy({ where: { - user_id: userId, + user_uuid: userId, provider: 'zoho', bulk_job_id: jobId } @@ -101,7 +101,7 @@ class ZohoBulkReadRepository { const records = await model.findAll({ where: { - user_id: userId, + user_uuid: userId, provider: 'zoho' }, limit: parseInt(limit), @@ -128,7 +128,7 @@ class ZohoBulkReadRepository { const count = await model.count({ where: { - user_id: userId, + user_uuid: userId, provider: 'zoho' } }); @@ -152,7 +152,7 @@ class ZohoBulkReadRepository { const job = await ZohoBulkReadJobs.create({ id: jobData.id, - user_id: jobData.user_id, + user_uuid: jobData.user_uuid, provider: 'zoho', module: jobData.module, operation: jobData.operation, @@ -224,7 +224,7 @@ class ZohoBulkReadRepository { const { limit = 50, offset = 0, status } = options; const whereClause = { - user_id: userId, + user_uuid: userId, provider: 'zoho' }; diff --git a/src/db/migrations/001_create_users.sql b/src/db/migrations/001_create_users.sql index a9c5503..8671a73 100644 --- a/src/db/migrations/001_create_users.sql +++ b/src/db/migrations/001_create_users.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS users ( - id INT AUTO_INCREMENT PRIMARY KEY, + id INT AUTO_INCREMENT, uuid CHAR(36) NOT NULL UNIQUE, email VARCHAR(255) NOT NULL UNIQUE, password_hash VARCHAR(255) NOT NULL, @@ -10,5 +10,7 @@ CREATE TABLE IF NOT EXISTS users ( is_active TINYINT(1) NOT NULL DEFAULT 1, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - deleted_at DATETIME NULL + deleted_at DATETIME NULL, + PRIMARY KEY (id), + UNIQUE KEY (uuid) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/src/db/migrations/002_create_user_auth_tokens.sql b/src/db/migrations/002_create_user_auth_tokens.sql index ec053b3..de99dd3 100644 --- a/src/db/migrations/002_create_user_auth_tokens.sql +++ b/src/db/migrations/002_create_user_auth_tokens.sql @@ -1,13 +1,13 @@ CREATE TABLE IF NOT EXISTS user_auth_tokens ( id INT AUTO_INCREMENT PRIMARY KEY, - user_id CHAR(36) NOT NULL, + user_uuid CHAR(36) NOT NULL, service_name ENUM('zoho','keka','bamboohr','hubspot','other') NOT NULL, access_token TEXT NOT NULL, refresh_token TEXT NULL, expires_at DATETIME NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - CONSTRAINT fk_user_auth_tokens_user FOREIGN KEY (user_id) REFERENCES users(uuid) ON DELETE CASCADE -); + CONSTRAINT fk_user_auth_tokens_user FOREIGN KEY (user_uuid) REFERENCES users(uuid) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/src/db/migrations/003_create_zoho_contacts_bulk.sql b/src/db/migrations/003_create_zoho_contacts_bulk.sql index 613e933..b86cace 100644 --- a/src/db/migrations/003_create_zoho_contacts_bulk.sql +++ b/src/db/migrations/003_create_zoho_contacts_bulk.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS zoho_contacts_bulk ( internal_id INT AUTO_INCREMENT PRIMARY KEY, zoho_id VARCHAR(255), - user_id VARCHAR(255) NOT NULL, + user_uuid CHAR(36) NOT NULL, provider VARCHAR(50) NOT NULL DEFAULT 'zoho', first_name VARCHAR(255), last_name VARCHAR(255), @@ -19,7 +19,8 @@ CREATE TABLE IF NOT EXISTS zoho_contacts_bulk ( bulk_job_id VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX idx_user_provider (user_id, provider), + INDEX idx_user_provider (user_uuid, provider), + CONSTRAINT fk_zoho_contacts_bulk_user FOREIGN KEY (user_uuid) REFERENCES users(uuid) ON DELETE CASCADE, INDEX idx_bulk_job (bulk_job_id), INDEX idx_created_time (created_time), INDEX idx_zoho_id (zoho_id) diff --git a/src/db/migrations/004_create_zoho_leads_bulk.sql b/src/db/migrations/004_create_zoho_leads_bulk.sql index 227bdfe..ecb6389 100644 --- a/src/db/migrations/004_create_zoho_leads_bulk.sql +++ b/src/db/migrations/004_create_zoho_leads_bulk.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS zoho_leads_bulk ( internal_id INT AUTO_INCREMENT PRIMARY KEY, zoho_id VARCHAR(255), - user_id VARCHAR(255) NOT NULL, + user_uuid CHAR(36) NOT NULL, provider VARCHAR(50) NOT NULL DEFAULT 'zoho', first_name VARCHAR(255), last_name VARCHAR(255), @@ -18,7 +18,8 @@ CREATE TABLE IF NOT EXISTS zoho_leads_bulk ( bulk_job_id VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX idx_user_provider (user_id, provider), + INDEX idx_user_provider (user_uuid, provider), + CONSTRAINT fk_zoho_leads_bulk_user FOREIGN KEY (user_uuid) REFERENCES users(uuid) ON DELETE CASCADE, INDEX idx_bulk_job (bulk_job_id), INDEX idx_created_time (created_time), INDEX idx_zoho_id (zoho_id) diff --git a/src/db/migrations/005_create_zoho_accounts_bulk.sql b/src/db/migrations/005_create_zoho_accounts_bulk.sql index f7a7c6a..851307d 100644 --- a/src/db/migrations/005_create_zoho_accounts_bulk.sql +++ b/src/db/migrations/005_create_zoho_accounts_bulk.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS zoho_accounts_bulk ( internal_id INT AUTO_INCREMENT PRIMARY KEY, zoho_id VARCHAR(255), - user_id VARCHAR(255) NOT NULL, + user_uuid CHAR(36) NOT NULL, provider VARCHAR(50) NOT NULL DEFAULT 'zoho', account_name VARCHAR(255), phone VARCHAR(255), @@ -17,7 +17,8 @@ CREATE TABLE IF NOT EXISTS zoho_accounts_bulk ( bulk_job_id VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX idx_user_provider (user_id, provider), + INDEX idx_user_provider (user_uuid, provider), + CONSTRAINT fk_zoho_accounts_bulk_user FOREIGN KEY (user_uuid) REFERENCES users(uuid) ON DELETE CASCADE, INDEX idx_bulk_job (bulk_job_id), INDEX idx_created_time (created_time), INDEX idx_zoho_id (zoho_id) diff --git a/src/db/migrations/006_create_zoho_tasks_bulk.sql b/src/db/migrations/006_create_zoho_tasks_bulk.sql index 8982f37..ff793ac 100644 --- a/src/db/migrations/006_create_zoho_tasks_bulk.sql +++ b/src/db/migrations/006_create_zoho_tasks_bulk.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS zoho_tasks_bulk ( internal_id INT AUTO_INCREMENT PRIMARY KEY, zoho_id VARCHAR(255), - user_id VARCHAR(255) NOT NULL, + user_uuid CHAR(36) NOT NULL, provider VARCHAR(50) NOT NULL DEFAULT 'zoho', subject VARCHAR(500), owner VARCHAR(255), @@ -16,7 +16,8 @@ CREATE TABLE IF NOT EXISTS zoho_tasks_bulk ( bulk_job_id VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX idx_user_provider (user_id, provider), + INDEX idx_user_provider (user_uuid, provider), + CONSTRAINT fk_zoho_tasks_bulk_user FOREIGN KEY (user_uuid) REFERENCES users(uuid) ON DELETE CASCADE, INDEX idx_bulk_job (bulk_job_id), INDEX idx_created_time (created_time), INDEX idx_zoho_id (zoho_id) diff --git a/src/db/migrations/007_create_zoho_vendors_bulk.sql b/src/db/migrations/007_create_zoho_vendors_bulk.sql index 8e08dfa..26228e1 100644 --- a/src/db/migrations/007_create_zoho_vendors_bulk.sql +++ b/src/db/migrations/007_create_zoho_vendors_bulk.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS zoho_vendors_bulk ( internal_id INT AUTO_INCREMENT PRIMARY KEY, zoho_id VARCHAR(255), - user_id VARCHAR(255) NOT NULL, + user_uuid CHAR(36) NOT NULL, provider VARCHAR(50) NOT NULL DEFAULT 'zoho', vendor_name VARCHAR(255), email VARCHAR(255), @@ -15,7 +15,8 @@ CREATE TABLE IF NOT EXISTS zoho_vendors_bulk ( bulk_job_id VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX idx_user_provider (user_id, provider), + INDEX idx_user_provider (user_uuid, provider), + CONSTRAINT fk_zoho_vendors_bulk_user FOREIGN KEY (user_uuid) REFERENCES users(uuid) ON DELETE CASCADE, INDEX idx_bulk_job (bulk_job_id), INDEX idx_created_time (created_time), INDEX idx_zoho_id (zoho_id) diff --git a/src/db/migrations/008_create_zoho_invoices_bulk.sql b/src/db/migrations/008_create_zoho_invoices_bulk.sql index 2ce5260..395d16b 100644 --- a/src/db/migrations/008_create_zoho_invoices_bulk.sql +++ b/src/db/migrations/008_create_zoho_invoices_bulk.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS zoho_invoices_bulk ( internal_id INT AUTO_INCREMENT PRIMARY KEY, zoho_id VARCHAR(255), - user_id VARCHAR(255) NOT NULL, + user_uuid CHAR(36) NOT NULL, provider VARCHAR(50) NOT NULL DEFAULT 'zoho', invoice_number VARCHAR(255), invoice_date DATE, @@ -18,7 +18,8 @@ CREATE TABLE IF NOT EXISTS zoho_invoices_bulk ( bulk_job_id VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX idx_user_provider (user_id, provider), + INDEX idx_user_provider (user_uuid, provider), + CONSTRAINT fk_zoho_invoices_bulk_user FOREIGN KEY (user_uuid) REFERENCES users(uuid) ON DELETE CASCADE, INDEX idx_bulk_job (bulk_job_id), INDEX idx_created_time (created_time), INDEX idx_zoho_id (zoho_id) diff --git a/src/db/migrations/009_create_zoho_sales_orders_bulk.sql b/src/db/migrations/009_create_zoho_sales_orders_bulk.sql index 032540f..a75d621 100644 --- a/src/db/migrations/009_create_zoho_sales_orders_bulk.sql +++ b/src/db/migrations/009_create_zoho_sales_orders_bulk.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS zoho_sales_orders_bulk ( internal_id INT AUTO_INCREMENT PRIMARY KEY, zoho_id VARCHAR(255), - user_id VARCHAR(255) NOT NULL, + user_uuid CHAR(36) NOT NULL, provider VARCHAR(50) NOT NULL DEFAULT 'zoho', sales_order_number VARCHAR(255), subject VARCHAR(500), @@ -17,7 +17,8 @@ CREATE TABLE IF NOT EXISTS zoho_sales_orders_bulk ( bulk_job_id VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX idx_user_provider (user_id, provider), + INDEX idx_user_provider (user_uuid, provider), + CONSTRAINT fk_zoho_sales_orders_bulk_user FOREIGN KEY (user_uuid) REFERENCES users(uuid) ON DELETE CASCADE, INDEX idx_bulk_job (bulk_job_id), INDEX idx_created_time (created_time), INDEX idx_zoho_id (zoho_id) diff --git a/src/db/migrations/010_create_zoho_purchase_orders_bulk.sql b/src/db/migrations/010_create_zoho_purchase_orders_bulk.sql index 4c358a6..8eaad40 100644 --- a/src/db/migrations/010_create_zoho_purchase_orders_bulk.sql +++ b/src/db/migrations/010_create_zoho_purchase_orders_bulk.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS zoho_purchase_orders_bulk ( internal_id INT AUTO_INCREMENT PRIMARY KEY, zoho_id VARCHAR(255), - user_id VARCHAR(255) NOT NULL, + user_uuid CHAR(36) NOT NULL, provider VARCHAR(50) NOT NULL DEFAULT 'zoho', purchase_order_number VARCHAR(255), subject VARCHAR(500), @@ -17,7 +17,8 @@ CREATE TABLE IF NOT EXISTS zoho_purchase_orders_bulk ( bulk_job_id VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX idx_user_provider (user_id, provider), + INDEX idx_user_provider (user_uuid, provider), + CONSTRAINT fk_zoho_purchase_orders_bulk_user FOREIGN KEY (user_uuid) REFERENCES users(uuid) ON DELETE CASCADE, INDEX idx_bulk_job (bulk_job_id), INDEX idx_created_time (created_time), INDEX idx_zoho_id (zoho_id) diff --git a/src/db/migrations/011_create_zoho_bulk_read_jobs.sql b/src/db/migrations/011_create_zoho_bulk_read_jobs.sql index 907bb99..aea76d3 100644 --- a/src/db/migrations/011_create_zoho_bulk_read_jobs.sql +++ b/src/db/migrations/011_create_zoho_bulk_read_jobs.sql @@ -3,7 +3,7 @@ CREATE TABLE IF NOT EXISTS zoho_bulk_read_jobs ( id VARCHAR(255) PRIMARY KEY, - user_id VARCHAR(255) NOT NULL, + user_uuid CHAR(36) NOT NULL, provider VARCHAR(50) NOT NULL DEFAULT 'zoho', module VARCHAR(100) NOT NULL, operation VARCHAR(50) NOT NULL, @@ -16,7 +16,8 @@ CREATE TABLE IF NOT EXISTS zoho_bulk_read_jobs ( error_message TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX idx_user_provider (user_id, provider), + INDEX idx_user_provider (user_uuid, provider), + CONSTRAINT fk_zoho_bulk_read_jobs_user FOREIGN KEY (user_uuid) REFERENCES users(uuid) ON DELETE CASCADE, INDEX idx_module (module), INDEX idx_status (status) ); diff --git a/src/integrations/zoho/client.js b/src/integrations/zoho/client.js index 91600c6..e4e6ca1 100644 --- a/src/integrations/zoho/client.js +++ b/src/integrations/zoho/client.js @@ -86,7 +86,7 @@ class ZohoClient { const expiresAt = expires_in ? new Date(Date.now() + expires_in * 1000) : null; await userAuthTokenRepo.upsertToken({ - userId: this.userId, + userUuid: this.userId, serviceName: 'zoho', accessToken: encrypt(access_token), refreshToken: refreshToken ? encrypt(refreshToken) : null, diff --git a/src/integrations/zoho/handler.js b/src/integrations/zoho/handler.js index f01058c..78b7749 100644 --- a/src/integrations/zoho/handler.js +++ b/src/integrations/zoho/handler.js @@ -495,7 +495,7 @@ class ZohoHandler { // Create job record with the webhook data const jobData = { id: job_id, - user_id: userId, + user_uuid: userId, module: query.module, operation: operation, state: state, @@ -508,9 +508,9 @@ class ZohoHandler { console.log('✅ Created new job record'); } else { // Update existing job record with user ID if it was unknown - if (jobRecord.user_id === 'unknown') { + if (jobRecord.user_uuid === 'unknown') { await ZohoBulkReadRepository.updateBulkReadJob(job_id, { - user_id: userId + user_uuid: userId }); console.log('✅ Updated job record with user ID'); } @@ -642,7 +642,7 @@ class ZohoHandler { const jobData = { id: data.job_id, - user_id: user.uuid, + user_uuid: user.uuid, module: data.query?.module || 'unknown', operation: data.operation || 'read', state: data.state || 'CREATED', diff --git a/src/services/bulkReadService.js b/src/services/bulkReadService.js index 2be5140..84d4b04 100644 --- a/src/services/bulkReadService.js +++ b/src/services/bulkReadService.js @@ -63,7 +63,7 @@ class BulkReadService { // Store job in database const jobRecord = await ZohoBulkReadRepository.createBulkReadJob({ id: jobData.id, - user_id: userId, + user_uuid: userId, module: module, operation: 'read', state: 'CREATED', @@ -111,7 +111,7 @@ class BulkReadService { throw new Error('Job not found'); } - if (job.user_id !== userId) { + if (job.user_uuid !== userId) { throw new Error('Unauthorized access to job'); } diff --git a/src/services/csvService.js b/src/services/csvService.js index 21219e0..ee8979f 100644 --- a/src/services/csvService.js +++ b/src/services/csvService.js @@ -140,7 +140,7 @@ class CsvService { const mappedData = csvData.map(record => { const baseRecord = { - user_id: userId, + user_uuid: userId, provider: 'zoho', bulk_job_id: jobId };