mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-23 18:26:32 -05:00
RevisionsService: Get note revision from database
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
a3ba5bccf7
commit
881263f2a4
2 changed files with 27 additions and 9 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<Revision>,
|
||||
@Inject(NotesService) private notesService: NotesService,
|
||||
) {}
|
||||
private readonly logger = new Logger(RevisionsService.name);
|
||||
|
||||
async getNoteRevisionMetadatas(
|
||||
noteIdOrAlias: string,
|
||||
): Promise<RevisionMetadataDto[]> {
|
||||
|
@ -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 {
|
||||
async getNoteRevision(
|
||||
noteIdOrAlias: string,
|
||||
revisionId: number,
|
||||
): Promise<RevisionDto> {
|
||||
const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||
const revision = await this.revisionRepository.findOne({
|
||||
where: {
|
||||
id: revisionId,
|
||||
content: 'Foobar',
|
||||
patch: 'barfoo',
|
||||
};
|
||||
note: note,
|
||||
},
|
||||
});
|
||||
return this.toDto(revision);
|
||||
}
|
||||
|
||||
getLatestRevision(noteId: string): Promise<Revision> {
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue