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;
|
||||
}
|
||||
|
||||
pau marked this conversation as resolved
Outdated
|
||||
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,
|
||||
pau marked this conversation as resolved
Outdated
alexm
commented
Revisar que se tenga que quitar o dejar sin Revisar que se tenga que quitar o dejar sin
pau
commented
Estaba asi para poder borrar por id, cambiado para que ambos tengan id pues ya no se borra asi Estaba asi para poder borrar por id, cambiado para que ambos tengan id pues ya no se borra asi
|
||||
"description": "Identifier"
|
||||
},
|
||||
"userFk": {
|
||||
|
|
Loading…
Reference in New Issue
Poner validacion del front aqui tambien