Commit 41eeb938 authored by soheib's avatar soheib
Browse files

comment check user is follower

parent 447e96bd
......@@ -36,12 +36,12 @@ import { StoryMentionSchema } from './instagram/models/storyMention.schema'
MongooseModule.forFeature([
{ name: 'Post', schema: PostSchema },
]),
MongooseModule.forFeature([
{ name: 'StoryMention', schema: StoryMentionSchema },
]),
MongooseModule.forFeature([
{ name: 'StoryMention', schema: StoryMentionSchema },
]),
InstagramModule,
LotteryModule,
],
......
......@@ -59,6 +59,8 @@ export class InstagramService implements OnApplicationBootstrap {
async getLikesFromInstaLoader(username: string, password: string, post_short_code: string, profile: string) {
console.log('start getting likes');
let paths = path.resolve("src", "instagram", "instaloader-service", "getLikes.py")
const getLikesProccess = spawn('python3', [`${paths}`, `${username}`, `${password}`, `${post_short_code}`, `${profile}`,])
......@@ -79,6 +81,7 @@ export class InstagramService implements OnApplicationBootstrap {
}
async getCommentsFromInstaLoader(username: string, password: string, post_short_code: string, profile: string) {
let paths = path.resolve("src", "instagram", "instaloader-service", "getComments.py")
console.log(paths);
const getCommentsProccess = spawn('python3', [`'${paths}`, `${username}`, `${password}`, `${post_short_code}`, `${profile}`])
......
......@@ -31,76 +31,76 @@ export class ScoreService {
async getUserLikesScore(user_id: string, profileUsername: string, postArray: string[]) {
let foundAccount = await this.userModel.findOne({ username: profileUsername })
let isfollowerValid = await this.followerModel.findOne({
$and: [
{ user_id: new Types.ObjectId(user_id) },
{ account_id: foundAccount._id }
]
})
if (isfollowerValid) {
let score = 0
for await (const post of postArray) {
let foundPost = await this.postModel.findOne({ url: post })
let foundLike = await this.likeModel.findOne({
$and: [
{
user_id: new Types.ObjectId(user_id)
},
{
post_id: new Types.ObjectId(foundPost._id)
}
]
})
if (foundLike) {
score++
}
// let foundAccount = await this.userModel.findOne({ username: profileUsername })
// let isfollowerValid = await this.followerModel.findOne({
// $and: [
// { user_id: new Types.ObjectId(user_id) },
// { account_id: foundAccount._id }
// ]
// })
// if (isfollowerValid) {
let score = 0
for await (const post of postArray) {
let foundPost = await this.postModel.findOne({ url: post })
let foundLike = await this.likeModel.findOne({
$and: [
{
user_id: new Types.ObjectId(user_id)
},
{
post_id: new Types.ObjectId(foundPost._id)
}
]
})
if (foundLike) {
score++
}
return score
}
else {
return 0
}
return score
// }
// else {
// return 0
// }
}
async getUserCommentsScore(user_id: string, profileUsername: string, postArray: string[]) {
let foundAccount = await this.userModel.findOne({ username: profileUsername })
let isfollowerValid = await this.followerModel.findOne({
$and: [{ user_id: new Types.ObjectId(user_id) }
, { account_id: foundAccount._id }]
})
if (isfollowerValid) {
let userCommentScore = new Array<{ post_id: string, post_score: number }>()
for await (const post of postArray) {
let foundPost = await this.postModel.findOne({ url: post })
userCommentScore.push({
post_id: foundPost._id,
post_score: 0
})
}
let foundUserComments = await this.commentModel.find({ user_id: new Types.ObjectId(user_id) })
for await (const comment of foundUserComments) {
userCommentScore.forEach(element => {
if (comment.post_id.toString() === element.post_id.toString() && element.post_score < 3) {
element.post_score++
}
})
}
let score = 0
userCommentScore.forEach(element => {
score += element.post_score
// let foundAccount = await this.userModel.findOne({ username: profileUsername })
// let isfollowerValid = await this.followerModel.findOne({
// $and: [{ user_id: new Types.ObjectId(user_id) }
// , { account_id: foundAccount._id }]
// })
// if (isfollowerValid) {
let userCommentScore = new Array<{ post_id: string, post_score: number }>()
for await (const post of postArray) {
let foundPost = await this.postModel.findOne({ url: post })
userCommentScore.push({
post_id: foundPost._id,
post_score: 0
})
return score
}
else {
return 0
let foundUserComments = await this.commentModel.find({ user_id: new Types.ObjectId(user_id) })
for await (const comment of foundUserComments) {
userCommentScore.forEach(element => {
if (comment.post_id.toString() === element.post_id.toString() && element.post_score < 3) {
element.post_score++
}
})
}
let score = 0
userCommentScore.forEach(element => {
score += element.post_score
})
return score
// }
// else {
// return 0
// }
}
async getTagsScore(user_id: string) {
let addToStoryScore = 0
let foundUserInStory = await this.storyMentionModel.findOne({user_id: new Types.ObjectId(user_id)})
let foundUserInStory = await this.storyMentionModel.findOne({ user_id: new Types.ObjectId(user_id) })
if (foundUserInStory) {
addToStoryScore = foundUserInStory.count
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment