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
d635a841
Commit
d635a841
authored
Mar 20, 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
!66
parents
9e79fdc2
4dda8c5c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
30 deletions
+46
-30
server.js
server.js
+46
-30
No files found.
server.js
View file @
d635a841
...
@@ -110,7 +110,7 @@ app.post("/getreportees",async (req, res) => {
...
@@ -110,7 +110,7 @@ app.post("/getreportees",async (req, res) => {
],
],
};
};
aggre
.
push
({
$match
:
orCondation
});
aggre
.
push
({
$match
:
orCondation
});
aggre
.
push
({
$unset
:
"empIdString"
});
query
=
Object
.
assign
(
query
);
query
=
Object
.
assign
(
query
);
}
}
aggre
.
push
({
$sort
:
{
[
sortBy
]:
sortByOrder
}
});
aggre
.
push
({
$sort
:
{
[
sortBy
]:
sortByOrder
}
});
...
@@ -244,42 +244,58 @@ const calculateAverage = async(query) => {
...
@@ -244,42 +244,58 @@ const calculateAverage = async(query) => {
{
{
"empId":41689,
"empId":41689,
"fromDate":"2024-03-10",
"fromDate":"2024-03-10",
"toDate":"2024-03-14"
"toDate":"2024-03-14",
page:0
perPage:10,
}
}
*/
*/
app
.
post
(
"/getActivities"
,
async
(
req
,
res
)
=>
{
app
.
post
(
"/getActivities"
,
async
(
req
,
res
)
=>
{
let
{
empId
,
fromDate
,
toDate
,
today
}
=
req
.
body
;
let
{
empId
,
today
}
=
req
.
body
;
if
(
!
empId
||
typeof
empId
==
"string"
)
{
if
(
!
empId
||
typeof
empId
==
"string"
)
{
res
.
status
(
401
).
json
({
message
:
"Employee id is missing / EmpId should be string only"
});
res
.
status
(
401
).
json
({
message
:
"Employee id is missing / EmpId should be string only"
});
return
;
return
;
}
else
{
}
else
{
let
query
=
{
let
page
=
req
.
body
.
page
?
parseInt
(
req
.
body
.
page
)
||
1
:
1
;
empId
:
empId
,
let
limit
=
req
.
body
.
perPage
?
parseInt
(
req
.
body
.
perPage
)
||
10
:
10
;
};
let
skip
=
(
page
-
1
)
*
limit
||
0
;
if
(
fromDate
&&
toDate
)
{
fromDate
=
new
Date
(
fromDate
)
//let query = { empId: empId};
toDate
=
new
Date
(
toDate
);
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
.
setHours
(
23
);
toDate
.
setMinutes
(
59
);
toDate
.
setMinutes
(
59
);
toDate
.
setSeconds
(
59
);
toDate
.
setSeconds
(
59
);
query
[
"activities.recorded_date"
]
=
{
// query["activities.recorded_date"] = {$gte: new Date(fromDate),$lte: new Date(toDate) };
$gte
:
new
Date
(
fromDate
),
aggreGate
.
push
({
$match
:{
"activities.recorded_date"
:
{
$gte
:
new
Date
(
fromDate
),
$lte
:
new
Date
(
toDate
)
}
}
});
$lte
:
new
Date
(
toDate
),
aggreGate
.
push
({
$unwind
:
"$activities"
});
aggreGate
.
push
({
$sort
:
{
"activities.recorded_date"
:
-
1
}
});
let
facet
=
{
data
:
[{
$skip
:
skip
},
{
$limit
:
limit
}],
totalCount
:
[{
$count
:
"count"
}],
};
};
aggreGate
.
push
({
$facet
:
facet
});
aggreGate
.
push
({
$unwind
:
{
path
:
"$totalCount"
}
});
db
.
collection
(
"performance_master"
)
.
aggregate
(
aggreGate
)
.
toArray
()
.
then
((
result
)
=>
{
if
(
result
&&
result
.
length
)
{
res
.
status
(
201
).
json
({
...
result
[
0
]
});
}
else
{
}
else
{
// If fromDate and toDate are not provided, fetch data for the last 90 days
res
.
status
(
201
).
json
({
data
:
[],
totalCount
:
{
count
:
0
}
});
query
[
"activities.recorded_date"
]
=
{
$gte
:
moment
().
subtract
(
90
,
"days"
).
toDate
(),
$lte
:
moment
().
toDate
(),
};
}
}
await
db
.
collection
(
"performance_master"
)
.
findOne
(
query
)
.
then
((
results
)
=>
{
res
.
status
(
201
).
json
(
results
);
})
})
.
catch
((
error
)
=>
{
.
catch
((
error
)
=>
res
.
status
(
401
).
send
(
error
));
res
.
status
(
401
).
json
({
message
:
"Error fetching data"
},
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