mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 09:46:30 -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()
|
@ValidateNested()
|
||||||
permissions: NotePermissionsDto;
|
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 { RevisionsService } from '../revisions/revisions.service';
|
||||||
import { User } from '../users/user.entity';
|
import { User } from '../users/user.entity';
|
||||||
import { UsersService } from '../users/users.service';
|
import { UsersService } from '../users/users.service';
|
||||||
import { NoteMetadataDto } from './note-metadata.dto';
|
import { NoteMetadataDto, NoteMetadataUpdateDto } from './note-metadata.dto';
|
||||||
import {
|
import {
|
||||||
NotePermissionsDto,
|
NotePermissionsDto,
|
||||||
NotePermissionsUpdateDto,
|
NotePermissionsUpdateDto,
|
||||||
} from './note-permissions.dto';
|
} from './note-permissions.dto';
|
||||||
import { NoteDto } from './note.dto';
|
import { NoteDto } from './note.dto';
|
||||||
import { Note } from './note.entity';
|
import { Note } from './note.entity';
|
||||||
import { NoteUtils } from './note.utils';
|
import { Tag } from './tag.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class NotesService {
|
export class NotesService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly logger: ConsoleLoggerService,
|
private readonly logger: ConsoleLoggerService,
|
||||||
@InjectRepository(Note) private noteRepository: Repository<Note>,
|
@InjectRepository(Note) private noteRepository: Repository<Note>,
|
||||||
|
@InjectRepository(Tag) private tagRepository: Repository<Tag>,
|
||||||
@Inject(UsersService) private usersService: UsersService,
|
@Inject(UsersService) private usersService: UsersService,
|
||||||
@Inject(forwardRef(() => RevisionsService))
|
@Inject(forwardRef(() => RevisionsService))
|
||||||
private revisionsService: RevisionsService,
|
private revisionsService: RevisionsService,
|
||||||
|
@ -219,4 +220,23 @@ export class NotesService {
|
||||||
editedByAtPosition: [],
|
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