diff --git a/src/revisions/revision.dto.ts b/src/revisions/revision.dto.ts index faff5e6ba..3bebce22a 100644 --- a/src/revisions/revision.dto.ts +++ b/src/revisions/revision.dto.ts @@ -1,4 +1,4 @@ -import { IsNumber, IsString } from 'class-validator'; +import { IsDate, IsNumber, IsString } from 'class-validator'; import { Revision } from './revision.entity'; export class RevisionDto { @@ -8,4 +8,6 @@ export class RevisionDto { content: string; @IsString() patch: string; + @IsDate() + createdAt: Date; } diff --git a/src/revisions/revisions.service.ts b/src/revisions/revisions.service.ts index 26beaa01e..1a64a89ea 100644 --- a/src/revisions/revisions.service.ts +++ b/src/revisions/revisions.service.ts @@ -8,12 +8,14 @@ import { Revision } from './revision.entity'; @Injectable() export class RevisionsService { + private readonly logger = new Logger(RevisionsService.name); + constructor( @InjectRepository(Revision) private revisionRepository: Repository, @Inject(NotesService) private notesService: NotesService, ) {} - private readonly logger = new Logger(RevisionsService.name); + async getNoteRevisionMetadatas( noteIdOrAlias: string, ): Promise { @@ -26,13 +28,18 @@ export class RevisionsService { return revisions.map(revision => this.toMetadataDto(revision)); } - getNoteRevision(noteIdOrAlias: string, revisionId: number): RevisionDto { - this.logger.warn('Using hardcoded data!'); - return { - id: revisionId, - content: 'Foobar', - patch: 'barfoo', - }; + async getNoteRevision( + noteIdOrAlias: string, + revisionId: number, + ): Promise { + const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias); + const revision = await this.revisionRepository.findOne({ + where: { + id: revisionId, + note: note, + }, + }); + return this.toDto(revision); } getLatestRevision(noteId: string): Promise { @@ -55,6 +62,15 @@ export class RevisionsService { }; } + toDto(revision: Revision): RevisionDto { + return { + id: revision.id, + content: revision.content, + createdAt: revision.createdAt, + patch: revision.patch, + }; + } + createRevision(content: string) { // TODO: Add previous revision // TODO: Calculate patch