basic implementation of "similar notes" widget

This commit is contained in:
zadam
2019-09-01 08:58:13 +02:00
parent bf5a31dcdb
commit 7c60080772
8 changed files with 71 additions and 3 deletions

View File

@@ -0,0 +1,24 @@
"use strict";
const noteCacheService = require('../../services/note_cache');
const repository = require('../../services/repository');
async function getSimilarNotes(req) {
const noteId = req.params.noteId;
const note = await repository.getNote(noteId);
if (!note) {
return [404, `Note ${noteId} not found.`];
}
const results = await noteCacheService.findNotes(note.title);
return results
.map(r => r.noteId)
.filter(similarNoteId => similarNoteId !== noteId);
}
module.exports = {
getSimilarNotes
};