diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2019-04-13 01:43:22 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-13 01:43:22 +0900 |
| commit | 987168b863c52d0548050ffbac569782bb9a8cef (patch) | |
| tree | c9aa2243dcdcbd044688d201a51c601574bff259 /src/queue/processors/db/export-notes.ts | |
| parent | Fix bug (diff) | |
| download | sharkey-987168b863c52d0548050ffbac569782bb9a8cef.tar.gz sharkey-987168b863c52d0548050ffbac569782bb9a8cef.tar.bz2 sharkey-987168b863c52d0548050ffbac569782bb9a8cef.zip | |
strictNullChecks (#4666)
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
Diffstat (limited to 'src/queue/processors/db/export-notes.ts')
| -rw-r--r-- | src/queue/processors/db/export-notes.ts | 15 |
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, |