0
我試圖在解析上運行一些雲功能,但originalFavorited.first
未運行。解析依賴對方的多個查詢的雲代碼
var _ = require('underscore');
Parse.Cloud.define("userFeed", function (request, response) {
if (request.user == undefined) {
response.error("User must be logged in!");
}
var friendsQuery = new Parse.Query("Friend");
friendsQuery.equalTo("fromUser", request.user);
var badPhotosQuery = new Parse.Query("Photo");
badPhotosQuery.greaterThanOrEqualTo("flagCount", 3);
var userFlaggedQuery = new Parse.Query("Photo");
userFlaggedQuery.containedIn("flagCount", request.user.flaggedItems);
var allBadPhotosQuery = new Parse.Query.or(badPhotosQuery, userFlaggedQuery);
var activitiesQuery = new Parse.Query("Activity");
activitiesQuery.skip(request.params.startRecord);
activitiesQuery.limit(request.params.numberRecords);
activitiesQuery.equalTo("type", "favorite");
activitiesQuery.matchesKeyInQuery("fromUser", "toUser", friendsQuery);
activitiesQuery.descending("createdAt");
activitiesQuery.include("photo")
activitiesQuery.include("fromUser");
activitiesQuery.notEqualTo("fromUser", request.user);
activitiesQuery.doesNotMatchQuery("photo", allBadPhotosQuery);
var parsedResults = [];
activitiesQuery.find().then(function (results) {
return results;
}).then(function (results) {
var promise = Parse.Promise.as();
_.each(results, function (activity) {
promise = promise.then(function() {
console.log("Parsing results for " + activity);
var originalFavorited = new Parse.Query("Activity");
originalFavorited.ascending("createdAt");
console.log(activity.get("photo"));
originalFavorited.equalTo("photo", activity.get("photo"));
originalFavorited.include("photo");
originalFavorited.include("fromUser");
originalFavorited.equalTo("type", "favorite");
originalFavorited.first(function (origResult) {
console.log("Found original");
parsedResults.push(origResult);
return parsedResults;
});
});
});
return promise;
}).then(function() {
var filteredResults = _.uniq(parsedResults, false);
response.success(filteredResults);
});
對於我的輸出console.log (activity.get("photo"));
正在輸出對象。 photo
是我的Photo
類的指針。
我是否正確地做了承諾,以便代碼正在同步運行?
感謝不幸的是,'Found original'查詢似乎沒有被運行。 – Bot
您是否檢查過該查詢是否發生錯誤?嘗試在.first(...)方法中處理錯誤回調。我已經更新了那個答案。 –
錯誤日誌中沒有錯誤,更新代碼 – Bot