4797-lilium-worker-notifications #1229

Merged
pau merged 37 commits from 4797-lilium-worker-notifications into dev 2023-02-02 08:53:29 +00:00
2 changed files with 8 additions and 10 deletions
Showing only changes of commit cc806cc08f - Show all commits

View File

@ -7,9 +7,7 @@ module.exports = Self => {
const user = await ctx.instance.userFk; const user = await ctx.instance.userFk;
const modifiedUser = await getUserToModify(null, user, models); const modifiedUser = await getUserToModify(null, user, models);
if (userId == modifiedUser.id || userId == modifiedUser.bossFk) if (userId != modifiedUser.id && userId != modifiedUser.bossFk)
pau marked this conversation as resolved Outdated
Outdated
Review

Pasar a funcion la parte de comprobar el usuario, ya que se repite en el before y en la ruta de delete

Pasar a funcion la parte de comprobar el usuario, ya que se repite en el before y en la ruta de delete
return;
else
throw new UserError('You dont have permission to modify this user'); throw new UserError('You dont have permission to modify this user');
pau marked this conversation as resolved
Review

Te ahorres fer if else, fent:

        if (userId != modifiedUser.id && userId != modifiedUser.bossFk)
            throw new UserError('You dont have permission to modify this user');

I ns si faria falta ficar return al final o no

Te ahorres fer if else, fent: ``` if (userId != modifiedUser.id && userId != modifiedUser.bossFk) throw new UserError('You dont have permission to modify this user'); ``` *I ns si faria falta ficar return al final o no*
}); });
@ -42,14 +40,13 @@ module.exports = Self => {
const user = ctx.req.accessToken.userId; const user = ctx.req.accessToken.userId;
const modifiedUser = await getUserToModify(notificationId, null, models); const modifiedUser = await getUserToModify(notificationId, null, models);
if (user == modifiedUser.id || modifiedUser.bossFk == user) { if (user != modifiedUser.id && user != modifiedUser.bossFk)
pau marked this conversation as resolved Outdated
Outdated
Review

No estas comprobando el usuario

No estas comprobando el usuario
Outdated
Review

No se comprueba el usuario porque se le pasa un id de notificationSubscription ya existente, por lo cual dentro del metodo getUserToModify se cumpliria el requisito del if-else y se realizaria la consulta en la que se sacaria a que usuario pertenece esa notificación

No se comprueba el usuario porque se le pasa un id de notificationSubscription ya existente, por lo cual dentro del metodo getUserToModify se cumpliria el requisito del if-else y se realizaria la consulta en la que se sacaria a que usuario pertenece esa notificación
await models.NotificationSubscription.destroyById(notificationId);
return;
} else
throw new UserError('You dont have permission to modify this user'); throw new UserError('You dont have permission to modify this user');
pau marked this conversation as resolved Outdated
Outdated
Review

Te ahorres fer if else, fent:

        if (user != modifiedUser.id && user != modifiedUser.bossFk)
            throw new UserError('You dont have permission to modify this user');
            
        await models.NotificationSubscription.destroyById(notificationId);   
        
Te ahorres fer if else, fent: ``` if (user != modifiedUser.id && user != modifiedUser.bossFk) throw new UserError('You dont have permission to modify this user'); await models.NotificationSubscription.destroyById(notificationId); ```
await models.NotificationSubscription.destroyById(notificationId);
}; };
pau marked this conversation as resolved
Review

Self.deleteNotification = async function(ctx, userId, notificationId)

Y asi te ahorras poner

const notificationId = await ctx.args.notificationId;
const userId = await ctx.args.userId;
`Self.deleteNotification = async function(ctx, userId, notificationId)` Y asi te ahorras poner ``` const notificationId = await ctx.args.notificationId; const userId = await ctx.args.userId; ```
async function getUserToModify(notificationId = null, userFk = null, models) { async function getUserToModify(notificationId, userFk, models) {
pau marked this conversation as resolved Outdated
Outdated
Review

No seria mejor utilizar ctx.req.accessToken.userId y no pasarlo por parametro?

No seria mejor utilizar ctx.req.accessToken.userId y no pasarlo por parametro?
if (notificationId != null) { if (notificationId != null) {
pau marked this conversation as resolved Outdated
Outdated
Review

Provar:
let userToCheck = userFk;
if (notificationId != null)
userToCheck = await models.NotificationSubscription.findById(notificationId).userFk;

return await models.Worker.findOne({
    fields: ['id', 'bossFk'],
    where: {
        id: userToCheck
    }
});
Provar: let userToCheck = userFk; if (notificationId != null) userToCheck = await models.NotificationSubscription.findById(notificationId).userFk; return await models.Worker.findOne({ fields: ['id', 'bossFk'], where: { id: userToCheck } });
const subscription = await models.NotificationSubscription.findById(notificationId); const subscription = await models.NotificationSubscription.findById(notificationId);
pau marked this conversation as resolved Outdated
Outdated
Review

Además de lo que comenta alex, quitar el await.

Además de lo que comenta alex, quitar el await.
const user = await subscription.userFk; const user = await subscription.userFk;
pau marked this conversation as resolved
Review

Pq per defecte els dos parametres son null?

Pq per defecte els dos parametres son null?

View File

@ -19726,10 +19726,11 @@ DROP TABLE IF EXISTS `notificationSubscription`;
/*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */; /*!40101 SET character_set_client = utf8 */;
CREATE TABLE `notificationSubscription` ( CREATE TABLE `notificationSubscription` (
`Id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
pau marked this conversation as resolved Outdated
Outdated
Review

Minúscula

Minúscula
Outdated
Review

Esto no debería estar en el changes también???

Esto no debería estar en el changes también???
`notificationFk` int(11) NOT NULL, `notificationFk` int(11) NOT NULL,
`userFk` int(10) unsigned NOT NULL, `userFk` int(10) unsigned NOT NULL,
PRIMARY KEY (`Id`), PRIMARY KEY (`id`),
pau marked this conversation as resolved Outdated
Outdated
Review

Minúscula

Minúscula
KEY `notificationSubscription_ibfk_1` (`notificationFk`),
pau marked this conversation as resolved Outdated
Outdated
Review

Hace falta añadir KEY notificationSubscription_ibfk_1 (notificationFk) ?

Hace falta añadir `KEY `notificationSubscription_ibfk_1` (`notificationFk`)` ?
KEY `notificationSubscription_ibfk_2` (`userFk`), KEY `notificationSubscription_ibfk_2` (`userFk`),
CONSTRAINT `notificationSubscription_ibfk_1` FOREIGN KEY (`notificationFk`) REFERENCES `notification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `notificationSubscription_ibfk_1` FOREIGN KEY (`notificationFk`) REFERENCES `notification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `notificationSubscription_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE CONSTRAINT `notificationSubscription_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE