| 111 | } |
| 112 | |
| 113 | function addIntegration({ |
| 114 | alert_id, integration_id, enabled, type |
| 115 | }) { |
| 116 | // first check if the integration already exists |
| 117 | return db.AlertIntegration.findOne({ |
| 118 | where: { |
| 119 | alert_id, |
| 120 | integration_id, |
| 121 | }, |
| 122 | }) |
| 123 | .then((alertIntegration) => { |
| 124 | if (alertIntegration) { |
| 125 | return db.AlertIntegration.update({ |
| 126 | enabled, |
| 127 | type, |
| 128 | }, { |
| 129 | where: { |
| 130 | id: alertIntegration.id, |
| 131 | }, |
| 132 | }) |
| 133 | .then(() => { |
| 134 | return db.AlertIntegration.findByPk(alertIntegration.id); |
| 135 | }); |
| 136 | } |
| 137 | |
| 138 | return db.AlertIntegration.create({ |
| 139 | alert_id, |
| 140 | integration_id, |
| 141 | enabled, |
| 142 | type, |
| 143 | }); |
| 144 | }); |
| 145 | } |
| 146 | |
| 147 | module.exports = { |
| 148 | findById, |