2019-09-01 14:58:13 +08:00
|
|
|
"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.`];
|
|
|
|
}
|
|
|
|
|
2019-09-01 17:33:45 +08:00
|
|
|
const results = await noteCacheService.findSimilarNotes(note.title);
|
|
|
|
|
2019-09-01 14:58:13 +08:00
|
|
|
return results
|
2019-09-01 17:33:45 +08:00
|
|
|
.filter(note => note.noteId !== noteId);
|
2019-09-01 14:58:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getSimilarNotes
|
|
|
|
};
|