feathersjs-ecosystem / feathers-reactive

Reactive API extensions for Feathers services
MIT License
216 stars 37 forks source link

$or filter doesn't work on watch/subscribe #139

Open adrianolsk opened 6 years ago

adrianolsk commented 6 years ago

I am using feathers-reactive, to get some data from a service and I subscribe to the result. When someone invites the user or he invites someone he should receive the updated data. It does work when I specify the user_id in the query, but if I use a $or he starts to receive updates from all users all over the app

this.app
    .service("friends")
    .watch()
    .find({
        query: { 
            $or: [{ user_id: user.id }, { friend_id: user.id }] // this doesn't work
            // user_id: user.id // this work
        }
    })
    .subscribe(friends => console.log(friends));

Expected behavior

It should respect the filter

Actual behavior

It completely ignores the filter when using a $or

More context

I am posting a simple object like this using postman:

{
    "user_id": 1,
    "friend_id": 2,
    "accepted": true
}

workaround

The thing I did to workaround was using channels to only publish the data if the user is in one of the fields:

// app.on("login", (authResult, { connection }) => {...
 app.channel(`friends/${connection.user.id}`).join(connection);

//publish
app.service("friends").publish(data => {
    return [
      app.channel(`friends/${data.user_id}`),
      app.channel(`friends/${data.friend_id}`)
    ];
});
Artaud commented 4 years ago

Has this been resolved and forgotten or is it still present?