44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
let Work = require('../models/works');
|
|
const asyncHandler = require('express-async-handler');
|
|
var mongoose = require('mongoose');
|
|
|
|
// A teljes munka ráfordítás műhelyben
|
|
exports.apiGetDailyReportSum=asyncHandler(async (req,res)=>{
|
|
//const {workId,foremanId, workTitle,employeeList }=req.body;
|
|
|
|
res.setHeader('Content-Type', 'application/json');
|
|
try{
|
|
var wtSum=0;
|
|
|
|
const count=await Work.aggregate([
|
|
{$match:{'_id' : mongoose.Types.ObjectId(req.params.id)}},
|
|
{$unwind: '$dailyReport'},
|
|
|
|
{$unwind: {path:'$dailyReport.employeeList',preserveNullAndEmptyArrays:true}},
|
|
|
|
|
|
{"$lookup": {
|
|
"localField": "dailyReport.employeeList",
|
|
|
|
"from": "employees",
|
|
"foreignField": "_id",
|
|
"as": "books"
|
|
}},
|
|
|
|
{$unwind: {path:'$books',preserveNullAndEmptyArrays:true}},
|
|
{$group: {_id: '$workFlow.EmployeeList', count:{$sum:1}}},
|
|
{ "$limit": 1 },
|
|
{"$project": {"_id":0,
|
|
"count": 1,}
|
|
}
|
|
])
|
|
|
|
if (count) wtSum=count[0].count*8
|
|
res.send({'response':'ok', 'dailyReportSum':wtSum});
|
|
}catch(err){
|
|
|
|
res.status(500).json({'response':'fail','message':'Hiba a mentésnél !\n'+err.message});
|
|
}
|
|
|
|
});
|