NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

else {
/* Load content A/c to category & subcategory */
let profileDetail = await Profile.findOne({ _id: req.query.profileId })
.select('category subCategory userId -_id');
console.log(profileDetail,'profileDetail');
let findAllProfile = await Profile.find({ userId: profileDetail.userId })
.select('subCategory -_id');
console.log(findAllProfile,'findAllProfile');

let subCategoryArray = [];
findAllProfile.map((a) => {
subCategoryArray.push(a.subCategory[ZERO]);
});


var filterQuery;
switch (req.query.type) {
case "1":
filterQuery = {
updatedAt: constant.MINUS_ONE
};
break;
case "2":
filterQuery = {
updatedAt: constant.ONE
};
break;
default:
filterQuery = {updatedAt: constant.MINUS_ONE};
}
let pageNo = parseInt(req.query.pageNo) || constant.ONE;
let pageLimit = parseInt(req.query.pageLimit) || constant.PAGE_LIMIT_TWO_ZERO;
if (pageNo <= constant.ZERO) {
throw { message: responseMessage.PAGE_INVALID };
}
let filter = [];

let filterData = {};
if (req.query.search) {
filterData =
{$or:[
{"profileId.username":{$regex: req.query.search ? req.query.search : "",$options: "i"}},
{"category.categoryName":{$regex: req.query.search ? req.query.search : "",$options: "i"}},
{"subCategory.subCategoryName":{$regex: req.query.search ? req.query.search : "",$options: "i"}},
{"keyWords.keywordName":{$regex: req.query.search ? req.query.search : "",$options: "i"}},
{"hashTags.hashtagName":{$regex: req.query.search ? req.query.search : "",$options: "i"}},
{tittle:{$regex: req.query.search ? req.query.search : "",$options: "i"}},
{description:{$regex: req.query.search ? req.query.search : "",$options: "i"}},
]}
}
if (req.query.status == constant.ZERO) {
let forYou = await Content.aggregate([
{
$match:{ isPublish: constant.ONE}
},
{
$match: {category: profileDetail.category[ZERO] }
},
// {
// $match: {category: {$in: subCategoryArray } }
// },
{
$lookup: {
from: "userprofiles",
let: { id: "$profileId" },
pipeline: [{
$match: {
$expr: { $eq: ["$_id", "$$id"] }
}
}, ],
as: "profileId"
}
},
{
$lookup: {
from: "categories",
let: { id: "$category" },
pipeline: [{
$match: {
$expr: { $eq: ["$_id", "$$id"] }
}
}, ],
as: "category"
}
},
{
$lookup: {
from: "subcategories",
let: { id: "$subCategory" },
pipeline: [{
$match: {
$expr: { $eq: ["$_id", "$$id"] }
}
}, ],
as: "subCategory"
}
},
{
$lookup: {
from: "keywords",
let: { id: "$keyWords" },
pipeline: [{
$match: {
$expr: { $eq: ["$_id", "$$id"] }
}
}, ],
as: "keyWords"
}
},
{
$lookup: {
from: "hashtags",
let: { id: "$hashTags" },
pipeline: [{
$match: {
$expr: { $eq: ["$_id", "$$id"] }
}
}, ],
as: "hashTags"
}
},
{
$match:filterData
},
{
$lookup: {
from: "contentcomments",
let: { id: "$_id" },
pipeline: [{
$match: {
$expr: { $eq: ["$$id", "$contentId"] }
}
}, ],
as: "comments"
}
},
{
$addFields: {
likeCount: { $size: '$like' },
replyCount: { $size: '$comments' },
// isLiked: { $in: [mongoose.Types.ObjectId(req.userId),"$like"] },
isLiked: { $in: [mongoose.Types.ObjectId(req.query.profileId),"$like"] },
// totalCount: {$count: "$count"},
}
},
{
$sort: { updatedAt: -1 },
},
{ $skip: pageLimit * (pageNo - constant.ONE) },
{ $limit: pageLimit },
{
$facet: {
data: [
{ $skip: pageLimit * (pageNo - constant.ONE) },
{ $limit: pageLimit },
],
count: [
{
$count: "count",
},
],
},
},
{
$project:{
"data":"$data",
count:{ $arrayElemAt: [ "$count.count", constant.ZERO ] }
}
}



]);

let totalData = await forYou[constant.ZERO].count;

var tempPage = 1;
while(tempPage){
if(totalData <= PAGE_LIMIT_TWO_ZERO || totalData <= PAGE_LIMIT_TWO_ZERO * tempPage ){
tempPage;
break;
}
tempPage++
}

let currentPage= await req.query.pageNo;

res
.status(statusCode.SUCCESS)
.send({
success: true,
message: responseMessage.RECORD_FOUND,
data: forYou[constant.ZERO].data,
totalCount:forYou[constant.ZERO].count,
currentPage:parseInt(currentPage),
totalPages: tempPage
})
}
if(req.query.status==constant.ONE){ //like
filter.push(
{
$lookup: {
from: "userprofiles",
let: { id: "$like" },
pipeline: [{
$match: {
// $expr: { $eq: ["$$id", "$_id"] }
$expr: { $in: ["$_id", "$$id"] }
}
}, ],
as: "liked"
}
},
{
$addFields: {
isLiked: { $in: [mongoose.Types.ObjectId(req.query.profileId),"$like"] },
}
},
{
$match:{isLiked: {$eq: true}}
},
{
$match:filterData
},
)
}
if(req.query.status==constant.TWO){ //expert
filter.push(
{
$lookup: {
from: "userprofiles",
let: { id: "$category" },
pipeline: [{
$match: {
$expr: { $eq: ["$category","$$id" ] }
}
}, ],
as: "expert"
}
},
{
$match:filterData
},
)
}
if(req.query.status==constant.THREE){ //following
let isFollowerExist = await Follower.findOne({followedBy: req.query.profileId})
if(!isFollowerExist){
res
.status(statusCode.SUCCESS)
.send({
success: true,
message: "Data not found",
})
}
filter.push(
{
$lookup: {
from: "followers",
let: { id: "$profileId" },
pipeline: [{
$match: {
$expr: { $eq: ["$$id", "$follow_user"] }
},
}],
as: "following"
}
},
{
$addFields: {
isUserFollowing: {
$cond: {
if: {
$in: [mongoose.Types.ObjectId(req.query.profileId),
{$cond:{if:"$following.followedBy",then: "$following.followedBy",
else: []}}]
},
then: true,
else: false
},
}
}
},
{
$match: {isUserFollowing: true}
},
{
$project:{
following: ZERO
}
},
// set1["following.$.followedBy"] = req.query.profileId,
{
$match:filterData
},
)
}
if(req.query.status==constant.FOUR){ //purchase
filter.push(
{
$lookup: {
from: "Subscriptions",
let: { id: "$profileId" },
pipeline: [{
$match: {
$expr: { $eq: ["$$id", "$purchagedBy"] }
}
},],
as: "purchase"
}
},
{
$match:filterData
},
)
}
if(req.query.status ==constant.FIVE){ //media
let isAnyMediaPosted = await Content.findOne({profileId: req.query.profileId})
if(!isAnyMediaPosted){
res
.status(statusCode.SUCCESS)
.send({
success: true,
message: "You did not post any media",
})
return
}
await filter.push(
{
$match: { profileId: mongoose.Types.ObjectId(req.query.profileId) }
},
{
$match:filterData
},
)
}
if(req.query.status ==constant.SIX){ //location
filter.push(
{
$geoNear: {
near: {
type: "Point",
coordinates: [
parseFloat(req.query.longitude),
parseFloat(req.query.latitude),
],
},
spherical: true,
distanceField: CALC_DISTANCE,
maxDistance: MAX_DIST,
},
},
{
$match:filterData
},
)
}
let forYou = await Content.aggregate([
{
$match:{ isPublish: constant.ONE}
},
...filter,
{
$lookup: {
from: "userprofiles",
let: { id: "$profileId" },
pipeline: [{
$match: {
$expr: { $eq: ["$_id", "$$id"] }
}
}, ],
as: "profileId"
}
},
// {$unwind: "$profileId"},
{
$lookup: {
from: "categories",
let: { id: "$category" },
pipeline: [{
$match: {
$expr: { $eq: ["$_id", "$$id"] }
}
}, ],
as: "category"
}
},
{
$lookup: {
from: "subcategories",
let: { id: "$subCategory" },
pipeline: [{
$match: {
$expr: { $eq: ["$_id", "$$id"] }
}
}, ],
as: "subCategory"
}
},
{
$lookup: {
from: "keywords",
let: { id: "$keyWords" },
pipeline: [{
$match: {
$expr: { $eq: ["$_id", "$$id"] }
}
}, ],
as: "keyWords"
}
},
{
$lookup: {
from: "hashtags",
let: { id: "$hashTags" },
pipeline: [{
$match: {
$expr: { $eq: ["$_id", "$$id"] }
}
}, ],
as: "hashTags"
}
},
{
$lookup: {
from: "contentcomments",
let: { id: "$_id" },
pipeline: [{
$match: {
$expr: { $eq: ["$$id", "$contentId"] }
}
}, ],
as: "comments"
}
},
// {
// $match: { profileId: req.query.profileId }
// },
{
$addFields: {
likeCount: { $size: '$like' },
replyCount: { $size: '$comments' },
// isLiked: { $in: [mongoose.Types.ObjectId(req.userId),"$like"] },
isLiked: { $in: [mongoose.Types.ObjectId(req.query.profileId),"$like"] },
}
},
// ...filter,
{
$sort: filterQuery,
},
{
$facet: {
data: [
{ $skip: pageLimit * (pageNo - constant.ONE) },
{ $limit: pageLimit },
],
count: [
{
$count: "count",
},
],
},
},
{
$project:{
"data":"$data",
count:{ $arrayElemAt: [ "$count.count", constant.ZERO ] },
}
}
]);
let totalData = await forYou[constant.ZERO].count;

var tempPage = 1;
while(tempPage){
if(totalData <= PAGE_LIMIT_TWO_ZERO || totalData <= PAGE_LIMIT_TWO_ZERO * tempPage ){
tempPage;
break;
}
tempPage++
}

let currentPage= await req.query.pageNo;


if(forYou[constant.ZERO].data[0].isMatch == false){
res
.status(statusCode.SUCCESS)
.send({
success: true,
message: "Data not found",
})
}


if(forYou[constant.ZERO].data.length){
res
.status(statusCode.SUCCESS)
.send({
success: true,
message: responseMessage.RECORD_FOUND,
data: forYou[constant.ZERO].data,
totalCount:forYou[constant.ZERO].count,
currentPage:parseInt(currentPage),
totalPages: tempPage
})
} else {
res
.status(statusCode.SUCCESS)
.send({
success: true,
message: responseMessage.NOT_FOUND("Record")
})
}

}
}
catch(err){
await setResponseObject(req, false, err.message);
next();
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.