1
1
const bannerService = require ( "../service/banner.service" ) ;
2
- const linkService = require ( "../service/link.service" ) ;
2
+ const guidelogService = require ( "../service/guidelog.service" ) ;
3
+ const helperLinkService = require ( "../service/helperLink.service" ) ;
3
4
const popupService = require ( "../service/popup.service" ) ;
4
5
5
6
class GuideController {
@@ -10,19 +11,55 @@ class GuideController {
10
11
if ( ! url || typeof url !== 'string' ) {
11
12
return res . status ( 400 ) . json ( { errors : [ { msg : "URL is missing or invalid" } ] } ) ;
12
13
}
13
- const [ banner , popup , link ] = await Promise . all ( [
14
+ const [ banner , popup , helperLink ] = await Promise . all ( [
14
15
bannerService . getBannerByUrl ( url ) ,
15
16
popupService . getPopupByUrl ( url ) ,
16
- linkService . getLinkByUrl ( url ) ,
17
+ helperLinkService . getAllHelpersWithLinks ( ) ,
17
18
] ) ;
18
- res . status ( 200 ) . json ( { banner, popup, link } ) ;
19
+ res . status ( 200 ) . json ( { banner, popup, helperLink } ) ;
19
20
} catch ( error ) {
20
21
internalServerError (
21
22
"GET_GUIDES_BY_URL_ERROR" ,
22
23
error . message ,
23
24
) ;
24
25
}
25
26
}
27
+
28
+ async getIncompleteGuidesByUrl ( req , res ) {
29
+ try {
30
+ const { url, userId } = req . body ;
31
+
32
+ if ( ! url || typeof url !== 'string' ) {
33
+ return res . status ( 400 ) . json ( { errors : [ { msg : "URL is missing or invalid" } ] } ) ;
34
+ }
35
+ if ( ! userId || typeof userId !== 'string' ) {
36
+ return res . status ( 400 ) . json ( { errors : [ { msg : "userId is missing or invalid" } ] } ) ;
37
+ }
38
+
39
+ const [ completePopupLogs , completeBannerLogs , completeHelperLogs ] = await Promise . all ( [
40
+ guidelogService . getCompletePopupLogs ( userId ) ,
41
+ guidelogService . getCompleteBannerLogs ( userId ) ,
42
+ guidelogService . getCompleteHelperLogs ( userId ) ,
43
+ ] ) ;
44
+
45
+ const popupIds = completePopupLogs . map ( log => log . guideId ) ;
46
+ const bannerIds = completeBannerLogs . map ( log => log . guideId ) ;
47
+ const helperLinkIds = completeHelperLogs . map ( log => log . guideId ) ;
48
+
49
+ const [ banner , popup , helperLink ] = await Promise . all ( [
50
+ bannerService . getIncompleteBannersByUrl ( url , bannerIds ) ,
51
+ popupService . getIncompletePopupsByUrl ( url , popupIds ) ,
52
+ helperLinkService . getIncompleteHelpers ( helperLinkIds ) ,
53
+ ] ) ;
54
+ res . status ( 200 ) . json ( { banner, popup, helperLink } ) ;
55
+
56
+ } catch ( error ) {
57
+ internalServerError (
58
+ "GET_INCOMPLETE_GUIDES_BY_URL_ERROR" ,
59
+ error . message ,
60
+ ) ;
61
+ }
62
+ }
26
63
}
27
64
28
65
module . exports = new GuideController ( ) ;
0 commit comments