@@ -285,6 +285,55 @@ export default class NoteSequelizeStorage {
285285 } ) ;
286286 }
287287
288+ /**
289+ * Gets note list created by user
290+ * @param creatorId - id of note creator
291+ * @param offset - number of skipped notes
292+ * @param limit - number of notes to get
293+ * @returns list of the notes ordered by updatedAt DESC
294+ */
295+ public async getMyNoteList ( creatorId : number , offset : number , limit : number ) : Promise < Note [ ] > {
296+ if ( ! this . settingsModel ) {
297+ throw new Error ( 'NoteStorage: Note settings model not initialized' ) ;
298+ }
299+
300+ const reply = await this . model . findAll ( {
301+ offset : offset ,
302+ limit : limit ,
303+ where : {
304+ creatorId : creatorId ,
305+ } ,
306+ order : [ [ 'updatedAt' , 'DESC' ] ] ,
307+ include : [
308+ {
309+ model : this . settingsModel ,
310+ as : 'noteSettings' ,
311+ attributes : [ 'cover' ] ,
312+ duplicating : false ,
313+ } ,
314+ ] ,
315+ } ) ;
316+
317+ /**
318+ * Convert note model data to Note entity with cover property
319+ */
320+ return reply . map ( ( note ) => {
321+ return {
322+ id : note . id ,
323+ /**
324+ * noteSettings is required to be, because we make join
325+ */
326+ cover : note . noteSettings ! . cover ,
327+ content : note . content ,
328+ updatedAt : note . updatedAt ,
329+ createdAt : note . createdAt ,
330+ publicId : note . publicId ,
331+ creatorId : note . creatorId ,
332+ tools : note . tools ,
333+ } ;
334+ } ) ;
335+ }
336+
288337 /**
289338 * Gets note by id
290339 * @param hostname - custom hostname
@@ -356,18 +405,18 @@ export default class NoteSequelizeStorage {
356405 // Fetch all notes and relations in a recursive query
357406 const query = `
358407 WITH RECURSIVE note_tree AS (
359- SELECT
408+ SELECT
360409 n.id AS "noteId",
361410 n.content,
362411 n.public_id AS "publicId",
363412 nr.parent_id AS "parentId"
364413 FROM ${ String ( this . database . literal ( this . tableName ) . val ) } n
365414 LEFT JOIN ${ String ( this . database . literal ( 'note_relations' ) . val ) } nr ON n.id = nr.note_id
366415 WHERE n.id = :startNoteId
367-
416+
368417 UNION ALL
369418
370- SELECT
419+ SELECT
371420 n.id AS "noteId",
372421 n.content,
373422 n.public_id AS "publicId",
0 commit comments