mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-01-22 23:01:46 +00:00
RevisionService: Implement getNoteRevisionMetadatas
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
3d4e9a9b92
commit
05a62b31ee
4 changed files with 31 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { RevisionsModule } from '../revisions/revisions.module';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
|
@ -9,7 +9,7 @@ import { NotesService } from './notes.service';
|
|||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Note, AuthorColor]),
|
||||
RevisionsModule,
|
||||
forwardRef(() => RevisionsModule),
|
||||
UsersModule,
|
||||
],
|
||||
controllers: [],
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Revision } from '../revisions/revision.entity';
|
||||
|
@ -21,7 +21,8 @@ export class NotesService {
|
|||
constructor(
|
||||
@InjectRepository(Note) private noteRepository: Repository<Note>,
|
||||
@Inject(UsersService) private usersService: UsersService,
|
||||
@Inject(RevisionsService) private revisionsService: RevisionsService,
|
||||
@Inject(forwardRef(() => RevisionsService))
|
||||
private revisionsService: RevisionsService,
|
||||
) {}
|
||||
|
||||
getUserNotes(username: string): NoteMetadataDto[] {
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { NotesModule } from '../notes/notes.module';
|
||||
import { Authorship } from './authorship.entity';
|
||||
import { Revision } from './revision.entity';
|
||||
import { RevisionsService } from './revisions.service';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Revision, Authorship])],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Revision, Authorship]),
|
||||
forwardRef(() => NotesModule),
|
||||
],
|
||||
providers: [RevisionsService],
|
||||
exports: [RevisionsService],
|
||||
})
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { NotesService } from '../notes/notes.service';
|
||||
import { RevisionMetadataDto } from './revision-metadata.dto';
|
||||
import { RevisionDto } from './revision.dto';
|
||||
import { Revision } from './revision.entity';
|
||||
|
@ -10,17 +11,19 @@ export class RevisionsService {
|
|||
constructor(
|
||||
@InjectRepository(Revision)
|
||||
private revisionRepository: Repository<Revision>,
|
||||
@Inject(NotesService) private notesService: NotesService,
|
||||
) {}
|
||||
private readonly logger = new Logger(RevisionsService.name);
|
||||
getNoteRevisionMetadatas(noteIdOrAlias: string): RevisionMetadataDto[] {
|
||||
this.logger.warn('Using hardcoded data!');
|
||||
return [
|
||||
{
|
||||
id: 42,
|
||||
updatedAt: new Date(),
|
||||
length: 42,
|
||||
async getNoteRevisionMetadatas(
|
||||
noteIdOrAlias: string,
|
||||
): Promise<RevisionMetadataDto[]> {
|
||||
const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||
const revisions = await this.revisionRepository.find({
|
||||
where: {
|
||||
note: note.id,
|
||||
},
|
||||
];
|
||||
});
|
||||
return revisions.map(revision => this.toMetadataDto(revision));
|
||||
}
|
||||
|
||||
getNoteRevision(noteIdOrAlias: string, revisionId: number): RevisionDto {
|
||||
|
@ -44,6 +47,14 @@ export class RevisionsService {
|
|||
});
|
||||
}
|
||||
|
||||
toMetadataDto(revision: Revision): RevisionMetadataDto {
|
||||
return {
|
||||
id: revision.id,
|
||||
length: revision.length,
|
||||
createdAt: revision.createdAt,
|
||||
};
|
||||
}
|
||||
|
||||
createRevision(content: string) {
|
||||
// TODO: Add previous revision
|
||||
// TODO: Calculate patch
|
||||
|
|
Loading…
Reference in a new issue