4797-lilium-worker-notifications #1229
|
@ -0,0 +1,56 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('deleteSubscription', {
|
||||
description: 'delete a notification subscription',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'notificationId',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'userId',
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/deleteSubscription`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.deleteSubscription = async(notificationId, userId, options) => {
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const query = `DELETE FROM util.notificationSubscription
|
||||
WHERE notificationFk = ? AND userFk = ?`;
|
||||
|
||||
await Self.rawSql(query, [notificationId, userId], myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return {success: true};
|
||||
} catch (error) {
|
||||
if (tx) await tx.rollback();
|
||||
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -6,6 +6,16 @@
|
|||
"table": "util.notificationAcl"
|
||||
}
|
||||
},
|
||||
"properties":{
|
||||
"notificationFk": {
|
||||
"id": true,
|
||||
"type": "number"
|
||||
},
|
||||
"roleFk":{
|
||||
"id": true,
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
"notification": {
|
||||
"type": "belongsTo",
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/notification/deleteSubcription')(Self);
|
||||
};
|
|
@ -9,7 +9,6 @@
|
|||
"properties": {
|
||||
"notificationFk": {
|
||||
"type": "number",
|
||||
"id": true,
|
||||
"description": "Identifier"
|
||||
},
|
||||
"userFk": {
|
||||
|
|
Loading…
Reference in New Issue