Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let clientAssignedQues = [];
- LoanStates.find({ _id: { $in: req.user.client.loanStates } }).exec((err, loanStates) => {
- if (err)
- return res._end(new ServiceError(err.message, ServiceError.STATUS.INTERNAL_SERVER_ERROR, ServiceError.CODE.ERROR_MONGODB_FIND));
- loanStates.forEach(state => {
- state.questionnaires.forEach(ques => {
- clientAssignedQues.push(ques);
- });
- });
- clientAssignedQues = _.concat(clientAssignedQues, req.user.client.createCustomerQuestionnaires);
- clientAssignedQues = _.uniq(clientAssignedQues);
- // console.log(clientAssignedQues);
- QuestionnaireClient.find({ client: req.user.client._id }).sort('createdAt').exec((err, questionnaires) => {
- if (err)
- return res._end(new ServiceError(err.message, ServiceError.STATUS.INTERNAL_SERVER_ERROR, ServiceError.CODE.ERROR_MONGODB_FIND));
- let existedQuestionnaires = [];
- questionnaires.forEach((item) => {
- existedQuestionnaires.push(item.questionnaireCard.toString())
- });
- let unusedQues = _.difference(clientAssignedQues, existedQuestionnaires);
- console.log(unusedQues);
- QuestionnaireModel.find({ _id: { $in: unusedQues } }).populate('business questionnaireCard')
- .exec((err, questionnaires) => {
- if (err)
- return res._end(new ServiceError(err.message, ServiceError.STATUS.INTERNAL_SERVER_ERROR, ServiceError.CODE.ERROR_MONGODB_FIND));
- res._end({ questionnaires: questionnaires });
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement