loopback4-microservice-catalog icon indicating copy to clipboard operation
loopback4-microservice-catalog copied to clipboard

/notification-users get api is not working for userTenantId (issue of @sourceloop/notification-service)

Open sandeep-sourcefuse opened this issue 4 years ago • 5 comments

Is your feature request related to a problem? Please describe. /notification-users get api is not working for userTenantId because we are using user tenant id for our socket connection which is "to" parameter in request and currently it is comparing userId column value with token userId

Describe the solution you'd like We can check userTenantId for userId column or we should introduce a provider for checking column value

Describe alternatives you've considered currently using a new controller for handling /notification-users get api

sandeep-sourcefuse avatar Mar 06 '21 14:03 sandeep-sourcefuse

@sandeep-sourcefuse I dont like the solution of adding a new provider for this. Any other solution ? @sourcefuse/sourceloop

samarpan-b avatar Mar 22 '21 06:03 samarpan-b

@sandeep-sourcefuse can you please elaborate the issue? Do you want the userTeanantId in the response body?

harshitmitSF avatar May 20 '21 06:05 harshitmitSF

@harshitmitSF there are two issue which i am facing in @sourceloop/notification-service but this is about first

We are using create-notification

{
      "template": {
        "method": "POST",
        "url": "/notifications",
        "headers": {
          "content-type": "application/json",
          "Authorization": "{token}"
        },
        "body": "{body}"
      },
      "functions": {
        "createNotification": ["body", "token"]
      }
},

and the body passed as

this.notificationService.createNotification(bearerToken, {
      ----
      receiver: {
        to: [{id: userTenantId}],
      },
      type: NotificationType.Push,
      ----
});

as you can see here we are passing userTenantId to send socket notification

but if we request for all notifications list for particular user then the condition check will incorrect as it is defined in

@sourceloop/notification-service/src/controllers/notification-user.controller.ts

 private _createFilterBuilder(
    currentUser: IAuthUserWithPermissions,
    filter: Filter<NotificationUser> = {},
  ) {
    const filterBuilder = new FilterBuilder(filter);
    if (filter) {
      const whereBuilder = new WhereBuilder(filter.where);
      whereBuilder.and([
        {
          userId: currentUser.id,
        },
      ]);
      filterBuilder.where(whereBuilder.build());
    }
    return filterBuilder;
  }

In above check we are using userId: currentUser.id, not userId: currentUser.userTenantId,

so can we get something to define our condition

sandeep-sourcefuse avatar May 26 '21 06:05 sandeep-sourcefuse

@sandeep-sourcefuse I think if we use currentUser.userTenantId instead of currentUser.id the issue will be resolved. Right?

harshitmitSF avatar May 27 '21 09:05 harshitmitSF

@harshitmitSF for my case it will work fine, but again other user may want to use currentUser.id

sandeep-sourcefuse avatar May 27 '21 10:05 sandeep-sourcefuse