Example #1
0
		reportQuery.find().then(function(results){
			if(results.length == 0){
				//需要扣减分数
				var user = new User();
				user.id = reportedUserId;
				var userDynamicQuery = new AV.Query(UserDynamicData);
				userDynamicQuery.equalTo('userId', user);
				userDynamicQuery.find().then(function(results){
					if(results.length > 0){
						var userDynamicData = results[0];
						var reportedScore = userDynamicData.get('reportedScore');
						if(reportedScore > 0){
							reportedScore=reportedScore -1*2;
							userDynamicData.set('reportedScore', reportedScore);
							userDynamicData.save();
						}
						report.save();
						response.success({"code":200, "result":"举报成功"});
					}else{
						response.error({"code":500, "result":"dynamicData不存在"});
					}
				},
				function(error){
					response.error({"code":500, result:"被举报人不存在"});
				});
			}else{
				report.save();
				response.success({"code":200, "result":"举报成功"});
			}
		},
Example #2
0
        success: function (pointresults) {
            for (var i = 0; i < pointresults.length; i++) {
                var point = pointresults[i];
                var pointid = point.id;


                var querypimg = new AV.Query(Point_Image);
                querypimg.equalTo("PointId", pointid);
                querypimg.find({
                    success: function (pimgresults) {
                        for (var i = 0; i < pimgresults.length; i++) {
                            var pimg = pimgresults[i];
                            var imgfile = pimg.get('Image');
                            imgfile.destroy();
                        }

                        AV.Object.destroyAll(pimgresults);

                    },
                    error: function (error) {
                        console.log("Error: " + error.code + " " + error.message);
                    }
                });

                point.destroy();
            }
            AV.Object.destroyAll(pointresults);
        },
Example #3
0
  param.targets.forEach(function(target) {
    var query = new AV.Query(target.leancloudClass);
    query.equalTo('size', model.modelSize);
    query.equalTo('loadGrade', model.loadGrade);
    query.equalTo(param.leancloudName, param.roundedValue);

    query.find().then(function(results) {
      queryCount += 1;
      if (results.length == 1) {
        console.log(target.name + '查找成功');
        target.value = results[0].get('value');
      } else if (results.length > 1) {
        console.log('***' + target.name +'结果不唯一');
      } else {
        console.log('***' + target.name + '无匹配结果');
      }
    },
    function(error) {
      console.log('Error: ' + error.code + ' ' + error.message);
    })
    .then(function(results) {
      if (queryCount === 8) {
        queryCount = 0;
        callback();
      }
    });
  });
Example #4
0
  LeanStore.prototype.get_ = function(id, callback) {
    var self = this;
    var query = new AV.Query(Session);

    query.equalTo('identity', id);
    query.first({
            success: function (foundSession)
            {
              if (!foundSession)
              {
                callback(Error.get(Error.ENOENT), null);
              }
              else if (foundSession.get('destroyAt') < new Date())
              {
                self.destroy(foundSession, callback)
              }
              else
              {
                callback(null, foundSession);
              }
            },
            error: function (error)
            {
              callback(error, null);
            }
        });
  };
Example #5
0
 promise = promise.then(function() {
   var query = new AV.Query(Order);
   query.equalTo('orderNumber', charge.order_no);
   query.include('route');
   query.include('user');
   return query.find();
 });
Example #6
0
File: app.js Project: xzhuah/Forest
app.get('/userlike/:userId/:nodeId', function(req, res) {
  var userId = req.params.userId;
  var nodeId = req.params.nodeId;
  if (userId == undefined || nodeId == undefined) {
    res.json({success: false, error: "invalid arguments"});
  }
  var nodeQuery = new AV.Query('Node');
  nodeQuery.get(nodeId).then(function(node) {
    if (node.get('likeBy') == undefined) {
      node.set('likeBy', [userId]);
    } else {
      var new_arr = node.get('likeBy');
      if (new_arr.indexOf(userId) > -1) {
        res.json({success: false, error: "already liked"});
      }
      new_arr.push(userId);
      node.set('likeBy', new_arr);
    }
    return node.save();
  }).then(function(success) {
    res.json({success: true, node: success});
  }).catch(function(error) {
    res.json({success: false, error: error});
  });
});
Example #7
0
File: app.js Project: xzhuah/Forest
 nodeQuery.get(developFrom).then(function(foundDevelopFrom) {
   developFrom = foundDevelopFrom;
   nodeQuery = new AV.Query('Node');
   if (linkTo != undefined) {
     newNode.set('linkTo', linkTo);
     nodeQuery.get(linkTo).then(function(foundLinkTo) {
       linkTo = foundLinkTo;
       var storyQuery = new AV.Query('Story');
       storyQuery.get(story).then(function(sto) {
         story = sto;
         var writerQuery = new AV.Query(AV.User);
         writerQuery.get(writer).then(function(wri) {
           writer = wri;
           newNode.set('story', story);
           newNode.set('writer', writer);
           return newNode.save();
         }).then(function(node) {
           res.json({success: true, node: node});
         }).catch(function(error) {
           res.json({success: false, error: error});
         });
       }).catch(function(error) {
         res.json({success: false, error: error});
       });
     }).catch(function(error) {
       res.json({success: false, error: error});
     });
   }
 }).catch(function(error) {
Example #8
0
router.get('/disclaimer',function (req, res) {
    console.log('获取当前用户: %j', AV.User.current());

    var currentUser = AV.User.current();
    var username = null;
    if (currentUser) {
        console.log(currentUser);
        username = AV.User.current().getUsername();
    }


    var query = new AV.Query(AV.User);
    var usercount;
    query.count({
        success: function(count) {
            // The count request succeeded. Show the count
            console.log(count);
            usercount=count;
            res.render('help/disclaimer', {title: 'Express', user: username, usercount:count,layout: 'share/layout'});
        },
        error: function(error) {
            // The request failed
            res.render('index', {title: 'Express', user: username, usercount:0,layout: 'share/layout'});
        }
    });


    //res.render('index', {title: 'Express', user: username, usercount:usercount,layout: 'share/layout'});
});
Example #9
0
router.post('/:productBrandId', (req, res) => {

    base.isAdminUserLogin(req, res);  //判断是否登录

    let productBrandId = parseInt(req.params.productBrandId);
    let name = req.body['name'];
    let brandName = req.body['brand-name'];
    let brandInfo = req.body['brand-info'];
    let brandLogoImage = req.body['brand-logo-image'];
    let brandDetail = req.body['brand-detail'];
    let authorName = req.body['author-name'];
    let authorInfo = req.body['author-info'];
    let authorImage = req.body['author-image'];
    let authorDetail = req.body['author-detail'];
    let url = req.body['url'];
    let comment = req.body['comment'];
    
    let query = new AV.Query(ProductBrand);
    query.equalTo('productBrandId',productBrandId);
    query.first().then(item => {
        
        return item.save({
            name,brandName,brandInfo,brandLogoImage,brandDetail,authorName,authorInfo,authorImage,authorDetail,url,comment
        });
        
    }).then(() => {
        req.flash('success','编辑品牌成功!');
        res.redirect('/admin/product-brand');
    });
    
});
Example #10
0
        new AV.Promise(resolve => {

            let query = new AV.Query(Product);
            query.equalTo('productId',productId);
            query.first().then(product => {
                product.save({
                    name,
                    nameEn,
                    mainImage,
                    productMethod,
                    category1,
                    category2,
                    bannerId,
                    detail,
                    review,
                    property,
                    instruction,
                    use,
                    detailImage,
                    isPublic
                }).then(result => {
                    resolve(result);
                });
            });
        }),
Example #11
0
router.get('/role/search', restrict, function(req, res) {
    var query = new AV.Query(AV.Role);
    query.equalTo("name", "admin");
    query.first({
        success: function (obj) {
            console.dir(arguments);
            if (obj) {
                obj.relation("users").query().find({
                    success: function (results) {
                        console.log(results.length);
                        res.send(results);
                    },
                    error: function (error) {
                        res.send(error);
                    }
                });
            } else {
                res.send("null");
            }
        },
        error: function (error) {
            console.error(error);
            res.send("false");
        }
    });
});
Example #12
0
AV.Cloud.define('cancelSpeedDate', function(request, response) {
	var speedDateId = request.params.speedDateId;
	if(!speedDateId || speedDateId === ''){
		response.error({"code":500, "result":"参数不正确, speedDateId=" + speedDateId});
	}else{
		var speedDate = null;
		var speedDateQuery = new AV.Query(SpeedDate);
		speedDateQuery.get(speedDateId).then(function(speedDate){
			if(speedDate){
				speedDate.set('isValid', false);
				speedDate.save();
				//修改from用户状态
				var user = new User();
				user.id=speedDate.get('fromUser');
				var userDynamicQuery  = new AV.Query(UserDynamicData);
				userDynamicQuery.equalTo('userId', user);
				userDynamicQuery.find().then(function(results){
					if(results.length >0){
						results[0].set('datingStatus', 1);
						results[0].save().then(function(userDynamicData){
							//修改to用户状态
							user.id=speedDate.get('toUser');
							userDynamicQuery.equalTo('userId', user);
					        userDynamicQuery.find().then(function(results){
					        	if(results.length >0){
	    							results[0].set('datingStatus', 1);
	    							results[0].save().then(function(userDynamicData){
	    								//返回当前快约记录
	    								response.success({"code":200, "results": speedDate});
	    							},
	    							function(error){
	    								response.error({"code":500, "result":"更新dynamicData异常(setep=5), toUser=" + speedDate.get('toUser') + " ,message=" + error.message});
	    							});
	    						}else{
	    							response.error({"code":500, "result":"dynamicData不存在(setep=4), toUser=" + speedDate.get('toUser')});
	    						}
					        },
					        function(error){
					        	response.error({"code":500, "result":"查询dynamicDate异常(setep=4), toUser=" + speedDate.get('toUser') + " ,message=" + error.message});
					        });
						},
						function(error){
							response.error({"code":500, "result":"更新dynamicData异常(setep=3), fromUser=" + speedDate.get('fromUser') + " ,message=" + error.message});
						});
					}else{
						response.error({"code":500, "result":"dynamicData不存在(setep=2), fromUser=" + speedDate.get('fromUser')});
					}
				},
				function(error){
					response.error({"code":500, "result":"查询dynamicDate异常(setep=2), fromUser=" + speedDate.get('fromUser') + " ,message=" + error.message});
				});
			}else{
				response.error({"code":500, "result":"speedDate不存在(setep=1), speedDateId=" + speedDateId});
			}
		},
		function(error){
			response.error({"code":500, "result":"查询speedDate异常(setep=1), speedDateId=" + speedDateId + " ,message=" + error.message});
		});
	}
});
Example #13
0
AV.Cloud.define('updateUserDynamicData', function(request, response) {
	var userId = request.params.userId;
	if(!userId || userId === ''){
		response.error({"code":500, "result":"参数userId不为空"});
	}else{
		var userDynamicQuery  = new AV.Query(UserDynamicData);
		var user = new User();
		user.id = userId;
		userDynamicQuery.equalTo('userId',user);
		userDynamicQuery.find().then(function(results){
			if(results.length > 0){
				var latitude = request.params.latitude;
				var longitude = request.params.longitude;
				if(latitude && latitude != '' && longitude && longitude != ''){
					var location = new AV.GeoPoint({"latitude": latitude, "longitude": longitude});
					results[0].set('location',location);
				}
				
				results[0].set('onlineStatus', true);
				results[0].save();
				response.success({"code":200, "result":results[0]});
			}else{
				response.error({"code":500, "result":"用户DynamicData不存在, userId=" + userId});
			}
		},function(error){
			response.error({"code":500, "result":"查询用户DynamicData异常,userId=" + userId});
		});
	}
});
Example #14
0
AV.Cloud.define('createUserDynamicData', function(request, response) {
	var userId = request.params.userId;
	if(!userId || userId === ''){
		response.error({"code":500, "result":"参数userId不为空"});
	}else{
		var user = new User();
		user.id = userId;
		var userDynamicQuery  = new AV.Query(UserDynamicData);
		userDynamicQuery.equalTo('userId',user);
		userDynamicQuery.find().then(function(results){
			if(results.length > 0){
				//已经存在则更新坐标和状态
				response.success({"code":200, "result":results[0]});
			}else{
				var userDynamicData = new UserDynamicData();
				userDynamicData.set('userId', user);
				userDynamicData.set('datingStatus', 1);
				userDynamicData.set('onlineStatus', true);
				userDynamicData.save().then(function(userDynamicData){
					response.success({"code":200, "result":userDynamicData})
				},
				function(error){
					response.error({"code":500, "result":"保存用户DynamicData异常"});
				});
			}
		},
		function(error){
			response.error({"code":500, "result":"查询用户DynamicData异常,userId=" + userId});
		});
	}
});
Example #15
0
File: app.js Project: xzhuah/Forest
app.get('/storybyuser/:userid',function(req,res){//OK 2016/4/16
  var querystoryidbyuser=req.params.userid;
  var findStoryIdByUserID=new AV.Query(AV.User);
  var innerQuery = new AV.Query('Story');
  innerQuery.include('theme');
  innerQuery.include('creator');
  var stories = [];
  var themeNames = [];
  var creators = [];
  findStoryIdByUserID.get(querystoryidbyuser).then(function(obj){
    innerQuery.find().then(function(results) {
      results.map(function(result) {
        if (result.get('followUser') != undefined && result.get('followUser').indexOf(querystoryidbyuser) > -1) {
          themeNames.push(result.get('theme').get('name'));
          creators.push({
            id: result.get('creator').id,
            username: result.get('creator').get('username')
          });
          stories.push(result);
        }
      });
      res.json({success: true, story: stories, themeNames: themeNames, creators: creators});
    });
  },function(error){
     res.json({success: false, error: error});
  });
});
Example #16
0
 const queryComments = () => {
   const targetArticle = AV.Object.createWithoutData('ContentList', articleId)
   const query = new AV.Query('Comments')
   query.ascending('createdAt')
   query.equalTo('pointerArticle', targetArticle)
   return query.find()
 }
Example #17
0
File: app.js Project: xzhuah/Forest
app.get('/beststory/:topnum',function(req,res){//OK 2016/4/16
  var topnum = req.params.topnum;
  var findStorybylikerank = new AV.Query('Story');
  var creators = [];
  findStorybylikerank.include('creator');
  findStorybylikerank.find().then(function(results) {
    results.sort(function(x, y) {
      if (x.get('followUser') != undefined && y.get('followUser') != undefined && x.get('followUser').length > y.get('followUser').length) {
        return -1;
      }
      if (x.get('followUser') != undefined && y.get('followUser') != undefined && x.get('followUser').length < y.get('followUser').length) {
        return 1;
      }
      return 0;
    });
    if (topnum > results.length) {
      res.json({success: false, error: "topnum too large"});
    }
    var bestStory = results.slice(0, topnum);
    bestStory.map(function(story) {
      creators.push(
        {
          id: story.get('creator').id,
          username: story.get('creator').get('username')
        }
    );
    });
    res.json({success: true, bestStory: bestStory, creators: creators});
  }).catch(function(error) {
    res.json({success: false, error: error});
  });
});
			store.getClass(function (er, classObj) {
				if(er) return fn(er);
				store.emit('lock');

				debug('SET "%s" %s', sid, jsess);
				var query = new AV.Query(classObj);
				query.equalTo('sid', psid);
				query.find().then(function (result) {

					if (result.length > 0) {
						result[0].set('value', jsess);
						result[0].save();
					} else {
						var AVSession = new classObj();
						AVSession.set('sid', psid);
						AVSession.set('value', jsess);
						AVSession.save();
						debug('SET NEW SESSION "%s" %s', sid, jsess);
					}
					debug('SET complete');
					fn.apply(null);

					store.emit('unlock');
				});
			});
Example #19
0
File: app.js Project: xzhuah/Forest
app.post('/comment/:nodeId/:userId', function(req, res) {
  var commentContent = req.body.commentContent;
  var userId = req.params.userId;
  var nodeId = req.params.nodeId;
  if (userId == undefined || nodeId == undefined || commentContent == undefined) {
    res.json({success: false, error: "invalid arguments"});
  }
  var nodeQuery = new AV.Query('Node');
  var userQuery = new AV.Query(AV.User);
  var comment = new Comment();
  comment.set('text', commentContent);
  userQuery.get(userId).then(function(user) {
    comment.set('userID', user);
    nodeQuery.get(nodeId).then(function(node) {
      comment.set('nodeID', node);
      return comment.save();
    }).then(function(success) {
      res.json({success: true, comment: success});
    }).catch(function(error) {
      res.json({success: false, error: error});
    });
  }).catch(function(error) {
    res.json({success: false, error: error});
  });
});
Example #20
0
router.post('/testJsApi', function(req, res, next) {
    // var gameScore = new GameScore();
    // gameScore.set("score", 1337);
    // gameScore.set("playerName", "Sean Plott");
    // gameScore.set("cheatMode", false);
    // gameScore.save(null, {
    //     success: function(gameScore) {
    //         // Execute any logic that should take place after the object is saved.
    //         console.log('New object created with objectId: ' + gameScore.id);
    //     },
    //     error: function(gameScore, error) {
    //         // Execute any logic that should take place if the save fails.
    //         // error is a AV.Error with an error code and description.
    //         console.log('Failed to create new object, with error code: ' + error.message);
    //     }
    // });

var query = new AV.Query(SoftwareFeedback);
query.get("55617c52e4b0d17d28b03608", {
    success: function(feedBack) {
        // The object was retrieved successfully.
        console.log(feedBack.id);
        res.send(feedBack.get("contact") + ' ' + feedBack.get("content"));
    },
    error: function(object, error) {
        // The object was not retrieved successfully.
        // error is a AV.Error with an error code and description.
        console.log('Failed to query a object, with error code: ' + error.message);

        res.send(error.message);
    }
});


});
Example #21
0
File: app.js Project: xzhuah/Forest
app.post('/story', function(req, res) {
  var creator = req.body.creator;
  var title = req.body.storyTitle;
  var theme = req.body.theme;
  var intro = req.body.intro;
  if (creator == undefined || title == undefined || theme == undefined || intro == undefined) {
    res.json({success: false, error: "parameter incomplete"});
  }
  //update theme
  var themeQuery = new AV.Query('Theme');
  var writerQuery = new AV.Query(AV.User);
  var newStory = new Story();
  themeQuery.get(theme).then(function(getTheme) {
      theme = getTheme;
      writerQuery.get(creator).then(function(wri) {
        creator = wri;
        newStory.set('creator', creator);
        newStory.set('title', title);
        newStory.set('theme', theme);
        newStory.set('introduction', intro);
        return newStory.save();
      }).then(function(success) {
          res.json({success: true, story: success});
      }).catch(function(error) {
        res.json({success: false, error: error});
      });
  }).catch(function(error) {
    res.json({success: false, error: error});
  });
});
Example #22
0
 router.get('/api/show-purchase-order-items', async (req, res) => {
     const PurchaseItems = new av.Query('PurchaseItems');
     const order = av.Object.createWithoutData(
         'PurchaseOrder',
         req.query.orderObjectId
     );
     try {
         const items = await PurchaseItems.equalTo('purchaseOrder', order)
             .include(['shoeType'])
             .find();
         const retData = items.map(item => ({
             itemId: item.id,
             shoeType: {
                 shoeObjectId: item.get('shoeType').id,
                 brand: item.get('shoeType').get('brand'),
                 color: item.get('shoeType').get('color'),
                 shoeId: item.get('shoeType').get('shoeId')
             },
             sizes: item.get('sizes')
         }));
         res.send({
             errNo: 0,
             retData
         });
     } catch (e) {
         res.send({ errNo: e.code });
     }
 });
Example #23
0
/*
**保存公告数据
** data:一个保存了表单信息的json。find:需要查找是否存在相同的元素。callback:回调函数;成功返回“success”,失败返回“error”;
 */
function saveAnnounceData(data,find,callback){
	var post = AV.Object.new('Announce');
	console.log(data);
	var query = new AV.Query('Announce');
	query.equalTo(find, data[find]);
	query.find().then(function(results) {
	  console.log('Successfully retrieved ' + results.length + ' posts.');
	  // 处理返回的结果数据
	  console.log(results.length);
		if(results.length=="0"){
			for(var key in data){
				post.set(key, data[key]);
			}
			post.save().then(function(post) {
			  // 成功保存之后,执行其他逻辑.
			  console.log('New object created with objectId: ' + post.id);
				callback.success("success");
			}, function(err) {
			  // 失败之后执行其他逻辑
			  // error 是 AV.Error 的实例,包含有错误码和描述信息.
			  console.log('Failed to create new object, with error message: ' + err.message);
				callback.error(err);
			});
		}
	}, function(error) {
	  console.log('Error: ' + error.code + ' ' + error.message);
	});
}
Example #24
0
 router.get('/api/show-purchase-orders', async (req, res) => {
     const user = req.currentUser;
     const PurchaseOrder = new av.Query('PurchaseOrder');
     try {
         const results = await PurchaseOrder.equalTo('user', user)
             .equalTo('isDel', false)
             .include(['vender'])
             .find();
         const orders = results.map(order => ({
             date: order.get('createdAt'),
             note: order.get('note'),
             vender: order.get('vender').get('name'),
             status: order.get('status'),
             orderId: order.get('orderId'),
             objectId: order.id
         }));
         res.send({
             errNo: 0,
             orders
         });
     } catch (e) {
         res.send({
             errNo: e.code,
             errMsg: '出错了'
         });
     }
 });
Example #25
0
router.get('/getallimages',function (req,res){


    var args = url.parse(req.url, true).query;

    var query = new AV.Query(Road_Image);
    query.equalTo("RoadId", args.RoadID);
    query.ascending("createdAt");
    query.find({
        success: function (results) {
            //alert("Successfully retrieved " + results.length + " scores.");
            // Do something with the returned AV.Object values

            var imgs=new Array();

            for (var i = 0; i < results.length; i++) {
                var object = results[i];
                var img = new Object();
                img.id = object.id;
                img.imageurl = object.get('Image').thumbnailURL(150, 150);

                imgs.push(img);
                //console.log(points);
            }
            res.send(imgs);
        },
        error: function (error) {
            // alert("Error: " + error.code + " " + error.message);
            res.send('false');

        }
    });
});
Example #26
0
 router.post('/api/update-shoe', async (req, res) => {
     const user = req.currentUser;
     const {
         stockObjectId,
         sizes,
         returns,
         delivered,
         purchased
     } = req.body;
     const Stock = new av.Query('Stock');
     try {
         let shoe = await Stock.get(stockObjectId);
         let _sizes = _.cloneDeep(shoe.get('sizes'));
         Object.keys(sizes).forEach(key => {
             _sizes[key] = sizes[key];
         });
         let count = Object.keys(_sizes)
             .map(size => _sizes[size])
             .reduce((sum, cur) => sum + cur);
         await shoe
             .set('sizes', _sizes)
             .set('count', count)
             .set('returns', returns)
             .set('delivered', delivered)
             .set('purchased', purchased)
             .save();
         res.send({ errNo: 0 });
     } catch (e) {
         console.log(e);
         res.send({ errNo: e.code });
     }
 });
Example #27
0
 new AV.Promise(resolve => {
     let query = new AV.Query(Banner);
     return query.find().then(banner => {
         data = extend(data, {banner});
         resolve();
     });
 }),
Example #28
0
router.post("/users/pwdreset", function (req, res) {
    var username = req.body.username;


    var query = new AV.Query(AV.User);
    query.equalTo("username", username);  // find all the women
    query.first({
        success: function (userinfo) {
            // Do stuff
            console.log(userinfo)

            if (userinfo != null) {

                var useremail = userinfo.attributes.email;
                res.render('users/sendpwdresetemail', {user: username, useremail: useremail, layout: 'share/layout'});

            }
            else {
                //res.send("<script language='javascript'> alert('该用户不存在');</script>")


                res.send("<script language='javascript'>if(confirm('该用户不存在!')){document.location.replace('/users/pwdreset')}else{document.location.replace('/users/pwdreset')};</script>");
            }
        }
    });

});
Example #29
0
 router.post('/api/create-client', async (req, res) => {
     const user = req.currentUser;
     const { name, mobilephone, telephone, address, note } = req.body;
     const Client = new av.Query('Clients');
     try {
         const clients = Client.equalTo('user', user)
             .equalTo('name', name)
             .equalTo('isDel', false)
             .find();
         if (!clients.length) {
             let newClient = new av.Object('Clients');
             newClient
                 .set('user', user)
                 .set('name', name)
                 .set('mobilephone', mobilephone)
                 .set('telephone', telephone)
                 .set('address', address)
                 .set('note', note);
             const { id } = await newClient.save();
             res.send({
                 errNo: 0,
                 retData: { id }
             });
         } else {
             throw {
                 code: -1,
                 errMsg: '已存在该客户'
             };
         }
     } catch ({ code, errMsg }) {
         res.send({ errNo: code, errMsg });
     }
 });
Example #30
0
AV.Cloud.define('datingRoute', function(request, response) {
	var speedDateId = request.params.speedDateId;
	var latitude = request.params.latitude;
	var longitude = request.params.longitude;
	var point = new AV.GeoPoint({"latitude": latitude, "longitude": longitude});
	var speedDateQuery = new AV.Query(SpeedDate);
	speedDateQuery.get(speedDateId).then(function(speedDate){
		if(speedDate){
			//新增用户走走坐标
			var speedDateRoute = new SpeedDateRoute();
			speedDateRoute.set('speedDate',speedDate);
			speedDateRoute.set('coordinate',point);
			speedDateRoute.save().then(function(speedDateRoute){
				response.success({"code":200, "results":"success"});
			},
			function(error){
				response.error({"code":500, "result":"保存数据异常, message=" + error.message});
			});
		}else{
			response.error({"code":500, "result":"SpeedDate不存在(setep=1), speedDateId=" + speedDateId});
		}
	},
	function(error){
		response.error({"code":500, "result":"查询SpeedDate异常(setep=1), speedDateId=" + speedDateId + " ,message=" + error.message});
	});
});