Skip to content

Commit

Permalink
backend routes, models and and migration files for integration_mapping (
Browse files Browse the repository at this point in the history
#702)

* backend routes, models and and migration files for integration_mapping

* update integration.js

* update integration_mapping

* remove integration creation

* add error messages, validation, and testing to all routes

* remove lines
  • Loading branch information
FancMa01 authored Mar 5, 2024
1 parent db9bbf2 commit 367b690
Show file tree
Hide file tree
Showing 13 changed files with 362 additions and 671 deletions.
11 changes: 6 additions & 5 deletions server/job-scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const {
} = require("./jobSchedularMethods/orbitJobs.js");

//import job directly to run it only once on server start
const { createIntegrations } = require("./jobs/integrationCreation.js");
//remove this
// const { createIntegrations } = require("./jobs/integrationCreation.js");

class JobScheduler {
constructor() {
Expand Down Expand Up @@ -128,7 +129,7 @@ class JobScheduler {
await this.createOrbitMegaphoneJob();

//one off jobs on server start
await this.createIntegrations();
// await this.createIntegrations();
})();
}

Expand Down Expand Up @@ -345,9 +346,9 @@ class JobScheduler {
return createOrbitMonitoringJob.call(this, { orbitMonitoring_id, cron });
}

createIntegrations() {
return createIntegrations.call(this);
}
// createIntegrations() {
// return createIntegrations.call(this);
// }
}

module.exports = new JobScheduler();
59 changes: 0 additions & 59 deletions server/jobs/integrationCreation.js

This file was deleted.

24 changes: 24 additions & 0 deletions server/migrations/20240301202952-remove_integration_columns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.removeColumn("integrations", "config");
await queryInterface.removeColumn("integrations", "metadata");
await queryInterface.removeColumn("integrations", "active");
},

down: async (queryInterface, Sequelize) => {
await queryInterface.addColumn("integrations", "config", {
type: Sequelize.STRING,
allowNull: true,
});
await queryInterface.addColumn("integrations", "metadata", {
type: Sequelize.STRING,
allowNull: true,
});
await queryInterface.addColumn("integrations", "active", {
type: Sequelize.BOOLEAN,
defaultValue: true,
});
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"use strict";
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable("integration_mapping", {
id: {
allowNull: false,
primaryKey: true,
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
},
integration_id: {
type: Sequelize.UUID,
references: {
model: "integrations",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
application_id: {
type: Sequelize.UUID,
references: {
model: "application",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
metaData: {
type: Sequelize.JSON,
allowNull: true,
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW,
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW,
},
});
},

async down(queryInterface, Sequelize) {
await queryInterface.dropTable("integration_mapping");
},
};
9 changes: 6 additions & 3 deletions server/models/application.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
"use strict";
module.exports = (sequelize, DataTypes) => {
const application = sequelize.define(
'application',
"application",
{
id: {
primaryKey: true,
Expand Down Expand Up @@ -101,8 +101,11 @@ module.exports = (sequelize, DataTypes) => {
foreignKey: "application_id",
onDelete: "CASCADE",
});
application.hasMany(models.integration_mapping, {
foreignKey: "application_id",
onDelete: "CASCADE",
});
};


return application;
};
58 changes: 58 additions & 0 deletions server/models/integration_mapping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use strict";
module.exports = (sequelize, DataTypes) => {
const IntegrationMapping = sequelize.define(
"integration_mapping",
{
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
allowNull: false,
},
integration_id: {
type: DataTypes.UUID,
references: {
model: "integrations",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
application_id: {
type: DataTypes.UUID,
references: {
model: "application",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
metaData: {
type: DataTypes.JSON,
allowNull: true,
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
},
},
{ freezeTableName: true }
);

IntegrationMapping.associate = (models) => {
IntegrationMapping.belongsTo(models.integrations, {
foreignKey: "integration_id",
});
IntegrationMapping.belongsTo(models.application, {
foreignKey: "application_id",
});
};

return IntegrationMapping;
};
Loading

0 comments on commit 367b690

Please sign in to comment.