mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
NotesService: Implement updateNoteMetadata
Signed-off-by: David Mehren <git@herrmehren.de> Co-authored-by: Yannick Bungers <git@innay.de>
This commit is contained in:
parent
6541cfda4e
commit
08fd070bcb
2 changed files with 32 additions and 2 deletions
|
@ -34,3 +34,13 @@ export class NoteMetadataDto {
|
|||
@ValidateNested()
|
||||
permissions: NotePermissionsDto;
|
||||
}
|
||||
|
||||
export class NoteMetadataUpdateDto {
|
||||
@IsString()
|
||||
title: string;
|
||||
@IsString()
|
||||
description: string;
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
tags: string[];
|
||||
}
|
||||
|
|
|
@ -7,20 +7,21 @@ import { Revision } from '../revisions/revision.entity';
|
|||
import { RevisionsService } from '../revisions/revisions.service';
|
||||
import { User } from '../users/user.entity';
|
||||
import { UsersService } from '../users/users.service';
|
||||
import { NoteMetadataDto } from './note-metadata.dto';
|
||||
import { NoteMetadataDto, NoteMetadataUpdateDto } from './note-metadata.dto';
|
||||
import {
|
||||
NotePermissionsDto,
|
||||
NotePermissionsUpdateDto,
|
||||
} from './note-permissions.dto';
|
||||
import { NoteDto } from './note.dto';
|
||||
import { Note } from './note.entity';
|
||||
import { NoteUtils } from './note.utils';
|
||||
import { Tag } from './tag.entity';
|
||||
|
||||
@Injectable()
|
||||
export class NotesService {
|
||||
constructor(
|
||||
private readonly logger: ConsoleLoggerService,
|
||||
@InjectRepository(Note) private noteRepository: Repository<Note>,
|
||||
@InjectRepository(Tag) private tagRepository: Repository<Tag>,
|
||||
@Inject(UsersService) private usersService: UsersService,
|
||||
@Inject(forwardRef(() => RevisionsService))
|
||||
private revisionsService: RevisionsService,
|
||||
|
@ -219,4 +220,23 @@ export class NotesService {
|
|||
editedByAtPosition: [],
|
||||
};
|
||||
}
|
||||
|
||||
async updateNoteMetadata(
|
||||
noteIdOrAlias: string,
|
||||
updateDto: NoteMetadataUpdateDto,
|
||||
) {
|
||||
const note = await this.getNoteByIdOrAlias(noteIdOrAlias);
|
||||
note.title = updateDto.title;
|
||||
note.description = updateDto.description;
|
||||
note.tags = await Promise.all(
|
||||
updateDto.tags.map(async tag => {
|
||||
let dbTag = await this.tagRepository.findOne({ where: { name: tag } });
|
||||
if (!dbTag) {
|
||||
dbTag = await this.tagRepository.create({ name: tag });
|
||||
}
|
||||
return dbTag;
|
||||
}),
|
||||
);
|
||||
await this.noteRepository.save(note);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue