* feat: rename commentThread into activity server * feat: rename commentThread into activity front * feat: migration only create tables feat: migration only create tables * Update activities * fix: rebase partial fix * fix: all rebase problems and drop activity target alter * fix: lint * Update migration * Update migration * Fix conflicts * Fix conflicts --------- Co-authored-by: Charles Bochet <charles@twenty.com>
80 lines
2.1 KiB
TypeScript
80 lines
2.1 KiB
TypeScript
import { Resolver, ResolveField, Root, Int } from '@nestjs/graphql';
|
|
|
|
import { Comment } from 'src/core/@generated/comment/comment.model';
|
|
import { Company } from 'src/core/@generated/company/company.model';
|
|
import { CommentService } from 'src/core/comment/comment.service';
|
|
import {
|
|
PrismaSelect,
|
|
PrismaSelector,
|
|
} from 'src/decorators/prisma-select.decorator';
|
|
import { ActivityService } from 'src/core/activity/services/activity.service';
|
|
import { Activity } from 'src/core/@generated/activity/activity.model';
|
|
|
|
@Resolver(() => Company)
|
|
export class CompanyRelationsResolver {
|
|
constructor(
|
|
private readonly activityService: ActivityService,
|
|
private readonly commentService: CommentService,
|
|
) {}
|
|
|
|
@ResolveField(() => [Activity], {
|
|
nullable: false,
|
|
})
|
|
async activities(
|
|
@Root() company: Company,
|
|
@PrismaSelector({ modelName: 'Activity' })
|
|
prismaSelect: PrismaSelect<'Activity'>,
|
|
): Promise<Partial<Activity>[]> {
|
|
return this.activityService.findMany({
|
|
where: {
|
|
activityTargets: {
|
|
some: {
|
|
commentableType: 'Company',
|
|
commentableId: company.id,
|
|
},
|
|
},
|
|
},
|
|
select: prismaSelect.value,
|
|
});
|
|
}
|
|
|
|
@ResolveField(() => [Comment], {
|
|
nullable: false,
|
|
})
|
|
async comments(
|
|
@Root() company: Company,
|
|
@PrismaSelector({ modelName: 'Comment' })
|
|
prismaSelect: PrismaSelect<'Comment'>,
|
|
): Promise<Partial<Comment>[]> {
|
|
return this.commentService.findMany({
|
|
where: {
|
|
activity: {
|
|
activityTargets: {
|
|
some: {
|
|
commentableType: 'Company',
|
|
commentableId: company.id,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
select: prismaSelect.value,
|
|
});
|
|
}
|
|
|
|
@ResolveField(() => Int, {
|
|
nullable: false,
|
|
})
|
|
async _activityCount(@Root() company: Company): Promise<number> {
|
|
return this.activityService.count({
|
|
where: {
|
|
activityTargets: {
|
|
some: {
|
|
commentableType: 'Company',
|
|
commentableId: company.id,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
}
|