2019-03-29 02:47:11 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Note from '/imports/api/note';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2021-02-10 23:24:24 +08:00
|
|
|
import addPad from '/imports/api/note/server/methods/addPad';
|
2019-03-29 02:47:11 +08:00
|
|
|
|
|
|
|
export default function addNote(meetingId, noteId, readOnlyNoteId) {
|
|
|
|
check(meetingId, String);
|
|
|
|
check(noteId, String);
|
|
|
|
check(readOnlyNoteId, String);
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
2019-06-01 04:02:33 +08:00
|
|
|
noteId,
|
2019-03-29 02:47:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
meetingId,
|
|
|
|
noteId,
|
|
|
|
readOnlyNoteId,
|
2019-06-01 04:02:33 +08:00
|
|
|
revs: 0,
|
2019-03-29 02:47:11 +08:00
|
|
|
};
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
|
|
|
const { insertedId } = Note.upsert(selector, modifier);
|
2019-03-29 02:47:11 +08:00
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
if (insertedId) {
|
2021-02-10 23:24:24 +08:00
|
|
|
addPad(meetingId, noteId, readOnlyNoteId);
|
2020-11-23 21:13:46 +08:00
|
|
|
Logger.info(`Added note id=${noteId} readOnlyId=${readOnlyNoteId} meeting=${meetingId}`);
|
|
|
|
} else {
|
|
|
|
Logger.info(`Upserted note id=${noteId} readOnlyId=${readOnlyNoteId} meeting=${meetingId}`);
|
2019-03-29 02:47:11 +08:00
|
|
|
}
|
2020-11-23 21:13:46 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Adding note to the collection: ${err}`);
|
|
|
|
}
|
2019-03-29 02:47:11 +08:00
|
|
|
}
|