コード例 #1
0
						.done(function(ingredientDatas2) {

							console.log(ingredientDatas2);
							var expected2 = [expected[0]];
							delete ingredientDatas2[0]._id;

							assert.deepEqual(ingredientDatas2, expected2);

							IngredientMongoHelper.updateIngredientBy_id(_id2, 'うに', ingredientData2.amount, user.userID)
							.done(function(result) {

								IngredientMongoHelper.getIngredients(rid)
								.done(function(ingredientDatas3) {

									console.log(ingredientDatas3);

									ingredientData2.ingredient = 'うに';
									delete ingredientData2.userID;
									ingredientData2.userName = user.userName;
									var expected3 = [ingredientData2];

									delete ingredientDatas3[0]._id;
									assert.deepEqual(ingredientDatas3, expected3);

								}, function(err) {});

							}, function(err) {});

						}, function(err) {});
コード例 #2
0
  routeFunc: function(queries) {

    var def = deferred();

    IngredientMongoHelper.getAvailableIngredientNameList()
      .done(function(foodList) {
        def.resolve(foodList);
      }, function(err) {
        console.log(err);
        def.promise(false);
      });

    return def.promise;
  }
コード例 #3
0
		sendIngredient: function(data, resFunc) {
		
			if (!(data.rid && data.ingredient && data.sender && data.amount)) {
				resFunc(false);
				return;
			}

			var rid = data.rid;
			var ingredient = data.ingredient;
			var amount = data.amount;
			var sender = data.sender;
			var ingredientData = {'ingredient': ingredient, 'amount': amount, 'sender': sender};
			IngredientMongoHelper.insertIngredient(rid, ingredient, amount, sender)
			.done(function(result) {
				
				if (!result) {
					resFunc(false);
					return;
				}

				NutritionHelper.getNutritionRates(ingredientData)
				.done(function(nutrition) {
					
					if (!nutritions && nutritions !== null) {
						resFunc(false);
						return;
					}

					var now = TimestampHelper.getTimestamp();
					var resObject = {'nutrition': nutrition, 'ingredient': ingredient};
					this.io.to(data.rid).emit('broadcastAddFood', resObject, function(data) {});
					resFunc(true);
				}, 

				function(err) {
					console.log(err);
					resFunc(false);
				});

			},

			function(err) {
				console.log(err);
				resFunc(false);
			});

		}
コード例 #4
0
		.done(function(isLoggedIn) {

			if (isLoggedIn) {

				IngredientMongoHelper.getIngredients(rid)
				.done(function(result) {
					def.resolve(result);
				}, function(err) {
					console.log(err);
					def.resolve(false);
				});

			} else {
				def.resolve(false);
			}
			

		}, function(err) {
コード例 #5
0
							.done(function(result) {

								IngredientMongoHelper.getIngredients(rid)
								.done(function(ingredientDatas3) {

									console.log(ingredientDatas3);

									ingredientData2.ingredient = 'うに';
									delete ingredientData2.userID;
									ingredientData2.userName = user.userName;
									var expected3 = [ingredientData2];

									delete ingredientDatas3[0]._id;
									assert.deepEqual(ingredientDatas3, expected3);

								}, function(err) {});

							}, function(err) {});
コード例 #6
0
		.done(function(_id1) {
			
			console.log(_id1);

			IngredientMongoHelper.insertIngredient(rid, ingredientData2.ingredient, ingredientData2.amount, ingredientData2.userID)
			.done(function(_id2) {

				console.log(_id2);
				IngredientMongoHelper.getIngredients(rid)
				.done(function(ingredientDatas1) {

					console.log(ingredientDatas1);

					var exIng1 = ingredientData1;
					delete exIng1.userID;
					exIng1.userName = user.userName;

					var exIng2 = ingredientData2;
					delete exIng2.userID;
					exIng2.userName = user.userName;
					
					var expected = [exIng2, exIng1];

					delete ingredientDatas1[0]._id;
					delete ingredientDatas1[1]._id;

					assert.deepEqual(ingredientDatas1, expected);

					IngredientMongoHelper.removeIngredientBy_id(_id1)
					.done(function(result) {

						IngredientMongoHelper.getIngredients(rid)
						.done(function(ingredientDatas2) {

							console.log(ingredientDatas2);
							var expected2 = [expected[0]];
							delete ingredientDatas2[0]._id;

							assert.deepEqual(ingredientDatas2, expected2);

							IngredientMongoHelper.updateIngredientBy_id(_id2, 'うに', ingredientData2.amount, user.userID)
							.done(function(result) {

								IngredientMongoHelper.getIngredients(rid)
								.done(function(ingredientDatas3) {

									console.log(ingredientDatas3);

									ingredientData2.ingredient = 'うに';
									delete ingredientData2.userID;
									ingredientData2.userName = user.userName;
									var expected3 = [ingredientData2];

									delete ingredientDatas3[0]._id;
									assert.deepEqual(ingredientDatas3, expected3);

								}, function(err) {});

							}, function(err) {});

						}, function(err) {});

					}, function(err) {});
				});

			}, function(err) {});

		}, function(err){});