Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nisum-scorecard-qa-server
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-qa-server
Commits
bdb4fe28
Commit
bdb4fe28
authored
Mar 25, 2024
by
Venkaiah Naidu Singamchetty
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slight modifications added
parent
fa4bd93b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
129 additions
and
45 deletions
+129
-45
state.json
.netlify/state.json
+1
-1
api.js
functions/api.js
+128
-44
No files found.
.netlify/state.json
View file @
bdb4fe28
{
"siteId"
:
"8
8710c90-4ca9-4277-ad9d-0cf4d14584a1
"
"siteId"
:
"8
f36bca9-54c8-4b3c-9bc9-a8932626eec7
"
}
\ No newline at end of file
functions/api.js
View file @
bdb4fe28
...
...
@@ -35,7 +35,7 @@ let db = client.db(dbName);
//to get all the employees data
router
.
get
(
"/employees"
,
async
(
req
,
res
)
=>
{
router
.
get
(
"/employees"
,
async
(
req
,
res
)
=>
{
await
db
.
collection
(
"employees"
)
.
find
()
.
toArray
()
...
...
@@ -46,7 +46,7 @@ router.get("/employees", async (req, res) => {
});
//to get only individual employee data
router
.
get
(
"/employee/:id"
,
async
(
req
,
res
)
=>
{
router
.
get
(
"/employee/:id"
,
async
(
req
,
res
)
=>
{
let
Id
=
parseInt
(
req
.
params
.
id
);
await
db
.
collection
(
"employees"
)
.
findOne
({
empId
:
Id
},
{
projection
:
{
_id
:
false
}
})
...
...
@@ -80,7 +80,7 @@ router.post('/login', async (req, res) => {
//to get activities to display
router
.
get
(
"/activities"
,
async
(
req
,
res
)
=>
{
router
.
get
(
"/activities"
,
async
(
req
,
res
)
=>
{
await
db
.
collection
(
"activities_master"
)
.
find
()
.
toArray
()
...
...
@@ -98,7 +98,7 @@ Example of post Data
,"page":1,"perPage":10,
"searchText":"eng"
}*/
router
.
post
(
"/getreportees"
,
async
(
req
,
res
)
=>
{
router
.
post
(
"/getreportees"
,
async
(
req
,
res
)
=>
{
let
reporteesArray
=
req
.
body
.
reportees
||
[];
let
sortBy
=
req
.
body
.
sort
?
req
.
body
.
sort
.
type
||
"_id"
:
"_id"
;
let
sortByOrder
=
req
.
body
.
sort
?
parseInt
(
req
.
body
.
sort
.
order
)
||
1
:
1
;
...
...
@@ -122,11 +122,11 @@ router.post("/getreportees", async (req, res) => {
{
empIdString
:
searchStr
},
{
empName
:
searchStr
},
{
designation
:
searchStr
},
{
techStack
:
searchStr
}
{
techStack
:
searchStr
}
],
};
aggre
.
push
({
$match
:
orCondation
});
aggre
.
push
({
$unset
:
"empIdString"
});
aggre
.
push
({
$unset
:
"empIdString"
});
query
=
Object
.
assign
(
query
);
}
aggre
.
push
({
$sort
:
{
[
sortBy
]:
sortByOrder
}
});
...
...
@@ -157,14 +157,14 @@ router.post("/getreportees", async (req, res) => {
"data":{
"aName":"Approval of timesheet",
"aId":"D001",
"type":"d
efault
",
"type":"d
uties
",
"ratedBy":"Name",
"score":3,
"comments":""
}
}
*/
router
.
post
(
'/createActivity'
,
async
(
req
,
res
)
=>
{
router
.
post
(
'/createActivity'
,
async
(
req
,
res
)
=>
{
const
empId
=
req
.
body
.
empId
;
if
(
!
empId
)
{
res
.
status
(
401
).
json
({
"message"
:
"Employee id is missing"
});
...
...
@@ -173,7 +173,7 @@ router.post('/createActivity', async (req, res) => {
let
{
data
}
=
req
.
body
;
//data validation
if
(
!
_
.
get
(
data
,
"aName"
,
""
)
||
!
_
.
get
(
data
,
"aId"
,
""
)
||
!
_
.
get
(
data
,
"type"
,
""
)
||
!
_
.
get
(
data
,
"score"
,
""
)
||
!
_
.
get
(
data
,
"comments"
,
""
)
||
!
_
.
get
(
data
,
"ratedBy"
,
""
)
)
{
if
(
!
_
.
get
(
data
,
"aName"
,
""
)
||
!
_
.
get
(
data
,
"aId"
,
""
)
||
!
_
.
get
(
data
,
"type"
,
""
)
||
!
_
.
get
(
data
,
"score"
,
""
)
||
!
_
.
get
(
data
,
"comments"
,
""
)
||!
_
.
get
(
data
,
"ratedBy"
,
""
)
)
{
res
.
status
(
401
).
json
({
"error"
:
"Invalid Activity data"
});
return
;
}
...
...
@@ -191,7 +191,7 @@ router.post('/createActivity', async (req, res) => {
data
=
Object
.
assign
(
data
,
{
"_id"
:
new
ObjectId
()
})
let
query
=
{
empId
:
empId
};
await
db
.
collection
(
'performance_master'
).
findOne
(
query
).
then
(
async
(
result
)
=>
{
await
db
.
collection
(
'performance_master'
).
findOne
(
query
).
then
(
async
(
result
)
=>
{
if
(
result
)
{
await
db
.
collection
(
'performance_master'
).
updateOne
(
query
,
{
$push
:
{
"activities"
:
data
}
})
.
then
(
async
(
updateRes
)
=>
{
...
...
@@ -225,11 +225,11 @@ router.post('/createActivity', async (req, res) => {
})
//calculating average score and updating into employees data
const
calculateAverage
=
async
(
query
)
=>
{
return
await
new
Promise
(
async
(
res
,
rej
)
=>
{
const
calculateAverage
=
async
(
query
)
=>
{
return
await
new
Promise
(
async
(
res
,
rej
)
=>
{
await
db
.
collection
(
"performance_master"
)
.
findOne
(
query
)
.
then
(
async
(
result
)
=>
{
.
then
(
async
(
result
)
=>
{
let
activitiesList
=
result
.
activities
;
let
activitiesLength
=
activitiesList
.
length
;
let
score
=
activitiesList
.
reduce
((
acc
,
curr
)
=>
{
return
acc
+
Number
(
curr
.
score
)
},
0
);
...
...
@@ -263,12 +263,12 @@ const calculateAverage = async (query) => {
"toDate":"2024-03-14",
page:0
perPage:10,
"types":["duties","initiative"]
}
*/
router
.
post
(
"/getActivities"
,
async
(
req
,
res
)
=>
{
let
{
empId
,
today
}
=
req
.
body
;
router
.
post
(
"/getActivities"
,
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
;
...
...
@@ -278,7 +278,9 @@ router.post("/getActivities", async (req, res) => {
let
skip
=
(
page
-
1
)
*
limit
||
0
;
//let query = { empId: empId};
let
aggreGate
=
[{
$match
:
{
empId
:
empId
}
}];
let
aggreGate
=
[
{
$match
:{
empId
:
empId
}
}
];
let
fromDate
=
moment
().
subtract
(
90
,
"days"
).
toDate
();
let
toDate
=
moment
().
toDate
()
...
...
@@ -291,9 +293,13 @@ router.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
({
$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
}],
...
...
@@ -308,9 +314,9 @@ router.post("/getActivities", async (req, res) => {
.
toArray
()
.
then
((
result
)
=>
{
if
(
result
&&
result
.
length
)
{
let
resData
=
{
activities
:
[],
totalCount
:
result
[
0
].
totalCount
,
"empId"
:
empId
};
if
(
result
[
0
].
data
?.
length
)
{
result
[
0
].
data
.
forEach
((
item
)
=>
{
let
resData
=
{
activities
:
[],
totalCount
:
result
[
0
].
totalCount
,
"empId"
:
empId
};
if
(
result
[
0
].
data
?.
length
)
{
result
[
0
].
data
.
forEach
((
item
)
=>
{
resData
[
"activities"
].
push
(
item
.
activities
);
});
...
...
@@ -319,13 +325,91 @@ router.post("/getActivities", async (req, res) => {
res
.
status
(
201
).
json
(
resData
);
}
else
{
res
.
status
(
201
).
json
({
activities
:
[],
totalCount
:
{
count
:
0
}
});
res
.
status
(
201
).
json
({
activities
:
[],
totalCount
:
{
count
:
0
},
"empId"
:
empId
});
}
})
.
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"]
}
*/
router
.
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"
}
}
});
aggreGate
.
push
({
$project
:{
"type"
:
"$_id"
,
"avgScore"
:
1
}
});
aggreGate
.
push
({
$unset
:
"_id"
});
db
.
collection
(
"performance_master"
)
.
aggregate
(
aggreGate
)
.
toArray
()
.
then
((
result
)
=>
{
res
.
status
(
201
).
json
(
result
);
})
.
catch
((
error
)
=>
res
.
status
(
401
).
send
(
error
));
}
});
app
.
use
(
'/.netlify/functions/api'
,
router
);
...
...
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