-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from bluewave-labs/535-tour-url-services
535 tour url services
- Loading branch information
Showing
7 changed files
with
143 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
const bannerService = require("../service/banner.service"); | ||
const guidelogService = require("../service/guidelog.service"); | ||
const helperLinkService = require("../service/helperLink.service"); | ||
const popupService = require("../service/popup.service"); | ||
const hintService = require("../service/hint.service"); | ||
const { internalServerError } = require("../utils/errors.helper"); | ||
const bannerService = require('../service/banner.service'); | ||
const guidelogService = require('../service/guidelog.service'); | ||
const helperLinkService = require('../service/helperLink.service'); | ||
const popupService = require('../service/popup.service'); | ||
const hintService = require('../service/hint.service'); | ||
const { internalServerError } = require('../utils/errors.helper'); | ||
const tourService = require('../service/tour.service'); | ||
|
||
class GuideController { | ||
async getGuidesByUrl(req, res) { | ||
try { | ||
const { url } = req.body; | ||
async getGuidesByUrl(req, res) { | ||
try { | ||
const { url } = req.body; | ||
|
||
if (!url || typeof url !== 'string') { | ||
return res.status(400).json({ errors: [{ msg: "URL is missing or invalid" }] }); | ||
} | ||
const [banner, popup, hint, helperLink] = await Promise.all([ | ||
bannerService.getBannerByUrl(url), | ||
popupService.getPopupByUrl(url), | ||
hintService.getHintByUrl(url), | ||
helperLinkService.getAllHelpersWithLinks(), | ||
]); | ||
res.status(200).json({ banner, popup, hint, helperLink }); | ||
} catch (error) { | ||
internalServerError( | ||
"GET_GUIDES_BY_URL_ERROR", | ||
error.message, | ||
); | ||
} | ||
if (!url || typeof url !== 'string') { | ||
return res.status(400).json({ errors: [{ msg: 'URL is missing or invalid' }] }); | ||
} | ||
const [banner, popup, hint, helperLink, tour] = await Promise.all([ | ||
bannerService.getBannerByUrl(url), | ||
popupService.getPopupByUrl(url), | ||
hintService.getHintByUrl(url), | ||
helperLinkService.getAllHelpersWithLinks(), | ||
tourService.getTourByUrl(url), | ||
]); | ||
res.status(200).json({ banner, popup, hint, helperLink, tour }); | ||
} catch (error) { | ||
const { payload, statusCode } = internalServerError('GET_GUIDES_BY_URL_ERROR', error.message); | ||
res.status(statusCode).json(payload); | ||
} | ||
} | ||
|
||
async getIncompleteGuidesByUrl(req, res) { | ||
try { | ||
const { url, userId } = req.body; | ||
async getIncompleteGuidesByUrl(req, res) { | ||
try { | ||
const { url, userId } = req.body; | ||
|
||
if (!url || typeof url !== 'string') { | ||
return res.status(400).json({ errors: [{ msg: "URL is missing or invalid" }] }); | ||
} | ||
if (!userId || typeof userId !== 'string') { | ||
return res.status(400).json({ errors: [{ msg: "userId is missing or invalid" }] }); | ||
} | ||
if (!url || typeof url !== 'string') { | ||
return res.status(400).json({ errors: [{ msg: 'URL is missing or invalid' }] }); | ||
} | ||
if (!userId || typeof userId !== 'string') { | ||
return res.status(400).json({ errors: [{ msg: 'userId is missing or invalid' }] }); | ||
} | ||
|
||
const [completePopupLogs, completeBannerLogs, completeHintLogs, completeHelperLogs] = await Promise.all([ | ||
guidelogService.getCompletePopupLogs(userId), | ||
guidelogService.getCompleteBannerLogs(userId), | ||
guidelogService.getCompleteHintLogs(userId), | ||
guidelogService.getCompleteHelperLogs(userId), | ||
]); | ||
const [completePopupLogs, completeBannerLogs, completeHintLogs, completeHelperLogs, completeTourLogs] = | ||
await Promise.all([ | ||
guidelogService.getCompletePopupLogs(userId), | ||
guidelogService.getCompleteBannerLogs(userId), | ||
guidelogService.getCompleteHintLogs(userId), | ||
guidelogService.getCompleteHelperLogs(userId), | ||
guidelogService.getCompleteToursLogs(userId), | ||
]); | ||
|
||
const popupIds = completePopupLogs.map(log => log.guideId); | ||
const bannerIds = completeBannerLogs.map(log => log.guideId); | ||
const hintIds = completeHintLogs.map(log => log.guideId); | ||
//const helperLinkIds = completeHelperLogs.map(log => log.guideId); | ||
const popupIds = completePopupLogs.map((log) => log.guideId); | ||
const bannerIds = completeBannerLogs.map((log) => log.guideId); | ||
const hintIds = completeHintLogs.map((log) => log.guideId); | ||
//const helperLinkIds = completeHelperLogs.map(log => log.guideId); | ||
const tourIds = completeTourLogs.map((log) => log.guideId); | ||
|
||
const [popup, banner, hint, helperLink] = await Promise.all([ | ||
popupService.getIncompletePopupsByUrl(url, popupIds), | ||
bannerService.getIncompleteBannersByUrl(url, bannerIds), | ||
hintService.getIncompleteHintsByUrl(url, hintIds), | ||
//helperLinkService.getIncompleteHelpers(helperLinkIds), | ||
helperLinkService.getAllHelpersWithLinks() | ||
]); | ||
res.status(200).json({popup, banner, hint, helperLink }); | ||
|
||
} catch (error) { | ||
internalServerError( | ||
"GET_INCOMPLETE_GUIDES_BY_URL_ERROR", | ||
error.message, | ||
); | ||
} | ||
const [popup, banner, hint, helperLink, tour] = await Promise.all([ | ||
popupService.getIncompletePopupsByUrl(url, popupIds), | ||
bannerService.getIncompleteBannersByUrl(url, bannerIds), | ||
hintService.getIncompleteHintsByUrl(url, hintIds), | ||
//helperLinkService.getIncompleteHelpers(helperLinkIds), | ||
helperLinkService.getAllHelpersWithLinks(), | ||
tourService.getIncompleteTourByUrl(url, tourIds), | ||
]); | ||
res.status(200).json({ popup, banner, hint, helperLink, tour }); | ||
} catch (error) { | ||
internalServerError('GET_INCOMPLETE_GUIDES_BY_URL_ERROR', error.message); | ||
} | ||
} | ||
} | ||
|
||
module.exports = new GuideController(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters