From 65c76d0998e0396d568ad17e7d4b54e4deba318c Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 10 Jan 2021 18:22:30 +0100 Subject: [PATCH] NotesService: Get note creation time from database Signed-off-by: David Mehren --- src/notes/notes.service.ts | 9 ++++++--- src/revisions/revisions.service.ts | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index 79c6df6ca..012a3898c 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -13,7 +13,7 @@ import { Revision } from '../revisions/revision.entity'; import { RevisionsService } from '../revisions/revisions.service'; import { User } from '../users/user.entity'; import { UsersService } from '../users/users.service'; -import { NoteMetadataDto, NoteMetadataUpdateDto } from './note-metadata.dto'; +import { NoteMetadataDto } from './note-metadata.dto'; import { NotePermissionsDto, NotePermissionsUpdateDto, @@ -104,14 +104,17 @@ export class NotesService { return this.revisionsService.getLatestRevision(note.id); } + async getFirstRevision(note: Note): Promise { + return this.revisionsService.getFirstRevision(note.id); + } + async getMetadata(note: Note): Promise { return { // TODO: Convert DB UUID to base64 id: note.id, alias: note.alias, title: note.title, - // TODO: Get actual createTime - createTime: new Date(), + createTime: (await this.getFirstRevision(note)).createdAt, description: note.description, editedBy: note.authorColors.map( (authorColor) => authorColor.user.userName, diff --git a/src/revisions/revisions.service.ts b/src/revisions/revisions.service.ts index f3de1a0c2..389fe422d 100644 --- a/src/revisions/revisions.service.ts +++ b/src/revisions/revisions.service.ts @@ -62,6 +62,17 @@ export class RevisionsService { }); } + getFirstRevision(noteId: string): Promise { + return this.revisionRepository.findOne({ + where: { + note: noteId, + }, + order: { + createdAt: 'ASC', + }, + }); + } + toMetadataDto(revision: Revision): RevisionMetadataDto { return { id: revision.id,