mirror of https://github.com/doccano/doccano.git
pythonannotation-tooldatasetsactive-learningtext-annotationdatasetnatural-language-processingdata-labelingmachine-learning
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.
47 lines
1.5 KiB
47 lines
1.5 KiB
import { plainToInstance } from 'class-transformer'
|
|
import { MemberDTO } from './memberData'
|
|
import { MemberRepository } from '~/domain/models/member/memberRepository'
|
|
import { MemberItem } from '~/domain/models/member/member'
|
|
|
|
export class MemberApplicationService {
|
|
constructor(
|
|
private readonly repository: MemberRepository
|
|
) {}
|
|
|
|
public async list(id: string): Promise<MemberDTO[]> {
|
|
try {
|
|
const items = await this.repository.list(id)
|
|
return items.map(item => new MemberDTO(item))
|
|
} catch(e: any) {
|
|
throw new Error(e.response.data.detail)
|
|
}
|
|
}
|
|
|
|
public async create(projectId: string, item: MemberDTO): Promise<void> {
|
|
try {
|
|
const member = plainToInstance(MemberItem, item)
|
|
await this.repository.create(projectId, member)
|
|
} catch(e: any) {
|
|
throw new Error(e.response.data.detail)
|
|
}
|
|
}
|
|
|
|
public async update(projectId: string, item: MemberDTO): Promise<void> {
|
|
try {
|
|
const member = plainToInstance(MemberItem, item)
|
|
await this.repository.update(projectId, member)
|
|
} catch(e: any) {
|
|
throw new Error(e.response.data.detail)
|
|
}
|
|
}
|
|
|
|
public bulkDelete(projectId: string, items: MemberDTO[]): Promise<void> {
|
|
const ids = items.map(item => item.id)
|
|
return this.repository.bulkDelete(projectId, ids)
|
|
}
|
|
|
|
public async isProjectAdmin(projectId: string, userId: number): Promise<boolean> {
|
|
const items = await this.repository.list(projectId)
|
|
return items.some((item) => item.user === userId && item.isProjectAdmin)
|
|
}
|
|
}
|