You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.4 KiB

3 years ago
3 years ago
  1. import { plainToInstance } from 'class-transformer'
  2. import { CommentReadDTO, CommentListDTO } from './commentData'
  3. import { CommentRepository, SearchOption } from '~/domain/models/comment/commentRepository'
  4. import { CommentItem } from '~/domain/models/comment/comment'
  5. export class CommentApplicationService {
  6. constructor(
  7. private readonly repository: CommentRepository
  8. ) {}
  9. public async listProjectComment(projectId: string, options: SearchOption): Promise<CommentListDTO> {
  10. const item = await this.repository.listAll(projectId, options)
  11. return new CommentListDTO(item)
  12. }
  13. public async list(projectId: string, docId: number): Promise<CommentReadDTO[]> {
  14. const items = await this.repository.list(projectId, docId)
  15. return items.map(item => new CommentReadDTO(item))
  16. }
  17. public create(projectId: string, docId: number, text: string): Promise<CommentItem> {
  18. return this.repository.create(projectId, docId, text)
  19. }
  20. public update(projectId: string, item: CommentReadDTO): Promise<CommentItem> {
  21. const comment = plainToInstance(CommentItem, item)
  22. return this.repository.update(projectId, comment)
  23. }
  24. public delete(projectId: string, item: CommentReadDTO): Promise<void> {
  25. return this.repository.delete(projectId, item.id)
  26. }
  27. public deleteBulk(projectId: string, items: CommentReadDTO[]): Promise<void> {
  28. const ids = items.map(item => item.id)
  29. return this.repository.deleteBulk(projectId, ids)
  30. }
  31. }