'reporteesapiadded'

parent c94a2354
const {MongoClient}=require("mongodb")
let dbConnection
module.exports = {
......@@ -16,5 +17,17 @@ module.exports = {
return cb(err)
})
},
getDb: () => dbConnection
getDb: () => dbConnection,
getModel:function(collectionName){
let dbConnection = dbConnection();
try {
return dbConnection.model(collectionName);
} catch (error) {
// if (['PERM_AGING_LOG', 'PETITION_AGING_LOG'].indexOf(collectionName) > -1) {
// return dbConnection.model(collectionName, new this.mongoDb.Schema(models[collectionName], { optimisticConcurrency: true, versionKey: 'version' }))
// } else {
return dbConnection.model(collectionName, new this.mongoDb.Schema(models[collectionName]))
// }
}
}
}
\ No newline at end of file
......@@ -29,4 +29,33 @@ app.get('/employee/:id', (req, res) => {
db.collection('employees').findOne({empId:Id},{projection:{_id:false}})
.then(result => { res.send(result) })
.catch(error => res.status(401).send(error))
})
\ No newline at end of file
})
app.post('/getreportees', (req, res) => {
let reporteesArray = req.body.reportees;
let page = parseInt(req.query.page) || 1;
let limit = 10;
let skip = (page - 1) * limit;
db.collection('employees').find({ empId: { $in: reporteesArray } }, { projection: { _id: false } })
.skip(skip)
.limit(limit)
.toArray()
.then(result => {
// Get the total count of data
db.collection('employees').countDocuments({ empId: { $in: reporteesArray } })
.then(totalCount => {
res.send({
total: totalCount,
currentPage: page,
totalPages: Math.ceil(totalCount / limit),
data: result
});
})
.catch(error => res.status(401).send(error));
})
.catch(error => res.status(401).send(error));
});
import {Schema} from "mongoose"
module.exports = {
employee :{
empName:string,
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment