RevisionsService: Implement getLatestRevision and createRevision methods

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2020-09-22 17:29:59 +02:00
parent fae8c679a9
commit 74b03fc1fd
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

@ -1,9 +1,16 @@
import { Injectable, Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { RevisionMetadataDto } from './revision-metadata.dto'; import { RevisionMetadataDto } from './revision-metadata.dto';
import { RevisionDto } from './revision.dto'; import { RevisionDto } from './revision.dto';
import { Revision } from './revision.entity';
@Injectable() @Injectable()
export class RevisionsService { export class RevisionsService {
constructor(
@InjectRepository(Revision)
private revisionRepository: Repository<Revision>,
) {}
private readonly logger = new Logger(RevisionsService.name); private readonly logger = new Logger(RevisionsService.name);
getNoteRevisionMetadatas(noteIdOrAlias: string): RevisionMetadataDto[] { getNoteRevisionMetadatas(noteIdOrAlias: string): RevisionMetadataDto[] {
this.logger.warn('Using hardcoded data!'); this.logger.warn('Using hardcoded data!');
@ -24,4 +31,25 @@ export class RevisionsService {
patch: 'barfoo', patch: 'barfoo',
}; };
} }
getLatestRevision(noteId: string): Promise<Revision> {
return this.revisionRepository.findOne({
where: {
note: noteId,
},
order: {
createdAt: 'DESC',
},
});
}
createRevision(content: string) {
// TODO: Add previous revision
// TODO: Calculate patch
return this.revisionRepository.create({
content: content,
length: content.length,
patch: '',
});
}
} }