Skip to content

Commit

Permalink
Merge pull request #1261 from amazeeio/1258-removeNotificationFromPro…
Browse files Browse the repository at this point in the history
…ject

Fix removeNotificationFromProject mutation
  • Loading branch information
Schnitzel authored Sep 25, 2019
2 parents 6576d2e + cec45c8 commit cef2d54
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions services/api/src/resources/notification/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,21 @@ const Sql /* : SqlObj */ = {
.select('nt.*', 'pn.*', knex.raw('? as type', [type]))
.toString();
},
deleteProjectNotification: (
input /* : Object */,
) => {
const { project, notificationType, notificationName } = input;

const deleteQuery = knex('project_notification AS pn')
.joinRaw(
`LEFT JOIN notification_${notificationType} AS nt ON pn.nid = nt.id AND pn.type = ?`,
[notificationType],
)
.leftJoin('project AS p', 'pn.pid', '=', 'p.id');
deleteProjectNotification: (input /* : Object */) => {
const deleteQuery = knex.raw(
`DELETE pn
FROM project_notification as pn
LEFT JOIN :notificationTable: AS nt ON pn.nid = nt.id AND pn.type = :notificationType
LEFT JOIN project as p on pn.pid = p.id
WHERE p.name = :project
AND nt.name = :notificationName`,
{
...input,
notificationTable: `notification_${input.notificationType}`,
},
);

return deleteQuery
.where('p.name', project)
.andWhere('nt.name', notificationName)
.del()
.toString();
return deleteQuery.toString();
},
selectProjectById: (input /* : Object */) =>
knex('project')
Expand Down Expand Up @@ -83,9 +81,7 @@ const Sql /* : SqlObj */ = {
.update(patch)
.toString();
},
selectNotificationsByTypeByProjectId: (
input /* : Object */,
) => {
selectNotificationsByTypeByProjectId: (input /* : Object */) => {
const { type, pid } = input;
const selectQuery = knex('project_notification AS pn').joinRaw(
`JOIN notification_${type} AS nt ON pn.nid = nt.id AND pn.type = ?`,
Expand Down

0 comments on commit cef2d54

Please sign in to comment.