返回 AiToEarn
media-group.service.ts
根目录 / project / aitoearn-backend / apps / aitoearn-server / src / core / content / media-group.service.ts
1 import { Injectable } from '@nestjs/common'
2 import { TableDto } from '@yikart/common'
3 import { MediaGroupRepository, MediaType } from '@yikart/mongodb'
4
5 @Injectable()
6 export class MediaGroupService {
7 constructor(private readonly mediaGroupRepository: MediaGroupRepository) { }
8 async create(
9 userId: string,
10 inData: { title: string, type: MediaType, desc?: string },
11 ) {
12 const res = await this.mediaGroupRepository.create({
13 userId,
14 ...inData,
15 })
16 return res
17 }
18
19 async del(id: string): Promise<boolean> {
20 const res = await this.mediaGroupRepository.delete(id)
21 return !!res
22 }
23
24 async updateInfo(
25 id: string,
26 newData: { title?: string, desc?: string },
27 ) {
28 const res = await this.mediaGroupRepository.update(id, newData)
29 return res
30 }
31
32 async getInfo(id: string) {
33 const res = await this.mediaGroupRepository.getInfo(id)
34 return res
35 }
36
37 async getDefaultGroup(userId: string) {
38 const res = await this.mediaGroupRepository.getDefaultGroup(userId)
39 return res
40 }
41
42 async getInfoByName(userId: string, title: string) {
43 const res = await this.mediaGroupRepository.getInfoByName(userId, title)
44 return res
45 }
46
47 async getList(
48 page: TableDto,
49 filter: {
50 userId: string
51 title?: string
52 type?: MediaType
53 },
54 ) {
55 const res = await this.mediaGroupRepository.getList(filter, page)
56 return res
57 }
58 }
59
59 lines TYPESCRIPT