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
70414ae9
Commit
70414ae9
authored
Mar 14, 2024
by
Venkaiah Naidu Singamchetty
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'apiserver' into 'master'
Apiserver See merge request
!6
parents
a6392805
d6513c10
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
67 deletions
+105
-67
package-lock.json
package-lock.json
+10
-0
package.json
package.json
+2
-0
server.js
server.js
+93
-67
No files found.
package-lock.json
View file @
70414ae9
...
...
@@ -13,6 +13,8 @@
"@testing-library/user-event"
:
"^13.5.0"
,
"cors"
:
"^2.8.5"
,
"express"
:
"^4.18.3"
,
"lodash"
:
"^4.17.21"
,
"moment"
:
"^2.30.1"
,
"mongodb"
:
"^6.5.0"
,
"react"
:
"^18.2.0"
,
"react-dom"
:
"^18.2.0"
,
...
...
@@ -12793,6 +12795,14 @@
"mkdirp"
:
"bin/cmd.js"
}
},
"node_modules/moment"
:
{
"version"
:
"2.30.1"
,
"resolved"
:
"https://registry.npmjs.org/moment/-/moment-2.30.1.tgz"
,
"integrity"
:
"sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how=="
,
"engines"
:
{
"node"
:
"*"
}
},
"node_modules/mongodb"
:
{
"version"
:
"6.5.0"
,
"resolved"
:
"https://registry.npmjs.org/mongodb/-/mongodb-6.5.0.tgz"
,
...
...
package.json
View file @
70414ae9
...
...
@@ -11,6 +11,8 @@
"
axios
"
:
"^1.6.7"
,
"
cors
"
:
"^2.8.5"
,
"
express
"
:
"^4.18.3"
,
"
lodash
"
:
"^4.17.21"
,
"
moment
"
:
"^2.30.1"
,
"
mongodb
"
:
"^6.5.0"
,
"
react
"
:
"^18.2.0"
,
"
react-dom
"
:
"^18.2.0"
,
...
...
server.js
View file @
70414ae9
...
...
@@ -18,25 +18,36 @@ connectToDb((err) => {
}
})
//to get all the employees data
app
.
get
(
'/employees'
,
(
req
,
res
)
=>
{
db
.
collection
(
'employees'
).
find
().
toArray
()
.
then
(
result
=>
{
res
.
send
(
result
)
})
.
catch
(
error
=>
res
.
status
(
401
).
send
(
error
))
})
app
.
get
(
'/activities'
,
(
req
,
res
)
=>
{
db
.
collection
(
'activities_master'
).
find
().
toArray
()
//to get only individual employee data
app
.
get
(
'/employee/:id'
,
(
req
,
res
)
=>
{
let
Id
=
parseInt
(
req
.
params
.
id
);
db
.
collection
(
'employees'
).
findOne
({
empId
:
Id
},{
projection
:{
_id
:
false
}})
.
then
(
result
=>
{
res
.
send
(
result
)
})
.
catch
(
error
=>
res
.
status
(
401
).
send
(
error
))
})
app
.
get
(
'/employee/:id'
,
(
req
,
res
)
=>
{
let
Id
=
parseInt
(
req
.
params
.
id
);
db
.
collection
(
'
employees'
).
findOne
({
empId
:
Id
},{
projection
:{
_id
:
false
}}
)
//to get activities to display
app
.
get
(
'/activities'
,
(
req
,
res
)
=>
{
db
.
collection
(
'
activities_master'
).
find
().
toArray
(
)
.
then
(
result
=>
{
res
.
send
(
result
)
})
.
catch
(
error
=>
res
.
status
(
401
).
send
(
error
))
})
/*
Example of post Data
{
"reportees":[41689,41716,41710,41750,41751,41714],
"sort":{"type":"empId","order":-1}
,"page":1,"perPage":10,
"searchText":"eng"
}*/
app
.
post
(
'/getreportees'
,
(
req
,
res
)
=>
{
let
reporteesArray
=
req
.
body
.
reportees
||
[];
let
sortBy
=
req
.
body
.
sort
?
req
.
body
.
sort
.
type
||
"_id"
:
"_id"
...
...
@@ -55,69 +66,84 @@ app.post('/getreportees', (req, res) => {
{
"designation"
:
searchStr
}
]
});
}
console
.
log
(
query
);
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"
}
]
}
}
])
db
.
collection
(
'employees'
).
find
(
query
,
{
projection
:
{
_id
:
false
}
})
.
skip
(
skip
)
.
sort
({[
sortBy
]:
sortByOrder
})
.
limit
(
limit
)
.
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
// Get the total count of data
db
.
collection
(
'employees'
).
countDocuments
(
query
)
.
then
(
totalCount
=>
{
res
.
send
({
totalC
ount
:
totalCount
,
totalc
ount
:
totalCount
,
currentPage
:
page
,
totalPages
:
Math
.
ceil
(
totalCount
/
limit
),
data
:
paginatedData
,
data
:
result
,
});
})
.
catch
(
error
=>
res
.
status
(
401
).
send
(
error
));
})
.
catch
(
error
=>
res
.
status
(
401
).
send
(
error
));
});
//Example of post Data
/*
{
"empId":10000,
"data":{
"aName":"timesheet",
"aId":"D001",
"type":"default",
"recorded_date":"2024-03-12",
"score":3,
"comments":"very good"
}
}
*/
app
.
post
(
'/create-performance'
,(
req
,
res
)
=>
{
const
empId
=
req
.
body
.
empId
||
null
;
if
(
!
empId
){
res
.
status
(
401
).
json
({
"message"
:
"Employee id is missing"
});
return
}
else
{
let
{
data
}
=
req
.
body
;
data
=
{...
data
,
"recorded_date"
:
new
Date
(
data
[
'recorded_date'
])
};
let
query
=
{
empId
:
empId
};
db
.
collection
(
'performance_master'
).
findOne
(
query
).
then
((
result
)
=>
{
if
(
result
){
db
.
collection
(
'performance_master'
).
updateOne
(
query
,{
$push
:
{
"activities"
:
data
}
})
.
then
((
updateRes
)
=>
{
res
.
json
({
"reuslt"
:
updateRes
});
})
.
catch
((
error
)
=>
{
res
.
json
({
"error"
:
error
});
});
}
else
{
//create ne one
let
insertData
=
{
empId
:
empId
,
activities
:[]};
insertData
.
activities
.
push
(
data
);
db
.
collection
(
'performance_master'
).
insertOne
(
insertData
).
then
((
result
)
=>
{
res
.
json
({
"result"
:
result
});
}).
catch
((
error
)
=>
{
res
.
json
({
"message"
:
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));
});
})
}
}).
catch
((
error
)
=>
{
console
.
log
(
error
)
res
.
send
(
query
)
})
}
})
...
...
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