Added types

Signed-off-by: Yannick Bungers <git@innay.de>
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
Yannick Bungers 2020-04-11 13:14:20 +02:00 committed by David Mehren
parent c6655d767a
commit 84e021a0b0
No known key found for this signature in database
GPG key ID: 6017AF117F9756CB

View file

@ -194,10 +194,10 @@ export class Revision extends Model<Revision> {
} }
] ]
} }
}).then(function (notes) { }).then(function (notes: Note[]) {
if (notes.length <= 0) return callback(null, notes) if (notes.length <= 0) return callback(null, notes)
const savedNotes: any[] = []; const savedNotes: Note[] = [];
async.each(notes, function (note: any, _callback) { async.each(notes, function (note: Note, _callback) {
// revision saving policy: note not been modified for 5 mins or not save for 10 mins // revision saving policy: note not been modified for 5 mins or not save for 10 mins
if (note.lastchangeAt && note.savedAt) { if (note.lastchangeAt && note.savedAt) {
const lastchangeAt = moment(note.lastchangeAt); const lastchangeAt = moment(note.lastchangeAt);
@ -220,7 +220,7 @@ export class Revision extends Model<Revision> {
return callback(err, null) return callback(err, null)
} }
// return null when no notes need saving at this moment but have delayed tasks to be done // return null when no notes need saving at this moment but have delayed tasks to be done
const result = ((savedNotes.length === 0) && (notes.length > savedNotes.length)) ? null : savedNotes; const result = ((savedNotes.length === 0) && (notes.length > 0)) ? null : savedNotes;
return callback(null, result) return callback(null, result)
}) })
}).catch(function (err) { }).catch(function (err) {
@ -228,7 +228,7 @@ export class Revision extends Model<Revision> {
}) })
} }
static saveNoteRevision(note, callback) { static saveNoteRevision(note : Note, callback) {
Revision.findAll({ Revision.findAll({
where: { where: {
noteId: note.id noteId: note.id
@ -237,10 +237,14 @@ export class Revision extends Model<Revision> {
}).then(function (revisions) { }).then(function (revisions) {
if (revisions.length <= 0) { if (revisions.length <= 0) {
// if no revision available // if no revision available
let noteContent = note.content;
if (noteContent.length === 0) {
noteContent = '';
}
Revision.create({ Revision.create({
noteId: note.id, noteId: note.id,
lastContent: note.content ? note.content : '', lastContent: noteContent,
length: note.content ? note.content.length : 0, length: noteContent.length,
authorship: note.authorship authorship: note.authorship
}).then(function (revision) { }).then(function (revision) {
Revision.finishSaveNoteRevision(note, revision, callback) Revision.finishSaveNoteRevision(note, revision, callback)