2019-09-01 08:58:13 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-05-17 10:11:19 +02:00
|
|
|
const noteCacheService = require('../../services/note_cache/note_cache_service');
|
2019-09-01 08:58:13 +02:00
|
|
|
const repository = require('../../services/repository');
|
|
|
|
|
2020-09-10 21:01:46 +02:00
|
|
|
async function getSimilarNotes(req) {
|
2019-09-01 08:58:13 +02:00
|
|
|
const noteId = req.params.noteId;
|
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
const note = repository.getNote(noteId);
|
2019-09-01 08:58:13 +02:00
|
|
|
|
|
|
|
if (!note) {
|
|
|
|
return [404, `Note ${noteId} not found.`];
|
|
|
|
}
|
|
|
|
|
2020-09-10 21:01:46 +02:00
|
|
|
const results = await noteCacheService.findSimilarNotes(noteId);
|
2019-09-01 11:33:45 +02:00
|
|
|
|
2019-09-01 08:58:13 +02:00
|
|
|
return results
|
2019-09-01 11:33:45 +02:00
|
|
|
.filter(note => note.noteId !== noteId);
|
2019-09-01 08:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getSimilarNotes
|
2020-05-13 14:42:16 +02:00
|
|
|
};
|