Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
widgetTemplate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Shweta Gupta
widgetTemplate
Commits
b1666375
Commit
b1666375
authored
10 months ago
by
Nayana Mogaveera
Browse files
Options
Downloads
Plain Diff
Merge branch 'nayana' into 'development'
Nayana See merge request
!9
parents
7b8ce879
457572c8
No related branches found
No related tags found
1 merge request
!9
Nayana
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/template/business.js
+3
-1
3 additions, 1 deletion
api/template/business.js
api/template/controller.js
+2
-1
2 additions, 1 deletion
api/template/controller.js
api/template/service.js
+77
-31
77 additions, 31 deletions
api/template/service.js
swagger.yaml
+0
-3
0 additions, 3 deletions
swagger.yaml
with
82 additions
and
36 deletions
api/template/business.js
+
3
−
1
View file @
b1666375
...
@@ -27,7 +27,9 @@ const createTemplate = async (name, desc,platform, widgets, hashId) => {
...
@@ -27,7 +27,9 @@ const createTemplate = async (name, desc,platform, widgets, hashId) => {
const
getParticularTemplate
=
async
(
page
,
platform
)
=>
{
const
getParticularTemplate
=
async
(
page
,
platform
)
=>
{
try
{
try
{
const
response
=
await
templateService
.
getParticularTemplate
(
page
,
platform
);
const
response
=
await
templateService
.
getParticularTemplate
(
page
,
platform
);
console
.
log
(
page
,
"
Pagessssssss
"
);
if
(
response
.
length
==
0
)
{
return
{
status
:
404
,
message
:
"
Template not found
"
};
}
return
{
status
:
'
200
'
,
response
}
return
{
status
:
'
200
'
,
response
}
}
catch
(
error
)
{
}
catch
(
error
)
{
throw
error
throw
error
...
...
This diff is collapsed.
Click to expand it.
api/template/controller.js
+
2
−
1
View file @
b1666375
...
@@ -29,7 +29,8 @@ const createTemplate = async (req, res, next) => {
...
@@ -29,7 +29,8 @@ const createTemplate = async (req, res, next) => {
const
getParticularTemplate
=
async
(
req
,
res
)
=>
{
const
getParticularTemplate
=
async
(
req
,
res
)
=>
{
try
{
try
{
console
.
log
(
"
GET template details of a particular page
"
);
console
.
log
(
"
GET template details of a particular page
"
);
const
{
page
,
platform
}
=
req
.
params
;
const
{
page
}
=
req
.
params
;
const
{
platform
}
=
req
.
query
const
response
=
await
templateBusiness
.
getParticularTemplate
(
page
,
platform
);
const
response
=
await
templateBusiness
.
getParticularTemplate
(
page
,
platform
);
return
res
.
status
(
response
.
status
).
json
({
data
:
response
});
return
res
.
status
(
response
.
status
).
json
({
data
:
response
});
}
catch
(
error
)
{
}
catch
(
error
)
{
...
...
This diff is collapsed.
Click to expand it.
api/template/service.js
+
77
−
31
View file @
b1666375
// const logger = require('utils/logger');
// const logger = require('utils/logger');
const
Widget
=
require
(
"
../models/widget
"
);
const
Widget
=
require
(
"
../models/widget
"
);
const
Template
=
require
(
"
../models/template
"
)
const
Template
=
require
(
"
../models/template
"
)
;
const
updateAndMapWidget
=
async
(
const
updateAndMapWidget
=
async
(
page
,
widgetId
,
position
,
startTime
,
endTime
)
=>
{
page
,
widgetId
,
position
,
startTime
,
endTime
)
=>
{
try
{
try
{
const
template
=
await
Template
.
findOne
({
name
:
page
});
const
template
=
await
Template
.
findOne
({
name
:
page
});
if
(
!
template
)
{
if
(
!
template
)
{
return
{
status
:
404
,
error
:
'
template not found
'
};
return
{
status
:
404
,
error
:
"
template not found
"
};
}
}
console
.
log
(
page
,
widgetId
,
position
,
startTime
,
endTime
)
console
.
log
(
page
,
widgetId
,
position
,
startTime
,
endTime
);
const
widgetIndex
=
template
.
widgets
.
findIndex
(
w
=>
w
.
widgetId
.
toString
()
===
widgetId
);
const
widgetIndex
=
template
.
widgets
.
findIndex
(
(
w
)
=>
w
.
widgetId
.
toString
()
===
widgetId
);
if
(
widgetIndex
!==
-
1
)
{
if
(
widgetIndex
!==
-
1
)
{
template
.
widgets
[
widgetIndex
]
=
{
template
.
widgets
[
widgetIndex
]
=
{
...
template
.
widgets
[
widgetIndex
],
...
template
.
widgets
[
widgetIndex
],
position
,
position
,
startTime
,
startTime
,
endTime
endTime
,
};
};
}
else
{
}
else
{
template
.
widgets
.
push
({
template
.
widgets
.
push
({
widgetId
:
widgetId
,
widgetId
:
widgetId
,
position
,
position
,
startTime
,
startTime
,
endTime
endTime
,
});
});
}
}
await
template
.
save
();
await
template
.
save
();
return
{
status
:
200
,
widgetId
:
widgetId
,
page
:
page
};
return
{
status
:
200
,
widgetId
:
widgetId
,
page
:
page
};
}
catch
(
error
)
{
}
catch
(
error
)
{
throw
error
throw
error
;
}
}
};
};
const
createTemplate
=
async
(
name
,
desc
,
platform
,
widgets
,
hashId
)
=>
{
const
createTemplate
=
async
(
name
,
desc
,
platform
,
widgets
,
hashId
)
=>
{
...
@@ -44,34 +50,74 @@ const createTemplate = async (name, desc, platform, widgets, hashId) => {
...
@@ -44,34 +50,74 @@ const createTemplate = async (name, desc, platform, widgets, hashId) => {
desc
,
desc
,
platform
,
platform
,
widgets
,
widgets
,
hashId
hashId
,
});
});
// Save the template to the database
// Save the template to the database
await
newTemplate
.
save
();
await
newTemplate
.
save
();
return
{
status
:
201
,
message
:
'
Template created successfully
'
,
id
:
newTemplate
.
_id
};
return
{
status
:
201
,
message
:
"
Template created successfully
"
,
id
:
newTemplate
.
_id
,
};
}
catch
(
error
)
{
}
catch
(
error
)
{
throw
error
throw
error
;
}
}
};
};
const
getParticularTemplate
=
async
(
page
,
platform
)
=>
{
const
getParticularTemplate
=
async
(
page
,
platform
)
=>
{
try
{
try
{
const
template
=
await
Template
.
findOne
({
name
:
page
,
platform
}).
populate
(
'
widgets.widgetId
'
);
let
pipeline
=
[];
if
(
!
template
)
{
pipeline
.
push
({
$match
:
{
name
:
page
,
platform
:
platform
}
});
return
{
status
:
404
,
message
:
'
Template not found
'
};
}
pipeline
.
push
({
$unwind
:
{
path
:
"
$widgets
"
}
});
pipeline
.
push
({
$lookup
:
{
localField
:
"
widgets.widgetId
"
,
foreignField
:
"
_id
"
,
from
:
"
widgets
"
,
as
:
"
widget
"
,
},
});
pipeline
.
push
({
$unwind
:
{
path
:
"
$widget
"
}
});
const
group
=
{
$group
:
{
_id
:
"
$_id
"
,
name
:
{
$first
:
"
$name
"
},
desc
:
{
$first
:
"
$desc
"
},
hashId
:
{
$first
:
"
$hashId
"
},
platform
:
{
$first
:
"
$platform
"
},
widgets
:
{
$addToSet
:
{
widgetId
:
"
$widget._id
"
,
title
:
"
$widget.title
"
,
widget
:
"
$widget.widget
"
,
enable
:
"
$widget.enable
"
,
sectionHeadingText
:
"
$widget.sectionHeadingText
"
,
apiUrl
:
"
$widget.apiUrl
"
,
buttonData
:
"
$widget.buttonData
"
,
list
:
"
$widget.list
"
,
position
:
"
$widgets.position
"
,
startTime
:
"
$widgets.startTime
"
,
endTime
:
"
$widgets.endTime
"
,
},
},
},
};
pipeline
.
push
(
group
);
const
template
=
await
Template
.
aggregate
(
pipeline
);
return
template
;
return
template
;
}
catch
(
error
)
{
}
catch
(
error
)
{
throw
error
throw
error
;
}
}
};
};
module
.
exports
=
{
module
.
exports
=
{
updateAndMapWidget
,
updateAndMapWidget
,
createTemplate
,
createTemplate
,
getParticularTemplate
getParticularTemplate
,
};
};
This diff is collapsed.
Click to expand it.
swagger.yaml
+
0
−
3
View file @
b1666375
...
@@ -46,9 +46,6 @@ paths:
...
@@ -46,9 +46,6 @@ paths:
type
:
array
type
:
array
items
:
items
:
type
:
object
type
:
object
properties
:
widgetId
:
type
:
string
position
:
position
:
type
:
integer
type
:
integer
startTime
:
startTime
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment