refs #7360 fix error weekly
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Carlos Satorres 2024-05-09 09:46:40 +02:00
parent f64e899061
commit 0f52fe65d3
3 changed files with 12 additions and 12 deletions

View File

@ -1,3 +1,5 @@
const moment = require('moment');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('resendWeeklyHourEmail', { Self.remoteMethodCtx('resendWeeklyHourEmail', {
description: 'Send the records for the week of the date provided', description: 'Send the records for the week of the date provided',
@ -31,7 +33,8 @@ module.exports = Self => {
Object.assign(myOptions, options); Object.assign(myOptions, options);
const yearNumber = dated.getFullYear(); const yearNumber = dated.getFullYear();
const weekNumber = getWeekNumber(dated); const weekNumber = moment(dated).isoWeek();
const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({ const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({
where: { where: {
workerFk: workerId, workerFk: workerId,
@ -54,15 +57,4 @@ module.exports = Self => {
return false; return false;
}; };
function getWeekNumber(date) {
const tempDate = new Date(date);
let dayOfWeek = tempDate.getDay();
dayOfWeek = (dayOfWeek === 0) ? 7 : dayOfWeek;
const firstDayOfWeek = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() - (dayOfWeek - 1));
const firstDayOfYear = new Date(tempDate.getFullYear(), 0, 1);
const differenceInMilliseconds = firstDayOfWeek.getTime() - firstDayOfYear.getTime();
const weekNumber = Math.floor(differenceInMilliseconds / (1000 * 60 * 60 * 24 * 7)) + 1;
return weekNumber;
}
}; };

View File

@ -39,6 +39,7 @@
"loopback-context": "^3.5.2", "loopback-context": "^3.5.2",
"loopback-datasource-juggler": "3.36.1", "loopback-datasource-juggler": "3.36.1",
"md5": "^2.2.1", "md5": "^2.2.1",
"moment": "^2.30.1",
"mysql": "2.18.1", "mysql": "2.18.1",
"node-ssh": "^11.0.0", "node-ssh": "^11.0.0",
"object.pick": "^1.3.0", "object.pick": "^1.3.0",

View File

@ -83,6 +83,9 @@ dependencies:
md5: md5:
specifier: ^2.2.1 specifier: ^2.2.1
version: 2.3.0 version: 2.3.0
moment:
specifier: ^2.30.1
version: 2.30.1
mysql: mysql:
specifier: 2.18.1 specifier: 2.18.1
version: 2.18.1 version: 2.18.1
@ -10202,6 +10205,10 @@ packages:
to-iso-string: 0.0.2 to-iso-string: 0.0.2
dev: false dev: false
/moment@2.30.1:
resolution: {integrity: sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==}
dev: false
/ms@0.7.1: /ms@0.7.1:
resolution: {integrity: sha512-lRLiIR9fSNpnP6TC4v8+4OU7oStC01esuNowdQ34L+Gk8e5Puoc88IqJ+XAY/B3Mn2ZKis8l8HX90oU8ivzUHg==} resolution: {integrity: sha512-lRLiIR9fSNpnP6TC4v8+4OU7oStC01esuNowdQ34L+Gk8e5Puoc88IqJ+XAY/B3Mn2ZKis8l8HX90oU8ivzUHg==}
dev: false dev: false