Skip to content

Commit

Permalink
Implement webhooks feature (#146)
Browse files Browse the repository at this point in the history
* First implementation of webhooks

* Remove webhooktoken field

* Reorganize files and functions

* Clean up webhook cards

* Add routes for testing webhooks when using development environment

* Fix Config subpage scrollbar issue

* Fix delete button

Co-authored-by: Tariq Soliman <Tariq.K.Soliman@jpl.nasa.gov>
  • Loading branch information
ac-61 and tariqksoliman committed Feb 10, 2022
1 parent a3b343a commit 2d2f03b
Show file tree
Hide file tree
Showing 19 changed files with 1,202 additions and 360 deletions.
5 changes: 4 additions & 1 deletion API/Backend/Config/setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const router = require("./routes/configs");
const triggerWebhooks = require("../Webhooks/processes/triggerwebhooks.js");

let setup = {
//Once the app initializes
Expand Down Expand Up @@ -33,7 +34,9 @@ let setup = {
//Once the server starts
onceStarted: (s) => {},
//Once all tables sync
onceSynced: (s) => {},
onceSynced: (s) => {
triggerWebhooks("getConfiguration", {});
},
};

module.exports = setup;
14 changes: 14 additions & 0 deletions API/Backend/Draw/routes/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const { sequelize } = require("../../../connection");

const router = express.Router();
const db = database.db;
const triggerWebhooks = require("../../Webhooks/processes/triggerwebhooks");

router.post("/", function (req, res, next) {
res.send("test draw");
Expand All @@ -41,6 +42,7 @@ const uniqueAcrossArrays = (arr1, arr2) => {

const pushToHistory = (
Table,
res,
file_id,
feature_id,
feature_idRemove,
Expand Down Expand Up @@ -88,6 +90,10 @@ const pushToHistory = (
Table.create(newHistoryEntry)
.then((created) => {
successCallback();
triggerWebhooks("drawFileChange", {
id: file_id,
res,
});
return null;
})
.catch((err) => {
Expand Down Expand Up @@ -239,6 +245,7 @@ const clipOver = function (
if (i >= results.length) {
pushToHistory(
Histories,
res,
req.body.file_id,
newIds,
oldIds,
Expand Down Expand Up @@ -378,6 +385,7 @@ const clipUnder = function (
if (i >= results.length) {
pushToHistory(
Histories,
res,
req.body.file_id,
newIds,
oldIds,
Expand Down Expand Up @@ -566,6 +574,7 @@ const add = function (
} else {
pushToHistory(
Histories,
res,
req.body.file_id,
id,
null,
Expand Down Expand Up @@ -733,6 +742,7 @@ const edit = function (req, res, successCallback, failureCallback) {
if (req.body.to_history) {
pushToHistory(
Histories,
res,
req.body.file_id,
created.id,
req.body.feature_id,
Expand Down Expand Up @@ -844,6 +854,7 @@ router.post("/remove", function (req, res, next) {
//Table, file_id, feature_id, feature_idRemove, time, undoToTime, action_index
pushToHistory(
Histories,
res,
req.body.file_id,
null,
req.body.id,
Expand Down Expand Up @@ -974,6 +985,7 @@ router.post("/undo", function (req, res, next) {
.then((r) => {
pushToHistory(
Histories,
res,
req.body.file_id,
null,
null,
Expand Down Expand Up @@ -1112,6 +1124,7 @@ router.post("/merge", function (req, res, next) {
if (i >= results.length) {
pushToHistory(
Histories,
res,
req.body.file_id,
newIds,
oldIds,
Expand Down Expand Up @@ -1270,6 +1283,7 @@ router.post("/split", function (req, res, next) {
if (i >= r.length) {
pushToHistory(
Histories,
res,
req.body.file_id,
newIds,
oldIds,
Expand Down
Loading

0 comments on commit 2d2f03b

Please sign in to comment.