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:
Philip Molares 2021-04-01 01:18:24 +02:00 committed by David Mehren
parent 41765ac300
commit b65297523c
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
2 changed files with 37 additions and 0 deletions

View file

@ -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();
});
});
});

View file

@ -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':