mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-29 18:14:26 -05:00
MediaService: Add listUploadsByNote method
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
53f5093630
commit
890de2dea1
2 changed files with 54 additions and 0 deletions
|
@ -264,4 +264,40 @@ describe('MediaService', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('listUploadsByNote', () => {
|
||||||
|
describe('works', () => {
|
||||||
|
it('with one upload to note', async () => {
|
||||||
|
const mockMediaUploadEntry = {
|
||||||
|
id: 'testMediaUpload',
|
||||||
|
backendData: 'testBackendData',
|
||||||
|
note: {
|
||||||
|
id: '123',
|
||||||
|
} as Note,
|
||||||
|
} as MediaUpload;
|
||||||
|
jest
|
||||||
|
.spyOn(mediaRepo, 'find')
|
||||||
|
.mockResolvedValueOnce([mockMediaUploadEntry]);
|
||||||
|
const mediaList = await service.listUploadsByNote({
|
||||||
|
id: '123',
|
||||||
|
} as Note);
|
||||||
|
expect(mediaList).toEqual([mockMediaUploadEntry]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('without uploads to note', async () => {
|
||||||
|
jest.spyOn(mediaRepo, 'find').mockResolvedValueOnce([]);
|
||||||
|
const mediaList = await service.listUploadsByNote({
|
||||||
|
id: '123',
|
||||||
|
} as Note);
|
||||||
|
expect(mediaList).toEqual([]);
|
||||||
|
});
|
||||||
|
it('with error (undefined as return value of find)', async () => {
|
||||||
|
jest.spyOn(mediaRepo, 'find').mockResolvedValueOnce(undefined);
|
||||||
|
const mediaList = await service.listUploadsByNote({
|
||||||
|
id: '123',
|
||||||
|
} as Note);
|
||||||
|
expect(mediaList).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -24,6 +24,7 @@ import { AzureBackend } from './backends/azure-backend';
|
||||||
import { ImgurBackend } from './backends/imgur-backend';
|
import { ImgurBackend } from './backends/imgur-backend';
|
||||||
import { User } from '../users/user.entity';
|
import { User } from '../users/user.entity';
|
||||||
import { MediaUploadDto } from './media-upload.dto';
|
import { MediaUploadDto } from './media-upload.dto';
|
||||||
|
import { Note } from '../notes/note.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MediaService {
|
export class MediaService {
|
||||||
|
@ -175,6 +176,23 @@ export class MediaService {
|
||||||
return mediaUploads;
|
return mediaUploads;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @async
|
||||||
|
* List all uploads by a specific note
|
||||||
|
* @param {Note} note - the specific user
|
||||||
|
* @return {MediaUpload[]} arary of media uploads owned by the user
|
||||||
|
*/
|
||||||
|
async listUploadsByNote(note: Note): Promise<MediaUpload[]> {
|
||||||
|
const mediaUploads = await this.mediaUploadRepository.find({
|
||||||
|
where: { note: note },
|
||||||
|
relations: ['user', 'note'],
|
||||||
|
});
|
||||||
|
if (mediaUploads === undefined) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return mediaUploads;
|
||||||
|
}
|
||||||
|
|
||||||
private chooseBackendType(): BackendType {
|
private chooseBackendType(): BackendType {
|
||||||
switch (this.mediaConfig.backend.use) {
|
switch (this.mediaConfig.backend.use) {
|
||||||
case 'filesystem':
|
case 'filesystem':
|
||||||
|
|
Loading…
Reference in a new issue