| 1 | import { Injectable } from '@nestjs/common' |
| 2 | import { TableDto } from '@yikart/common' |
| 3 | import { MaterialGroupRepository } from '@yikart/mongodb' |
| 4 | import { NewMaterialGroup, UpdateMaterialGroup } from './common' |
| 5 | |
| 6 | @Injectable() |
| 7 | export class MaterialGroupService { |
| 8 | constructor( |
| 9 | private readonly materialGroupRepository: MaterialGroupRepository, |
| 10 | ) { } |
| 11 | |
| 12 | async createGroup(newData: NewMaterialGroup) { |
| 13 | return this.materialGroupRepository.create(newData) |
| 14 | } |
| 15 | |
| 16 | async delGroup(id: string): Promise<boolean> { |
| 17 | return this.materialGroupRepository.delete(id) |
| 18 | } |
| 19 | |
| 20 | async updateGroupInfo(id: string, newData: UpdateMaterialGroup) { |
| 21 | return this.materialGroupRepository.update(id, newData) |
| 22 | } |
| 23 | |
| 24 | async getGroupInfo(id: string) { |
| 25 | return this.materialGroupRepository.getById(id) |
| 26 | } |
| 27 | |
| 28 | async getInfoByName(userId: string, name: string) { |
| 29 | return this.materialGroupRepository.getInfoByName(userId, name) |
| 30 | } |
| 31 | |
| 32 | async getDefaultGroup(userId: string) { |
| 33 | return this.materialGroupRepository.getDefaultGroup(userId) |
| 34 | } |
| 35 | |
| 36 | async ensureDefaultGroup(userId: string) { |
| 37 | return this.materialGroupRepository.createDefault(userId) |
| 38 | } |
| 39 | |
| 40 | async getGroupList( |
| 41 | page: TableDto, |
| 42 | filter: { |
| 43 | userId?: string |
| 44 | title?: string |
| 45 | }, |
| 46 | ) { |
| 47 | return this.materialGroupRepository.getList(filter, page) |
| 48 | } |
| 49 | } |
| 50 |