-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #937 from Hylozoic/826-zapier-integration
826 zapier integration
- Loading branch information
Showing
13 changed files
with
175 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
export async function createZapierTrigger (userId, groupId, targetUrl, type) { | ||
if (groupId) { | ||
const membership = await GroupMembership.forPair(userId, groupId) | ||
if (!membership) { | ||
throw new GraphQLYogaError('You don\'t have access to a group with this ID') | ||
export async function createZapierTrigger (userId, groupIds, targetUrl, type, params) { | ||
return bookshelf.transaction(async (transacting) => { | ||
const trigger = await ZapierTrigger.forge({ user_id: userId, target_url: targetUrl, type, params }).save({}, { transacting }) | ||
|
||
if (groupIds && groupIds.length > 0) { | ||
const memberships = await GroupMembership.query(q => q.where({ user_id: userId }).whereIn('group_id', groupIds)).fetchAll({ transacting }) | ||
if (!memberships || memberships.length === 0) { | ||
throw new GraphQLYogaError('You don\'t have access to any of these groups') | ||
} | ||
await trigger.groups().attach(memberships.map(m => m.get('group_id')), { transacting }) | ||
} | ||
} | ||
|
||
const trigger = await ZapierTrigger.forge({ user_id: userId, group_id: groupId, target_url: targetUrl, type }).save() | ||
return trigger | ||
return trigger | ||
}) | ||
} | ||
|
||
export async function deleteZapierTrigger (userId, id) { | ||
const trigger = await ZapierTrigger.query(q => q.where({ id, userId })).fetch() | ||
return bookshelf.transaction(async (transacting) => { | ||
const trigger = await ZapierTrigger.query(q => q.where({ id, userId })).fetch() | ||
|
||
if (trigger) { | ||
await trigger.destroy() | ||
} | ||
return true | ||
if (trigger) { | ||
await ZapierTriggerGroup.where({ zapier_trigger_id: id }).destroy({ transacting }) | ||
await trigger.destroy({ transacting }) | ||
} | ||
return true | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = bookshelf.Model.extend({ | ||
tableName: 'zapier_triggers_groups', | ||
requireFetch: false, | ||
hasTimestamps: false, | ||
|
||
trigger: function () { | ||
return this.belongsTo(ZapierTrigger) | ||
}, | ||
|
||
group: function () { | ||
return this.belongsTo(Group) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
migrations/20230221155959_zapier-triggers-multiple-groups.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
exports.up = async function (knex) { | ||
await knex.schema.createTable('zapier_triggers_groups', table => { | ||
table.increments().primary() | ||
table.bigInteger('zapier_trigger_id').references('id').inTable('zapier_triggers') | ||
table.bigInteger('group_id').references('id').inTable('groups') | ||
table.index(['zapier_trigger_id']) | ||
}) | ||
|
||
await knex.raw('alter table zapier_triggers_groups alter constraint zapier_triggers_groups_zapier_trigger_id_foreign deferrable initially deferred') | ||
await knex.raw('alter table zapier_triggers_groups alter constraint zapier_triggers_groups_group_id_foreign deferrable initially deferred') | ||
|
||
await knex.raw('insert into zapier_triggers_groups (zapier_trigger_id, group_id) (select id, group_id from zapier_triggers)') | ||
|
||
await knex.schema.table('zapier_triggers', table => { | ||
table.dropColumn('group_id') | ||
table.jsonb('params') | ||
}) | ||
} | ||
|
||
exports.down = async function (knex) { | ||
await knex.schema.table('zapier_triggers', table => { | ||
table.dropColumn('params') | ||
table.bigInteger('group_id').references('id').inTable('groups') | ||
}) | ||
await knex.raw('UPDATE zapier_triggers SET group_id = \'externalLink\' WHERE type= \'externalLink\'') | ||
await knex.schema.dropTable('zapier_triggers_groups') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters