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
cbb2314f
Commit
cbb2314f
authored
Mar 13, 2024
by
GithubRepositoryPrashanth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'activities-api-added'
parent
a3081570
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
24 deletions
+84
-24
server.js
server.js
+84
-24
No files found.
server.js
View file @
cbb2314f
...
@@ -24,6 +24,12 @@ app.get('/employees', (req, res) => {
...
@@ -24,6 +24,12 @@ app.get('/employees', (req, res) => {
.
catch
(
error
=>
res
.
status
(
401
).
send
(
error
))
.
catch
(
error
=>
res
.
status
(
401
).
send
(
error
))
})
})
app
.
get
(
'/activities'
,
(
req
,
res
)
=>
{
db
.
collection
(
'activities_master'
).
find
().
toArray
()
.
then
(
result
=>
{
res
.
send
(
result
)
})
.
catch
(
error
=>
res
.
status
(
401
).
send
(
error
))
})
app
.
get
(
'/employee/:id'
,
(
req
,
res
)
=>
{
app
.
get
(
'/employee/:id'
,
(
req
,
res
)
=>
{
let
Id
=
parseInt
(
req
.
params
.
id
);
let
Id
=
parseInt
(
req
.
params
.
id
);
db
.
collection
(
'employees'
).
findOne
({
empId
:
Id
},{
projection
:{
_id
:
false
}})
db
.
collection
(
'employees'
).
findOne
({
empId
:
Id
},{
projection
:{
_id
:
false
}})
...
@@ -32,31 +38,85 @@ app.get('/employee/:id', (req, res) => {
...
@@ -32,31 +38,85 @@ app.get('/employee/:id', (req, res) => {
})
})
app
.
post
(
'/getreportees'
,
(
req
,
res
)
=>
{
app
.
post
(
'/getreportees'
,
(
req
,
res
)
=>
{
let
reporteesArray
=
req
.
body
.
reportees
;
let
reporteesArray
=
req
.
body
.
reportees
||
[]
;
let
sortBy
=
req
.
body
.
sort
.
type
||
_id
let
sortBy
=
req
.
body
.
sort
?
req
.
body
.
sort
.
type
||
"_id"
:
"_id"
let
sortByOrder
=
parseInt
(
req
.
body
.
sort
.
order
)
||
1
let
sortByOrder
=
req
.
body
.
sort
?
parseInt
(
req
.
body
.
sort
.
order
)
||
1
:
1
;
let
page
=
parseInt
(
req
.
body
.
page
)
||
1
;
let
page
=
req
.
body
.
page
?
parseInt
(
req
.
body
.
page
)
||
1
:
1
;
let
limit
=
parseInt
(
req
.
body
.
perPage
)
||
10
;
let
limit
=
req
.
body
.
perPage
?
parseInt
(
req
.
body
.
perPage
)
||
10
:
10
;
let
skip
=
(
page
-
1
)
*
limit
||
0
;
let
skip
=
(
page
-
1
)
*
limit
||
0
;
db
.
collection
(
'employees'
).
find
({
empId
:
{
$in
:
reporteesArray
}
},
{
projection
:
{
_id
:
false
}
})
let
query
=
{
empId
:
{
$in
:
reporteesArray
}
};
.
skip
(
skip
)
if
(
req
.
body
.
searchText
){
.
sort
({[
sortBy
]:
sortByOrder
})
let
searchText
=
req
.
body
.
searchText
.
trim
();
.
limit
(
limit
)
let
searchStr
=
new
RegExp
(
searchText
,
'ig'
);
.
toArray
()
query
=
Object
.
assign
(
query
,
{
.
then
(
result
=>
{
"$or"
:
[
// Get the total count of data
{
'empId'
:
searchStr
},
db
.
collection
(
'employees'
).
countDocuments
({
empId
:
{
$in
:
reporteesArray
}
})
{
'empName'
:
searchStr
},
.
then
(
totalCount
=>
{
{
"designation"
:
searchStr
}
res
.
send
({
]
total
:
totalCount
,
});
currentPage
:
page
,
totalPages
:
Math
.
ceil
(
totalCount
/
limit
),
data
:
result
}
});
console
.
log
(
query
);
})
.
catch
(
error
=>
res
.
status
(
401
).
send
(
error
));
})
.
catch
(
error
=>
res
.
status
(
401
).
send
(
error
));
db
.
collection
(
'employees'
).
aggregate
([
{
$match
:
query
},
{
$facet
:
{
// Perform the main query to get paginated data
paginatedData
:
[
{
$skip
:
skip
},
{
$limit
:
limit
},
{
$sort
:
{
[
sortBy
]:
sortByOrder
}
},
{
$project
:
{
_id
:
false
}
}
],
// Perform a separate query to get the total count of documents
totalCount
:
[
{
$count
:
"total"
}
]
}
}
])
.
toArray
()
.
then
(
result
=>
{
// Extract paginated data and total count from the result
const
paginatedData
=
result
[
0
].
paginatedData
;
const
totalCount
=
result
[
0
].
totalCount
[
0
].
total
;
// Send the response with pagination details
res
.
send
({
totalCount
:
totalCount
,
currentPage
:
page
,
totalPages
:
Math
.
ceil
(
totalCount
/
limit
),
data
:
paginatedData
,
});
})
.
catch
(
error
=>
res
.
status
(
401
).
send
(
error
));
// db.collection('employees').find(query, { projection: { _id: false } })
// .skip(skip)
// .sort({[sortBy]:sortByOrder})
// .limit(limit)
// .toArray()
// .then(result => {
// // Get the total count of data
// db.collection('employees').countDocuments(query)
// .then(totalCount => {
// res.send({
// totalcount: totalCount,
// currentPage: page,
// totalPages: Math.ceil(totalCount / limit),
// data: result,
// });
// })
// .catch(error => res.status(401).send(error));
// })
// .catch(error => res.status(401).send(error));
});
});
...
...
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