Skip to content

Commit

Permalink
+ Updated Trends Database with category column and updated search fu…
Browse files Browse the repository at this point in the history
…nctionalities with categery include.

   + Updated newsApi trends request.
   +  Added Team reports functionality.
   + Added teamPublishCount in the Team Report, updated deprection of route in Team section, Updated TeamReport Model
   + Added 2- way Authentication for Mail and Mobile, Updated Team insights
   + Updated facebook scopes, pinterest scopes, Pinterest Borad validation Updated, Updated Schedule validations.
   + modified: 1.signup 2.schedule new: 1.TeamReport.
  • Loading branch information
vikashglb committed Oct 18, 2019
1 parent 596a273 commit 4839e55
Show file tree
Hide file tree
Showing 234 changed files with 33,983 additions and 3,160 deletions.
256 changes: 132 additions & 124 deletions socioboard-api/feeds/config/configuration.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ class NetworkInsightController {
});
}

getTeamInsights(req, res) {
var networkInsightLibs = new NetworkInsightLibs();
return networkInsightLibs.getTeamInsights(req.body.userScopeId, req.query.teamId, req.query.filterPeriod, req.query.since, req.query.untill)
.then((response) => {
analyticsServices.registerEvents({
category: req.body.userScopeEmail,
action: configruation.feeds_service_events.event_action.Team,
label: configruation.feeds_service_events.networkInsights_event_label.team_insights.replace('{{user}}', req.body.userScopeName).replace('{{accountId}}', req.query.accountId).replace('{{id}}', req.body.userScopeId).replace('{{teamId}}', req.query.teamId)
});
res.status(200).json({ code: 200, status: "success", result: response });
})
.catch((error) => {
analyticsServices.registerEvents({
category: req.body.userScopeEmail,
action: configruation.feeds_service_events.event_action.Team,
label: configruation.feeds_service_events.networkInsights_event_label.team_insights_failed.replace('{{user}}', req.body.userScopeName).replace('{{accountId}}', req.query.accountId).replace('{{id}}', req.body.userScopeId).replace('{{teamId}}', req.query.teamId)
});
res.status(200).json({ code: 400, status: "failed", error: error.message });
});
}
}
module.exports = new NetworkInsightController();

41 changes: 41 additions & 0 deletions socioboard-api/feeds/core/networkInsights/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,47 @@ routes.get('/getInstagramBusinessInsights', networkSightController.getInstagramB
*/
routes.get('/getTwitterInsights', networkSightController.getTwitterInsights);

/**
* @swagger
* /v1/networkinsights/getTeamInsights:
* get:
* operationId: secured_networkinsights_getTeamInsights
* summary: Secured
* security:
* - AccessToken: []
* tags:
* - NetworkInsights
* description: To fetch the Team insights
* produces:
* - application/json
* parameters:
* - in: query
* description: Team Id
* name: teamId
* type: integer
* - in: query
* description: Filter Period 1- Today, 2-Yesterday, 3-Last week, 4-Last 30 days, 5- this month, 6- last month, 7- custom range
* name: filterPeriod
* type: integer
* enum: [1,2,3,4,5,6,7]
* - in: query
* description: Custom since range in YYYY-MM-DD format
* name: since
* type: string
* - in: query
* description: Custom untill range in YYYY-MM-DD format
* name: untill
* type: string
* responses:
* 200:
* description: Return success!
* 404:
* description: Return Not Found or ErrorMessage
* 401:
* $ref: "#/responses/unauthorizedError"
*/
routes.get('/getTeamInsights', networkSightController.getTeamInsights);

module.exports = routes;


Expand Down
231 changes: 182 additions & 49 deletions socioboard-api/feeds/core/networkInsights/utils/networkinsightlibs.js

Large diffs are not rendered by default.

213 changes: 210 additions & 3 deletions socioboard-api/library/mixins/userteamaccount.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const db = require('../sequelize-cli/models/index');
const CoreServices = require('../utility/coreServices');
const TeamInsightsMongoModel = require('../mongoose/models/teamInsights');
const PublishedPostsMongoModel = require('../mongoose/models/publishedposts');
const moment = require('moment');
const lodash = require('lodash');

const socialAccount = db.social_accounts;
const scheduleDetails = db.users_schedule_details;
const userDetails = db.user_details;
const userTeamJoinTable = db.join_table_users_teams;
const teamSocialAccountJoinTable = db.join_table_teams_social_accounts;
const accountFeedsUpdateTable = db.social_account_feeds_updates;
const Operator = db.Sequelize.Op;

const teamInfo = db.team_informations;
const updateFriendsTable = db.social_account_friends_counts;

const coreServices = new CoreServices();
Expand Down Expand Up @@ -275,9 +277,214 @@ const UserTeamAccount = {
.catch((error) => reject(error));
}
});
}
},

createOrUpdateTeamReport(teamId, update) {
return new Promise((resolve, reject) => {
if (!teamId) {
reject(new Error("Invalid Inputs"));
} else {
var teamDetails = null;
var SocialAccountStats = {};
SocialAccountStats.facebookStats = [];
SocialAccountStats.twitterStats = [];
SocialAccountStats.instagramStats = [];
SocialAccountStats.youtubeStats = [];
var teamMembers = 0;
var invitedList = 0;
var socialProfiles = 0;
var data = {};
var updatedData = {};

return teamInfo.findAll({
where: {
team_id: teamId
},
attributes: ['team_id', 'team_name', 'team_logo', 'team_description', 'team_admin_id'],
include: [{
model: socialAccount,
as: 'SocialAccount',
attributes: ['account_id', 'account_type', 'first_name', 'last_name', 'email', 'social_id', 'profile_pic_url', 'cover_pic_url', 'friendship_counts'],
through: {
attributes: ['is_account_locked']
}
}]
})
.then((teamSocialAccounts) => {
teamDetails = teamSocialAccounts;
return userTeamJoinTable.findAll({
where: {
team_id: teamId,
},
attributes: ['id', 'team_id', 'invitation_accepted', 'permission', 'user_id'],
raw: true
});
})
.then((teamMembersData) => {
teamMembersData.forEach(element => {
if (element.invitation_accepted == true) {
teamMembers += 1;
}
if (element.invitation_accepted == false) {
invitedList += 1;
}
});
return Promise.all(teamDetails.map(accounts => {
socialProfiles = accounts.SocialAccount.length;
return Promise.all(accounts.SocialAccount.map(account => {
var fields = [];
switch (Number(account.account_type)) {
case 1:
fields = ['account_id', 'friendship_count', 'page_count'];
break;
case 4:
fields = ['account_id', 'follower_count', 'following_count', 'total_like_count', 'total_post_count'];
break;
case 5:
fields = ['account_id', 'friendship_count', 'follower_count', 'following_count', 'total_post_count'];
break;
case 9:
fields = ['account_id', 'subscription_count', 'total_post_count'];
break;
default:
break;
}
if (fields.length > 0) {
return updateFriendsTable.findOne({
where: { account_id: account.account_id },
attributes: fields,
raw: true
})
.then((resultData) => {
var data = resultData;
switch (Number(account.account_type)) {
case 1:
SocialAccountStats.facebookStats.push({ facebookStats: data });
break;
case 4:
SocialAccountStats.twitterStats.push({ twitterStats: data });
break;
case 5:
SocialAccountStats.instagramStats.push({ instagramStats: data });
break;
case 9:
SocialAccountStats.youtubeStats.push({ youtubeStats: data });
break;
default:
break;
}
})
.catch((error) => {
throw error;
});
}
}));
}));
})
.then(() => {
var publishedPostsMongoModelObject = new PublishedPostsMongoModel();
return publishedPostsMongoModelObject.getTeamPublishedCount(teamId);
})
.then((publishedCount) => {
data = {
teamId: teamId,
insights: {
teamMembersCount: teamMembers,
invitedList: invitedList,
socialProfilesCount: socialProfiles,
publishCount: publishedCount,
SocialAccountStats: SocialAccountStats
}
};
updatedData = [{
teamMembersCount: teamMembers,
invitedList: invitedList,
socialProfilesCount: socialProfiles,
publishCount: publishedCount,
SocialAccountStats: SocialAccountStats
}];
var teamInsightsMongoModelObject = new TeamInsightsMongoModel();
// insertInsights(data) then addTeamInsights(teamId, updatedData)
// update or insert, Update status is', update, 'update data is \n\n', updatedData;
if (!update || update == null || update == false)
return teamInsightsMongoModelObject.insertInsights(data);
else
return teamInsightsMongoModelObject.addTeamInsights(teamId, updatedData);
})
.then(() => {
resolve(updatedData);
})
.catch((error) => {
reject(error);
});
}
});
},

getTeamSocialAccounts(userId, teamId) {
return new Promise((resolve, reject) => {
if (!userId || !teamId) {
reject(new Error('Invalid Inputs'));
} else {
var filteredTeams = null;
return userDetails.findOne({
where: { user_id: userId },
attributes: ['user_id'],
include: [{
model: teamInfo,
as: 'Team',
where: { team_id: teamId },
attributes: ['team_id'],
through: {
where: {
[Operator.and]: [{
invitation_accepted: true
}, {
left_from_team: false
}]
}
}
}]
})
.then((teamInformation) => {
filteredTeams = teamInformation;
if (!teamInformation) {
throw new Error("Team not found or access denied!");
}
else if (teamInformation.count == 0) {
throw new Error({
isNoTeam: true,
message: "User don't have any team!"
});
}
else {
return Promise.all(teamInformation.Team.map(function (teamResponse) {
return teamInfo.findAll({
where: {
team_id: teamResponse.dataValues.team_id
},
attributes: ['team_id', 'team_name', 'team_logo', 'team_description', 'team_admin_id'],
include: [{
model: socialAccount,
as: 'SocialAccount',
attributes: ['account_id', 'account_type', 'first_name', 'last_name', 'email', 'social_id', 'profile_pic_url', 'cover_pic_url', 'friendship_counts'],
through: {
attributes: ['is_account_locked']
}
}]
});
}));
}
})
.then((teamDetails) => {
resolve({ teamDetails, filteredTeams });
})
.catch((error) => {
reject(error);
})
}
})
}


};
Expand Down
2 changes: 1 addition & 1 deletion socioboard-api/library/mongoose/models/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ notificationInfo.methods.getNotificationsDetails = function (id, teamId, userId,

return this.model('Notifications')
.find(query)
.sort({ publishedDate: -1 })
.sort({ dateTime: -1 })
.skip(skip)
.limit(limit)
.then((result) => {
Expand Down
15 changes: 15 additions & 0 deletions socioboard-api/library/mongoose/models/publishedposts.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ publishedPost.methods.getAccountPublishCount = function (accountId) {
});
};

publishedPost.methods.getTeamPublishedCount = function (teamId) {
// Fetching total posts counts published in an account
var query = {
TeamId: Number(teamId)
};
return this.model('PublishedPosts')
.find(query)
.then((result) => {
return result.length;
})
.catch((error) => {
throw error;
});
};

publishedPost.methods.getSchedulePublishedReport = function (mongoId, skip, limit) {

// Fetching publish details of a specified content id
Expand Down
Loading

0 comments on commit 4839e55

Please sign in to comment.