mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 19:26:31 -05:00
MediaService: Add removeNoteFromMediaUpload method
This method replaces the associated note of a media upload with null. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
41765ac300
commit
b65297523c
2 changed files with 37 additions and 0 deletions
|
@ -265,4 +265,27 @@ describe('MediaService', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeNoteFromMediaUpload', () => {
|
||||
it('works', async () => {
|
||||
const mockMediaUploadEntry = {
|
||||
id: 'testMediaUpload',
|
||||
backendData: 'testBackendData',
|
||||
note: {
|
||||
alias: 'test',
|
||||
} as Note,
|
||||
user: {
|
||||
userName: 'hardcoded',
|
||||
} as User,
|
||||
} as MediaUpload;
|
||||
jest
|
||||
.spyOn(mediaRepo, 'save')
|
||||
.mockImplementationOnce(async (entry: MediaUpload) => {
|
||||
expect(entry.note).toBeNull();
|
||||
return entry;
|
||||
});
|
||||
await service.removeNoteFromMediaUpload(mockMediaUploadEntry);
|
||||
expect(mediaRepo.save).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -176,6 +176,20 @@ export class MediaService {
|
|||
return mediaUploads;
|
||||
}
|
||||
|
||||
/**
|
||||
* @async
|
||||
* Set the note of a mediaUpload to null
|
||||
* @param {MediaUpload} mediaUpload - the media upload to be changed
|
||||
*/
|
||||
async removeNoteFromMediaUpload(mediaUpload: MediaUpload): Promise<void> {
|
||||
this.logger.debug(
|
||||
'Setting note to null for mediaUpload: ' + mediaUpload.id,
|
||||
'removeNoteFromMediaUpload',
|
||||
);
|
||||
mediaUpload.note = null;
|
||||
await this.mediaUploadRepository.save(mediaUpload);
|
||||
}
|
||||
|
||||
private chooseBackendType(): BackendType {
|
||||
switch (this.mediaConfig.backend.use) {
|
||||
case 'filesystem':
|
||||
|
|
Loading…
Reference in a new issue