oneuptime/init-script/scripts/3.0.9222.ts
Nawaz Dhandala afd62f21ce
fix lint
2022-03-22 14:33:55 +00:00

32 lines
912 B
TypeScript

import { find, update, findOne } from '../util/db';
const scheduledEventNoteCollection = 'scheduledeventnotes';
const scheduledEventCollection = 'scheduledevents';
// run this script once
async function run() {
const scheduledEventNotes = await find(scheduledEventNoteCollection, {
content: 'THIS SCHEDULED EVENT HAS BEEN CREATED',
event_state: 'Created',
deleted: false,
});
for (const note of scheduledEventNotes) {
const scheduledEvent = await findOne(scheduledEventCollection, {
_id: note.scheduledEventId,
});
if (scheduledEvent) {
await update(
scheduledEventNoteCollection,
{ _id: note._id },
{ content: scheduledEvent.description }
);
}
}
return `Script ran for ${scheduledEventNotes.length} scheduled event notes`;
}
export default run;