I am trying to hide some fields in my cloud code for a class with blocking value to a default number in afterFind trigger.
Parse.Cloud.afterFind("Question", async (req) => {
let objs = req.objects;
if (req.master) return req.objects;
objs.forEach(obj => {
obj.set("answer", -100);
});
return objs;
});
It it working fine but when I subscribe to this Class with LiveQuery on update event I can see all fields in my console.
sub.on("update", async (obj) => {
console.log(obj.toJSON());
//this.getQuestion(this.cat_id);
});
Is there any way to modify/block fields in LiveQuery events ?
EDIT:
I am trying to implement protectedFields but it gives same response
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'id',
masterKey: process.env.MASTER_KEY || 'master', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Message", "Marker", "Question"] // List of classes to support for query subscriptions
},
protectedFields: {
Question: {
"*": ["answer", "active"]
}
} });
LiveQuery :
async subToQuestions(category) {
let questionQuery = new Parse.Query(Question);
questionQuery.equalTo("category", category);
try {
return await questionQuery.subscribe();
}
catch (e) {
throw e;
}
}
category is a pointer
async subToQuestion(cat) {
let sub = await this.ParseService.subToQuestions(cat);
sub.on('create', async (obj) => {
console.log(obj.toJSON());
});
sub.on("update", async (obj) => {
console.log(obj.toJSON());
});
}
When I log the result of LiveQuery it prompts protected fields too.
And beforeFind for Question class
Parse.Cloud.beforeFind("Question", async (req) => {
let query = req.query;
query.limit(1);
query.equalTo("active", true);
let now = new Date();
query.greaterThan("close_date", now);
query.include(["close_date", "text"]);
});