Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement webhooks feature #146

Merged
merged 7 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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