userRelationShipService.prototype.unfollow = function(params, callback) { try { validator.has(params, ['followUserId', 'followedUserId']); validator.unsignedInteger(params.followUserId); validator.unsignedInteger(params.followedUserId); validator.function(callback); } catch (error) { callback(error); return; } async.waterfall([ // 取得 function(callback) { userRelationShipDao.getByFollowUserIdAndFollowedUserId({ followUserId: params.followUserId, followedUserId: params.followedUserId }, callback); }, // 更新処理 function(userRelationShip ,callback) { if (userRelationShip && !userRelationShip.deleteFlag) { userRelationShipDao.updateDeleteFlag({ followUserId: params.followUserId, followedUserId: params.followedUserId, deleteFlag: true }, callback); } else { callback(); } } ], callback); }
userRelationShipService.prototype.matchingNotification = function(params, callback) { try { validator.has(params, ['fromUserId', 'toUserId']); validator.unsignedInteger(params.fromUserId); validator.unsignedInteger(params.toUserId); validator.function(callback); } catch (error) { callback(error); return; } async.parallel([ // 相手にfacebook通知を送信 function(callback) { facebookService.notification({ toUserId: params.toUserId, fromUserId: params.fromUserId, code: facebookNotificationDao.code.matching }, function(error, result) { callback(error); }); }, // 自分にfacebook通知を送信 function(callback) { facebookService.notification({ toUserId: params.fromUserId, fromUserId: params.toUserId, code: facebookNotificationDao.code.matching }, function(error, result) { callback(error); }); }, ], callback); }
BaseJsonDao.prototype.getAllMap = function(callback) { try { validator.function(callback); } catch (error) { callback(error); return; } callback(null, this.jsonData || null); }
BaseJsonDao.prototype.getById = function(id, callback) { try { validator.unsignedInteger(id); validator.function(callback); } catch (error) { callback(error); return; } callback(null, this.jsonData[id] || null); }
BaseJsonDao.prototype.getByCode = function(code, callback) { try { validator.string(code); validator.function(callback); } catch (error) { callback(error); return; } var data = _.find(this.jsonData, function(value, key) { return value.code === code; }); callback(null, data || null); }
Map2TreasureDao.prototype.getListByMapId = function(mapId, callback) { try { validator.string(mapId); validator.function(callback); } catch (error) { callback(error); return; } var self = this; var connection = self.connection; connection.query('select * from map2treasure where mapId = ' + '"' + mapId + '"', function(error, result) { callback(error, result) }); }
LikeService.prototype.like = function(params, callback){ try { validator.unsignedInteger(params.userId); validator.unsignedInteger(params.postId); validator.function(callback); } catch (error) { callback(error); return; } async.waterfall([ // like情報を取得 function(callback) { likeDao.getByUserIdAndPostId({ userId: params.userId, postId: params.postId }, callback); }, // 追加or更新 function(like, callback) { // 追加 if (like === null) { likeDao.add({ userId: params.userId, postId: params.postId }, callback); // like更新 } else if (like.deleteFlag) { likeDao.updateDeleteFlag({ userId: params.userId, postId: params.postId, deleteFlag: false }, callback); // unLike更新 } else if (!like.deleteFlag) { likeDao.updateDeleteFlag({ userId: params.userId, postId: params.postId, deleteFlag: true }, callback); } } ], callback); }
userRelationShipService.prototype.follow = function(params, callback) { try { validator.has(params, ['followUserId', 'followedUserId']); validator.unsignedInteger(params.followUserId); validator.unsignedInteger(params.followedUserId); validator.function(callback); } catch (error) { callback(error); return; } async.waterfall([ // 取得 function(callback) { userRelationShipDao.getByFollowUserIdAndFollowedUserId({ followUserId: params.followUserId, followedUserId: params.followedUserId }, callback); }, // 更新処理 function(userRelationShip ,callback) { // 登録データがない場合は新規でデータを追加 if (!userRelationShip) { userRelationShipDao.add({ followUserId: params.followUserId, followedUserId: params.followedUserId }, callback); return; // 削除フラグがtureだったら更新をかける } else if (userRelationShip.deleteFlag) { userRelationShipDao.updateDeleteFlag({ followUserId: params.followUserId, followedUserId: params.followedUserId, deleteFlag: false }, callback); return; } callback(); } ], callback); }
User2MapDao.prototype.getByUserId = function(userId, callback) { try { validator.string(userId); validator.function(callback); } catch (error) { callback(error); return; } var self = this; var connection = self.connection; connection.query('select * from user2map where userId = ' + '"' + userId + '"', function(error, result) { if (error) { callback(error); return } callback(null, _.first(result)); }); }
userRelationShipService.prototype.checkMatching = function(params, callback) { try { validator.has(params, ['followUserId', 'followedUserId']); validator.unsignedInteger(params.followUserId); validator.unsignedInteger(params.followedUserId); validator.function(callback); } catch (error) { callback(error); return; } async.parallel({ // フォローしているか判定 isFollow: function(callback) { userRelationShipDao.isFollow({ followUserId: params.followUserId, followedUserId: params.followedUserId }, callback); }, // フォローされているか判定 isFollowed: function(callback) { userRelationShipDao.isFollow({ followUserId: params.followedUserId, followedUserId: params.followUserId }, callback); }, }, function(error, result) { if (error) { callback(error); return; } var matchingFlag = false if (result.isFollow && result.isFollowed) { matchingFlag = true; } callback(null, matchingFlag); }); }