Commit f0d7c01d authored by Venkaiah Naidu Singamchetty's avatar Venkaiah Naidu Singamchetty

Merge branch 'scorecarduidesigns' of...

Merge branch 'scorecarduidesigns' of https://gitlab.mynisum.com/vsingamchetty/nisum-scorecard into apiserver
parents c234e116 755f2adb
...@@ -247,11 +247,12 @@ const calculateAverage = async(query) => { ...@@ -247,11 +247,12 @@ const calculateAverage = async(query) => {
"toDate":"2024-03-14", "toDate":"2024-03-14",
page:0 page:0
perPage:10, perPage:10,
"types":["duties","initiative"]
} }
*/ */
app.post("/getActivities", async(req, res) => { app.post("/getActivities", async(req, res) => {
let { empId,today } = req.body; let { empId,today,types } = 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;
...@@ -262,6 +263,8 @@ app.post("/getActivities", async(req, res) => { ...@@ -262,6 +263,8 @@ app.post("/getActivities", async(req, res) => {
//let query = { empId: empId}; //let query = { empId: empId};
let aggreGate = [ { $match:{empId: empId} } ]; let aggreGate = [ { $match:{empId: empId} } ];
let fromDate = moment().subtract(90, "days").toDate(); let fromDate = moment().subtract(90, "days").toDate();
let toDate = moment().toDate() let toDate = moment().toDate()
...@@ -274,9 +277,13 @@ app.post("/getActivities", async(req, res) => { ...@@ -274,9 +277,13 @@ app.post("/getActivities", async(req, res) => {
toDate.setMinutes(59); toDate.setMinutes(59);
toDate.setSeconds(59); toDate.setSeconds(59);
// query["activities.recorded_date"] = {$gte: new Date(fromDate),$lte: new Date(toDate) }; // 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({$match:{"activities.recorded_date": {$gte: new Date(fromDate),$lte: new Date(toDate) } } });
aggreGate.push({$unwind:"$activities" }); aggreGate.push({$unwind:"$activities" });
aggreGate.push({ $sort: { "activities.recorded_date": -1 } }); 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 = { let facet = {
data: [{ $skip: skip }, { $limit: limit }], data: [{ $skip: skip }, { $limit: limit }],
...@@ -307,4 +314,83 @@ app.post("/getActivities", async(req, res) => { ...@@ -307,4 +314,83 @@ app.post("/getActivities", async(req, res) => {
}) })
.catch((error) => res.status(401).send(error)); .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"]
}
*/
app.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));
}
}); });
\ No newline at end of file
This diff is collapsed.
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import { base_url } from "../../utils/constants"; import { base_url } from "../../utils/constants";
import axios from "axios"; import axios from "axios";
const initialState = { const initialState = {
activitiesData:null, // totalReporteesData: [],
activitiesData:[],
loading: false, loading: false,
error: null, error: null,
};
};
export const fetchReportesActivitiesData = createAsyncThunk("getactivities", async (data) => {
export const fetchReportesActivitiesData = createAsyncThunk("gettotalactivities", async (data) => {
return await axios.post(`${base_url}/getActivities`, data) return await axios.post(`${base_url}/getActivities`, data)
.then((response) => response.data.activities); .then((response) => response.data);
}); });
const exporttableSlice = createSlice({ const exporttableSlice = createSlice({
name: "totalReportees", name: "totalReportees",
initialState, initialState,
...@@ -21,16 +24,18 @@ const exporttableSlice = createSlice({ ...@@ -21,16 +24,18 @@ const exporttableSlice = createSlice({
resetReporteesTableData:() => { resetReporteesTableData:() => {
return initialState return initialState
}, },
}, },
extraReducers: (builder) => { extraReducers: (builder) => {
builder.addCase(fetchReportesActivitiesData.pending, (state) => { builder.addCase(fetchReportesActivitiesData.pending, (state) => {
state.loading = true; state.loading = true;
state.error = "pending"; state.error = "pending";
}); });
builder.addCase(fetchReportesActivitiesData.fulfilled, (state, action) => { builder.addCase(fetchReportesActivitiesData.fulfilled, (state, action) => {
console.log(action.payload.activities)
state.loading = false; state.loading = false;
state.activitiesData = action.payload; state.activitiesData = action.payload.activities ;
state.error = ""; state.error = "";
}); });
builder.addCase(fetchReportesActivitiesData.rejected, (state, action) => { builder.addCase(fetchReportesActivitiesData.rejected, (state, action) => {
...@@ -40,7 +45,7 @@ const exporttableSlice = createSlice({ ...@@ -40,7 +45,7 @@ const exporttableSlice = createSlice({
}); });
}, },
}); });
export const {resetReporteesTableData} = exporttableSlice.actions; export const {resetReporteesTableData} = exporttableSlice.actions;
export default exporttableSlice.reducer; export default exporttableSlice.reducer;
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