0

我试图在我的云代码中隐藏一些字段,用于在 afterFind 触发器中将阻塞值设置为默认数字的类。

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;
});

它工作正常,但是当我在更新事件中使用 LiveQuery 订阅这个类时,我可以在我的控制台中看到所有字段。

sub.on("update", async (obj) => {
      console.log(obj.toJSON());
      //this.getQuestion(this.cat_id);
    });

有没有办法修改/阻止 LiveQuery 事件中的字段?

编辑:

我正在尝试实现 protectedFields 但它给出了相同的响应

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"]
   }

} });

实时查询:

async subToQuestions(category) {
  let questionQuery = new Parse.Query(Question);
  questionQuery.equalTo("category", category);
  try {
    return await questionQuery.subscribe();
  }
  catch (e) {
    throw e;
  }
}

类别是一个指针

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());
    });
  }

当我记录 LiveQuery 的结果时,它也会提示受保护的字段。

和 beforeFind for Question 类

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"]);
});

查询示例 在此处输入图像描述

4

0 回答 0