summaryrefslogtreecommitdiff
path: root/src/queue/processors/db/export-notes.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/queue/processors/db/export-notes.ts')
-rw-r--r--src/queue/processors/db/export-notes.ts15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/queue/processors/db/export-notes.ts b/src/queue/processors/db/export-notes.ts
index 92867ad82e..eaa5caf63f 100644
--- a/src/queue/processors/db/export-notes.ts
+++ b/src/queue/processors/db/export-notes.ts
@@ -9,15 +9,18 @@ import { Users, Notes, Polls } from '../../../models';
import { MoreThan } from 'typeorm';
import { Note } from '../../../models/entities/note';
import { Poll } from '../../../models/entities/poll';
+import { ensure } from '../../../prelude/ensure';
const logger = queueLogger.createSubLogger('export-notes');
export async function exportNotes(job: Bull.Job, done: any): Promise<void> {
logger.info(`Exporting notes of ${job.data.user.id} ...`);
- const user = await Users.findOne({
- id: job.data.user.id
- });
+ const user = await Users.findOne(job.data.user.id);
+ if (user == null) {
+ done();
+ return;
+ }
// Create temp file
const [path, cleanup] = await new Promise<[string, any]>((res, rej) => {
@@ -67,9 +70,9 @@ export async function exportNotes(job: Bull.Job, done: any): Promise<void> {
cursor = notes[notes.length - 1].id;
for (const note of notes) {
- let poll: Poll;
+ let poll: Poll | undefined;
if (note.hasPoll) {
- poll = await Polls.findOne({ noteId: note.id });
+ poll = await Polls.findOne({ noteId: note.id }).then(ensure);
}
const content = JSON.stringify(serialize(note, poll));
await new Promise((res, rej) => {
@@ -114,7 +117,7 @@ export async function exportNotes(job: Bull.Job, done: any): Promise<void> {
done();
}
-function serialize(note: Note, poll: Poll): any {
+function serialize(note: Note, poll: Poll | null = null): any {
return {
id: note.id,
text: note.text,