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';
|
import { Revision } from './revision.entity';
|
||||||
|
|
||||||
export class RevisionDto {
|
export class RevisionDto {
|
||||||
|
@ -8,4 +8,6 @@ export class RevisionDto {
|
||||||
content: string;
|
content: string;
|
||||||
@IsString()
|
@IsString()
|
||||||
patch: string;
|
patch: string;
|
||||||
|
@IsDate()
|
||||||
|
createdAt: Date;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,14 @@ import { Revision } from './revision.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RevisionsService {
|
export class RevisionsService {
|
||||||
|
private readonly logger = new Logger(RevisionsService.name);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Revision)
|
@InjectRepository(Revision)
|
||||||
private revisionRepository: Repository<Revision>,
|
private revisionRepository: Repository<Revision>,
|
||||||
@Inject(NotesService) private notesService: NotesService,
|
@Inject(NotesService) private notesService: NotesService,
|
||||||
) {}
|
) {}
|
||||||
private readonly logger = new Logger(RevisionsService.name);
|
|
||||||
async getNoteRevisionMetadatas(
|
async getNoteRevisionMetadatas(
|
||||||
noteIdOrAlias: string,
|
noteIdOrAlias: string,
|
||||||
): Promise<RevisionMetadataDto[]> {
|
): Promise<RevisionMetadataDto[]> {
|
||||||
|
@ -26,13 +28,18 @@ export class RevisionsService {
|
||||||
return revisions.map(revision => this.toMetadataDto(revision));
|
return revisions.map(revision => this.toMetadataDto(revision));
|
||||||
}
|
}
|
||||||
|
|
||||||
getNoteRevision(noteIdOrAlias: string, revisionId: number): RevisionDto {
|
async getNoteRevision(
|
||||||
this.logger.warn('Using hardcoded data!');
|
noteIdOrAlias: string,
|
||||||
return {
|
revisionId: number,
|
||||||
|
): Promise<RevisionDto> {
|
||||||
|
const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||||
|
const revision = await this.revisionRepository.findOne({
|
||||||
|
where: {
|
||||||
id: revisionId,
|
id: revisionId,
|
||||||
content: 'Foobar',
|
note: note,
|
||||||
patch: 'barfoo',
|
},
|
||||||
};
|
});
|
||||||
|
return this.toDto(revision);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLatestRevision(noteId: string): Promise<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) {
|
createRevision(content: string) {
|
||||||
// TODO: Add previous revision
|
// TODO: Add previous revision
|
||||||
// TODO: Calculate patch
|
// TODO: Calculate patch
|
||||||
|
|
Loading…
Reference in a new issue