2023-05-11 04:03:20 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Timer from '/imports/api/timer';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import updateTimer from '/imports/api/timer/server/modifiers/updateTimer';
|
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
|
|
|
|
|
|
|
export default function stopTimer() {
|
2022-07-14 00:59:02 +08:00
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2023-05-11 04:03:20 +08:00
|
|
|
check(meetingId, String);
|
2022-07-14 00:59:02 +08:00
|
|
|
check(requesterUserId, String);
|
2023-05-11 04:03:20 +08:00
|
|
|
|
|
|
|
const now = Date.now();
|
|
|
|
const timer = Timer.findOne(
|
|
|
|
{ meetingId },
|
|
|
|
{ fields:
|
|
|
|
{
|
2020-04-26 03:03:35 +08:00
|
|
|
stopwatch: 1,
|
2023-05-11 04:03:20 +08:00
|
|
|
time: 1,
|
|
|
|
accumulated: 1,
|
|
|
|
timestamp: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
if (timer) {
|
2020-04-26 03:03:35 +08:00
|
|
|
const {
|
|
|
|
stopwatch,
|
|
|
|
time,
|
|
|
|
timestamp,
|
|
|
|
} = timer;
|
|
|
|
|
|
|
|
const accumulated = timer.accumulated + (now - timestamp);
|
2022-08-31 22:46:03 +08:00
|
|
|
updateTimer({
|
|
|
|
action: 'stop',
|
|
|
|
meetingId,
|
|
|
|
requesterUserId,
|
|
|
|
time,
|
|
|
|
stopwatch,
|
|
|
|
accumulated,
|
|
|
|
});
|
2023-05-11 04:03:20 +08:00
|
|
|
} else {
|
|
|
|
Logger.warn(`Could not stop timer for meetingId=${meetingId}`);
|
|
|
|
}
|
|
|
|
}
|