mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-27 12:08:02 -05:00
RevisionsService: Implement getLatestRevision
and createRevision
methods
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
fae8c679a9
commit
74b03fc1fd
1 changed files with 28 additions and 0 deletions
|
@ -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: '',
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue