-
Notifications
You must be signed in to change notification settings - Fork 70
/
chat-archive.service.ts
59 lines (50 loc) · 1.76 KB
/
chat-archive.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2023 Sourcefuse Technologies
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
import {injectable, inject, BindingScope} from '@loopback/core';
import {repository} from '@loopback/repository';
import {HttpErrors} from '@loopback/rest';
import {ExternalStorageOptions} from '..';
import {VideoChatBindings} from '../keys';
import {VideoChatSessionRepository} from '../repositories';
import {VideoChatInterface} from '../types';
@injectable({scope: BindingScope.TRANSIENT})
export class ChatArchiveService {
constructor(
@inject(VideoChatBindings.VideoChatProvider)
private readonly videoChatProvider: VideoChatInterface,
@repository(VideoChatSessionRepository)
private readonly videoChatSessionRepository: VideoChatSessionRepository,
) {}
async getArchive(archiveId: string) {
const archiveExists = await this.videoChatSessionRepository.findOne({
where: {
archiveId: archiveId,
},
});
if (!archiveExists) {
const errorMessage = 'Archive Not Found';
throw new HttpErrors.NotFound(errorMessage);
}
return this.videoChatProvider.getArchives(archiveId);
}
async getArchives() {
return this.videoChatProvider.getArchives(null);
}
async deleteArchive(archiveId: string): Promise<void> {
const archiveExists = await this.videoChatSessionRepository.findOne({
where: {
archiveId: archiveId,
},
});
if (!archiveExists) {
const errorMessage = 'Archive Not Found';
throw new HttpErrors.NotFound(errorMessage);
}
return this.videoChatProvider.deleteArchive(archiveId);
}
async setUploadTarget(body: ExternalStorageOptions): Promise<void> {
await this.videoChatProvider.setUploadTarget(body);
}
}