Reportistica Ore 2

This commit is contained in:
Paolo Arena
2021-02-24 04:48:31 +01:00
parent 14a3292da2
commit 39c08afb95
13 changed files with 427 additions and 56 deletions

View File

@@ -12,11 +12,17 @@ mongoose.plugin(schema => {
schema.options.usePushEach = true
});
var ObjectId = mongoose.Types.ObjectId;
const { ObjectID } = require('mongodb');
const HoursSchema = new Schema({
idapp: {
type: String,
},
userId: { type: Schema.Types.ObjectId, ref: 'User' },
userId: {
type: String
},
descr: {
type: String,
},
@@ -55,6 +61,127 @@ module.exports.findAllIdApp = async function (idapp) {
return await Hours.find(myfind);
};
module.exports.correggiHours = async function (idapp) {
const myfind = { idapp };
const myarr = await Hours.find(myfind);
for (const rec of myarr) {
rec.userId = rec.userId.toString();
let ris = await Hours.findOneAndUpdate({ _id: rec._id }, { $set: { userId: rec.userId } }, { new: false } );
if (!!ris) {
console.log('ris', ris);
}
}
};
module.exports.getHoursByIdCat = async function (idapp, userId, idCat, date_start, date_end) {
const myfind = [
{
$match: {
idapp,
userId,
date: { $gte: new Date(date_start), $lte: new Date(date_end) },
todoId: idCat
}
},
{
$group:
{
_id: "$todoId",
totalAmount: {
$sum: "$hours"
},
count: {
$sum: 1
}
}
}
];
try {
const ris = await Hours.aggregate(myfind);
if (ris.length > 0) {
return ris[0].totalAmount;
} else {
return 0;
}
} catch (e) {
console.log('e', e);
return 0;
}
};
module.exports.getTotalHoursByDate = async function (idapp, userId, date) {
const myfind = [
{
$match: {
idapp,
userId,
hours: { $gt: 0 },
date:
{
$gte: new Date(tools.getstrDateYYYY_MM_DD(date)),
$lte: new Date(tools.getstrDateYYYY_MM_DD(tools.AddDate(date, 1)))
}
},
},
{
$group:
{
_id: { $dateToString: { format: "%Y-%m-%d", date: "$date" } },
totalAmount: {
$sum: "$hours"
},
count: {
$sum: 1
}
}
}
]
;
try {
const ris = await Hours.aggregate(myfind);
if (ris.length > 0) {
return ris[0].totalAmount;
} else {
return 0;
}
} catch (e) {
console.log('e', e);
return 0;
}
}
;
module.exports.getHoursByDate = async function (idapp, userId, date) {
const mystr = tools.getstrDateYYYY_MM_DD(date);
// console.log(mystr);
const myfind =
{
idapp,
userId,
hours: { $gt: 0 },
date: {
$gte: new Date(tools.getstrDateYYYY_MM_DD(date)),
$lte: new Date(tools.getstrDateYYYY_MM_DD(tools.AddDate(date, 1)))
}
};
try {
return await Hours.find(myfind);
} catch (e) {
console.log('e', e);
return 0;
}
};
module.exports.calculateHoursTodo = async function (idtodo) {
const Hours = this;
@@ -93,6 +220,5 @@ module.exports.calculateHoursTodo = async function (idtodo) {
return 0;
}
}
;
};