Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nisum-scorecard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Venkaiah Naidu Singamchetty
nisum-scorecard
Commits
255fc7ee
Commit
255fc7ee
authored
Mar 22, 2024
by
Venkaiah Naidu Singamchetty
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feture/get-activities' into 'master'
Feture/get activities See merge request
!76
parents
28d6db83
3fad3085
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
1 deletion
+76
-1
server.js
server.js
+76
-1
No files found.
server.js
View file @
255fc7ee
...
...
@@ -247,11 +247,12 @@ const calculateAverage = async(query) => {
"toDate":"2024-03-14",
page:0
perPage:10,
"types":["duties","initiative"]
}
*/
app
.
post
(
"/getActivities"
,
async
(
req
,
res
)
=>
{
let
{
empId
,
today
}
=
req
.
body
;
let
{
empId
,
today
,
types
}
=
req
.
body
;
if
(
!
empId
||
typeof
empId
==
"string"
)
{
res
.
status
(
401
).
json
({
message
:
"Employee id is missing / EmpId should be string only"
});
return
;
...
...
@@ -262,6 +263,8 @@ app.post("/getActivities", async(req, res) => {
//let query = { empId: empId};
let
aggreGate
=
[
{
$match
:{
empId
:
empId
}
}
];
let
fromDate
=
moment
().
subtract
(
90
,
"days"
).
toDate
();
let
toDate
=
moment
().
toDate
()
...
...
@@ -274,9 +277,13 @@ app.post("/getActivities", async(req, res) => {
toDate
.
setMinutes
(
59
);
toDate
.
setSeconds
(
59
);
// query["activities.recorded_date"] = {$gte: new Date(fromDate),$lte: new Date(toDate) };
aggreGate
.
push
({
$match
:{
"activities.recorded_date"
:
{
$gte
:
new
Date
(
fromDate
),
$lte
:
new
Date
(
toDate
)
}
}
});
aggreGate
.
push
({
$unwind
:
"$activities"
});
aggreGate
.
push
({
$sort
:
{
"activities.recorded_date"
:
-
1
}
});
if
(
types
&&
types
?.
length
)
aggreGate
.
push
({
$match
:{
"activities.type"
:
{
"$in"
:
types
}
}
});
//console.log(JSON.stringify(aggreGate));
let
facet
=
{
data
:
[{
$skip
:
skip
},
{
$limit
:
limit
}],
...
...
@@ -307,4 +314,72 @@ app.post("/getActivities", async(req, res) => {
})
.
catch
((
error
)
=>
res
.
status
(
401
).
send
(
error
));
}
});
//sending filtered activities avg score data
/*Example post data
{
"empId":41689,
"fromDate":"2024-03-10",
"toDate":"2024-03-14",
"types":["duties","initiative"]
}
*/
app
.
post
(
"/getActivities-avg"
,
async
(
req
,
res
)
=>
{
let
{
empId
,
today
,
types
}
=
req
.
body
;
if
(
!
empId
||
typeof
empId
==
"string"
)
{
res
.
status
(
401
).
json
({
message
:
"Employee id is missing / EmpId should be string only"
});
return
;
}
else
{
let
page
=
req
.
body
.
page
?
parseInt
(
req
.
body
.
page
)
||
1
:
1
;
let
limit
=
req
.
body
.
perPage
?
parseInt
(
req
.
body
.
perPage
)
||
10
:
10
;
let
skip
=
(
page
-
1
)
*
limit
||
0
;
//let query = { empId: empId};
let
aggreGate
=
[
{
$match
:{
empId
:
empId
}
}
];
let
fromDate
=
moment
().
subtract
(
90
,
"days"
).
toDate
();
let
toDate
=
moment
().
toDate
()
if
(
req
.
body
.
fromDate
&&
req
.
body
.
toDate
)
{
fromDate
=
new
Date
(
req
.
body
.
fromDate
);
toDate
=
new
Date
(
req
.
body
.
toDate
);
}
toDate
.
setHours
(
23
);
toDate
.
setMinutes
(
59
);
toDate
.
setSeconds
(
59
);
// query["activities.recorded_date"] = {$gte: new Date(fromDate),$lte: new Date(toDate) };
aggreGate
.
push
({
$match
:{
"activities.recorded_date"
:
{
$gte
:
new
Date
(
fromDate
),
$lte
:
new
Date
(
toDate
)
}
}
});
aggreGate
.
push
({
$unwind
:
"$activities"
});
aggreGate
.
push
({
$sort
:
{
"activities.recorded_date"
:
-
1
}
});
if
(
types
&&
types
?.
length
)
aggreGate
.
push
({
$match
:{
"activities.type"
:
{
"$in"
:
types
}
}
});
let
facet
=
{
data
:
[{
$skip
:
skip
},
{
$limit
:
limit
}],
totalCount
:
[{
$count
:
"count"
}],
};
//aggreGate.push({ $facet: facet });
//aggreGate.push({ $unwind: { path: "$totalCount" } });
aggreGate
.
push
({
$group
:{
_id
:
"$activities.type"
,
"avgScore"
:{
"$avg"
:
"$activities.score"
}
}
});
db
.
collection
(
"performance_master"
)
.
aggregate
(
aggreGate
)
.
toArray
()
.
then
((
result
)
=>
{
res
.
status
(
201
).
json
(
result
);
})
.
catch
((
error
)
=>
res
.
status
(
401
).
send
(
error
));
}
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment