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';
|
2020-04-26 03:03:35 +08:00
|
|
|
import { getDefaultTime } from '/imports/api/timer/server/helpers';
|
2023-05-11 04:03:20 +08:00
|
|
|
|
2020-04-26 03:03:35 +08:00
|
|
|
// This method should only be used by the server
|
2023-05-11 04:03:20 +08:00
|
|
|
export default function addTimer(meetingId) {
|
|
|
|
check(meetingId, String);
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
};
|
|
|
|
|
2020-04-26 03:03:35 +08:00
|
|
|
const time = getDefaultTime();
|
|
|
|
check(time, Number);
|
|
|
|
|
2023-05-11 04:03:20 +08:00
|
|
|
const modifier = {
|
|
|
|
meetingId,
|
|
|
|
stopwatch: true,
|
|
|
|
active: false,
|
|
|
|
running: false,
|
2020-04-26 03:03:35 +08:00
|
|
|
time,
|
2023-05-11 04:03:20 +08:00
|
|
|
accumulated: 0,
|
|
|
|
timestamp: 0,
|
2021-09-03 20:44:16 +08:00
|
|
|
music: false,
|
2023-05-11 04:03:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
|
|
|
return Logger.error(`Adding timer to the collection: ${err}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numChanged) {
|
2020-04-27 01:44:01 +08:00
|
|
|
return Logger.debug(`Added timer meeting=${meetingId}`);
|
2023-05-11 04:03:20 +08:00
|
|
|
}
|
|
|
|
|
2020-04-27 01:44:01 +08:00
|
|
|
return Logger.debug(`Upserted timer meeting=${meetingId}`);
|
2023-05-11 04:03:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return Timer.upsert(selector, modifier, cb);
|
|
|
|
}
|