Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Update to all User, Publish & Update services #321

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import calenderViewService from './calender-view.service.js';
*/
class CalenderViewController {
/**
* TODO To get scheduled details for calender view
* Get all scheduling details.
* @param {import('express').Request} req have optional schedule_status, schedule_type
* @param {import('express').Response} res
* @param {import('express').NextFunction} next
* @return {object} Returns scheduled details
*/
* TODO To get scheduled details for calender view
* Get all scheduling details.
* @param {import('express').Request} req have optional schedule_status, schedule_type
* @param {import('express').Response} res
* @param {import('express').NextFunction} next
* @return {object} Returns scheduled details
*/
async scheduleDetails(req, res, next) {
/* #swagger.tags = ['Calender View']
#swagger.description = 'To get the schedule details of the user by category' */
Expand All @@ -26,6 +26,10 @@ class CalenderViewController {
/* #swagger.parameters['scheduleStatus'] = {
in: 'query',
description: 'schedule status,1- ready Queue, 2-wait(pause), 3-approvalpending, 4-rejected, 5-draft, 6-done'
}
#swagger.parameters['teamId'] = {
in: 'query',
description: 'Team id'
}
#swagger.parameters['scheduleCategory'] = {
in: 'query',
Expand Down
22 changes: 15 additions & 7 deletions socioboard-api/Publish/core/calender-view/calender-view.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* @typedef {import('../../../Common/Shared/response.shared.js')}
*/
import { SuccessResponse, CatchResponse } from '../../../Common/Shared/response.shared.js';
import {
SuccessResponse,
CatchResponse,
} from '../../../Common/Shared/response.shared.js';

/**
* @typedef {import('../../../Common/Models/schedule.model.js')}
Expand All @@ -19,14 +22,19 @@ const scheduleModel = new ScheduleModel();
*/
class CalenderViewService {
/**
* TODO To get scheduled details for calender view
* @param {import('express').Request} req
* @param {import('express').Response} res
* @return {object} Returns scheduled details
*/
* TODO To get scheduled details for calender view
* @param {import('express').Request} req
* @param {import('express').Response} res
* @return {object} Returns scheduled details
*/
async scheduleDetails(req, res) {
try {
const response = await scheduleModel.getScheduleDetailsForCalenderView(req.body.userScopeId, req.query.scheduleStatus, req.query.scheduleCategory);
const response = await scheduleModel.getScheduleDetailsForCalenderView(
req.body.userScopeId,
req.query.scheduleStatus,
req.query.scheduleCategory,
req.query.teamId
);

SuccessResponse(res, response);
} catch (error) {
Expand Down
67 changes: 60 additions & 7 deletions socioboard-api/Publish/core/publish/publish.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PublisherLibs from '../../../Common/Models/publish.model.js';
import bitlyCluster from '../../../Common/Cluster/bitly.cluster.js';
import TeamLibs from '../../../Common/Models/team.model.js';
import BITLY_CONSTANTS from '../../../Common/Constants/bitly.constants.js';
import { CatchResponse } from '../../../Common/Shared/response.shared.js';
import {CatchResponse} from '../../../Common/Shared/response.shared.js';

const teamLibs = new TeamLibs();

Expand Down Expand Up @@ -162,15 +162,17 @@ class PublishController {

async publishPostMiddleware(req, res, next) {
try {
const { link, userScopeId: userId } = req.body;
const {link, userScopeId: userId} = req.body;

req.body.link = link && await this.shortenPostLinkByBitly(link, userId);
req.body.link = link && (await this.shortenPostLinkByBitly(link, userId));

return next();
} catch (error) {
const errorMessage = error?.error?.message;

if (errorMessage === BITLY_CONSTANTS.ERROR_MESSAGES.ALREADY_A_BITLY_LINK) {
if (
errorMessage === BITLY_CONSTANTS.ERROR_MESSAGES.ALREADY_A_BITLY_LINK
) {
return next();
}

Expand All @@ -195,15 +197,66 @@ class PublishController {
async findBitlyAccount(userId) {
const foundUserAccounts = await teamLibs.getSocialProfiles(userId);

return foundUserAccounts.find(({ dataValues }) => dataValues.account_type === BITLY_CONSTANTS.ACCOUNT_TYPE);
return foundUserAccounts.find(
({dataValues}) => dataValues.account_type === BITLY_CONSTANTS.ACCOUNT_TYPE
);
}

async shortenLink(longUrl, account) {
const { dataValues: { access_token: accessToken }} = account;
const {
dataValues: {access_token: accessToken},
} = account;

const { link } = await bitlyCluster.shortenLink(accessToken, { long_url: longUrl });
const {link} = await bitlyCluster.shortenLink(accessToken, {
long_url: longUrl,
});

return link;
}

async filterPublishedPosts(req, res, next) {
/* #swagger.tags = ['Publish']
#swagger.description = 'To get all published posts' */
/* #swagger.security = [{
"AccessToken": []
}] */
/* #swagger.parameters['teamId'] = {
in: 'query',
description: 'Enter team id',
}
#swagger.parameters['pageId'] = {
in: 'query',
description: 'pagination id'
}
#swagger.parameters['publishedStatus'] = {
in: 'query',
description: 'pagination id'
}
#swagger.parameters['criteria'] = {
in: 'body',
description: 'Criteria to filter',
required: true,
schema: { $ref: "#/definitions/searchPublishedPost" }
}
#swagger.parameters['filterPeriod'] = {
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',
enum: [1,2,3,4,5,6,7]
}
#swagger.parameters['since'] = {
in: 'query',
description: 'Custom since range in YYYY-MM-DD format'
}
#swagger.parameters['until'] = {
in: 'query',
description: 'Custom until range in YYYY-MM-DD format'
}
#swagger.parameters['publishedStatus'] = {
in: 'query',
description: 'Success or failed',
enum: ['Success','Failed']
} */
return await PublishService.filterPublishedPosts(req, res, next);
}
}
export default new PublishController();
18 changes: 14 additions & 4 deletions socioboard-api/Publish/core/publish/publish.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ import PublishController from './publish.controller.js';

const router = Router();

router.post('/publishPosts', PublishController.publishPostMiddleware.bind(PublishController), PublishController.publishPost);
router.post(
'/publishPosts',
PublishController.publishPostMiddleware.bind(PublishController),
PublishController.publishPost
);
router.get('/get-drafted-posts', PublishController.getDraftedPosts);
router.get('/get-draft-post-by-id', PublishController.getDraftPostById);
router.put('/update-draft-post-by-id', PublishController.updateDraftPostById);
router.delete('/delete-draft-post-by-id', PublishController.deleteDraftPostById);
router.delete(
'/delete-draft-post-by-id',
PublishController.deleteDraftPostById
);
router.get('/get-approval-postStatus', PublishController.getApprovalPostStatus);
router.get('/get-approval-post-by-id', PublishController.getApprovalPostById);
router.delete('/delete-approval-post-by-id', PublishController.deleteApprovalPostById);
router.delete(
'/delete-approval-post-by-id',
PublishController.deleteApprovalPostById
);
router.get('/get-published-posts', PublishController.getPublishedPosts);

router.post('/filter-published-posts', PublishController.filterPublishedPosts);
export default router;
56 changes: 48 additions & 8 deletions socioboard-api/Publish/core/publish/publish.service.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import {
ErrorResponse, SuccessResponse, CatchResponse, ValidateErrorResponse,
ErrorResponse,
SuccessResponse,
CatchResponse,
ValidateErrorResponse,
} from '../../../Common/Shared/response.shared.js';
import PublishModel from '../../../Common/Models/publish.model.js';

const publishModel = new PublishModel();

class PublishController {
constructor() {
}
constructor() {}

async publishPost(req, res, next) {
try {
const response = await publishModel.publishPost(req.body, req.query.teamId, req.query.language);
const response = await publishModel.publishPost(
req.body,
req.query.teamId,
req.query.language
);

SuccessResponse(res, response?.data, response?.message, response?.code);
} catch (error) {
Expand All @@ -21,7 +27,11 @@ class PublishController {

async getDraftedPosts(req, res, next) {
try {
const response = await publishModel.getDraftedPosts(req.query.userScopeId, req.query.teamId, req.query.pageId);
const response = await publishModel.getDraftedPosts(
req.query.userScopeId,
req.query.teamId,
req.query.pageId
);

SuccessResponse(res, response);
} catch (error) {
Expand All @@ -41,7 +51,10 @@ class PublishController {

async updateDraftPostById(req, res, next) {
try {
const response = await publishModel.updateDraftPostById(req.query.id, req.body.draftPost);
const response = await publishModel.updateDraftPostById(
req.query.id,
req.body.draftPost
);

SuccessResponse(res, response);
} catch (error) {
Expand Down Expand Up @@ -81,7 +94,11 @@ class PublishController {

async getApprovalPostStatus(req, res, next) {
try {
const response = await publishModel.getApprovalPostStatus(req.query.userScopeId, req.query.teamId, req.query.pageId);
const response = await publishModel.getApprovalPostStatus(
req.query.userScopeId,
req.query.teamId,
req.query.pageId
);

SuccessResponse(res, response);
} catch (error) {
Expand All @@ -91,7 +108,30 @@ class PublishController {

async getPublishedPosts(req, res, next) {
try {
const response = await publishModel.getPublishedPosts(req.query.userScopeId, req.query.teamId, req.query.pageId);
const response = await publishModel.getPublishedPosts(
req.query.userScopeId,
req.query.teamId,
req.query.pageId
);

SuccessResponse(res, response);
} catch (error) {
CatchResponse(res, error.message);
}
}

async filterPublishedPosts(req, res, next) {
try {
const response = await publishModel.filterPublishedPosts(
req.query.userScopeId,
req.query.teamId,
req.query.pageId,
req.body.searchPublishedPostInfo,
req.query.publishedStatus,
req.query.filterPeriod,
req.query.since,
req.query.until
);

SuccessResponse(res, response);
} catch (error) {
Expand Down