Skip to content
This repository was archived by the owner on Sep 4, 2020. It is now read-only.

Commit 7c54729

Browse files
feat(#3): for new cronjob, search candidates active within the last 2 days
1 parent 5d34e1b commit 7c54729

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

config/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ define("DEFAULT_DISTANCE", 99);
1616

1717
// Discover roommates
1818
define("LIMIT_CANDIDATES", 40); // Find only roommates active in the last x days
19+
define("LIMIT_RECENT_CANDIDATES", 2);
1920
define("LIMIT_TARGETED_USERS", 60);
2021

2122
// Item

controllers/candidates/candidatesHelper.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ const utils = require('../utils/utils');
77

88
const queryUtils = require('../utils/query-utils');
99

10-
const constants = require('../../config/constants');
11-
1210
const Q = require('q');
1311

1412
function CandidatesHelper() {
1513
this.findCandidates = findCandidates;
1614
}
1715

18-
function findCandidates(userIds, page, limit, params) {
16+
function findCandidates(userIds, page, limit, params, lastLoginInDays) {
1917
let deferred = Q.defer();
2018

21-
const startLastLogin = moment(new Date()).startOf('day').add(-1 * constants.LIMIT_CANDIDATES, 'd').toDate();
19+
const startLastLogin = moment(new Date()).startOf('day').add(-1 * lastLoginInDays, 'd').toDate();
2220

2321
// Prepare the query
2422
let query = {

controllers/candidates/get-candidates.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
var mongoose = require('mongoose');
1+
const mongoose = require('mongoose');
22

3-
var CandidatesHelper = require('./candidatesHelper');
3+
const CandidatesHelper = require('./candidatesHelper');
44

5-
var utils = require('../utils/utils');
5+
const utils = require('../utils/utils');
66

7-
var constants = require('../../config/constants');
7+
const constants = require('../../config/constants');
88

9-
module.exports.getCandidates = function (req, res, next) {
10-
var userId = req.params.userId || req.body.userId || req.query.userId || null;
9+
module.exports.getCandidates = (req, res, next) => {
10+
const userId = req.params.userId || req.body.userId || req.query.userId || null;
1111

12-
var userIds = new Array();
12+
const userIds = new Array();
1313
userIds.push(new mongoose.Types.ObjectId(userId));
1414

15-
var limit = constants.LIMIT_QUERY;
16-
var page = null;
15+
const limit = constants.LIMIT_QUERY;
16+
let page = null;
1717
if (!utils.isStringEmpty(req.query.pageIndex)) {
1818
page = parseInt(req.query.pageIndex) * limit;
1919
}
2020

21-
var candidatesHelper = new CandidatesHelper();
21+
const candidatesHelper = new CandidatesHelper();
2222

23-
candidatesHelper.findCandidates(userIds, page, limit, req.query).then(function (users) {
23+
candidatesHelper.findCandidates(userIds, page, limit, req.query, constants.LIMIT_CANDIDATES).then((users) => {
2424
res.format({
25-
json: function () {
25+
json: () => {
2626
res.json(users);
2727
}
2828
});
29-
}, function (err) {
29+
}, (err) => {
3030
res.status(500).json({
3131
error: "Get users error:" + err
3232
});

cronjobs/helpers/push-candidates-helper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
sendPushNotification: sendPushNotification
2020
};
2121

22-
function findCandidates(item, ageMin, ageMax) {
22+
function findCandidates(item, ageMin, ageMax, lastLoginInDays) {
2323
const deferred = Q.defer();
2424

2525
const candidatesHelper = new CandidatesHelper();
@@ -77,9 +77,9 @@ function findCandidates(item, ageMin, ageMax) {
7777
userIds = userIds.concat(dislikes);
7878
}
7979

80-
candidatesHelper.findCandidates(userIds, 0, constants.MAX_ITEM_USERS, query).then(function (users) {
80+
candidatesHelper.findCandidates(userIds, 0, constants.MAX_ITEM_USERS, query, lastLoginInDays).then((users) => {
8181
deferred.resolve(users);
82-
}, function (err) {
82+
}, (err) => {
8383
deferred.reject(new Error(err));
8484
});
8585

cronjobs/push-new-candidates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function hasItemCandidates(item) {
7474
const ageMin = item.userLimitations.age.min === 18 ? 18 : getFilterAgeMin(item.userLimitations.age.min);
7575
const ageMax = item.userLimitations.age.max === 99 ? 99 : getFilterAgeMax(item.userLimitations.age.max);
7676

77-
pushCandidatesHelper.findCandidates(item, ageMin, ageMax).then((users) => {
77+
pushCandidatesHelper.findCandidates(item, ageMin, ageMax, constants.LIMIT_RECENT_CANDIDATES).then((users) => {
7878
deferred.resolve({
7979
item: item,
8080
hasCandidates: utils.isNotEmpty(users)

cronjobs/push-new-items.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function pushNewItems() {
4646
const ageMin = item.userLimitations.age.min;
4747
const ageMax = item.userLimitations.age.max;
4848

49-
promises.push(pushCandidatesHelper.findCandidates(item, ageMin, ageMax));
49+
promises.push(pushCandidatesHelper.findCandidates(item, ageMin, ageMax, constants.LIMIT_CANDIDATES));
5050
}
5151

5252
Promise.all(promises).then((values) => {

0 commit comments

Comments
 (0)