Implement comment count on person and company (#183)

This commit is contained in:
Charles Bochet
2023-06-02 12:35:20 +02:00
committed by GitHub
parent 2395f791c8
commit 0609994477
10 changed files with 92 additions and 53 deletions

View File

@ -33,6 +33,6 @@ export class CommentThread {
@HideField()
workspace?: Workspace;
@Field(() => CommentThreadCount, { nullable: false })
@HideField()
_count?: CommentThreadCount;
}

View File

@ -49,6 +49,6 @@ export class Company {
@HideField()
workspace?: Workspace;
@Field(() => CompanyCount, { nullable: false })
@HideField()
_count?: CompanyCount;
}

View File

@ -45,6 +45,6 @@ export class PipelineStage {
@HideField()
workspace?: Workspace;
@Field(() => PipelineStageCount, { nullable: false })
@HideField()
_count?: PipelineStageCount;
}

View File

@ -39,6 +39,6 @@ export class Pipeline {
@HideField()
workspace?: Workspace;
@Field(() => PipelineCount, { nullable: false })
@HideField()
_count?: PipelineCount;
}

View File

@ -65,6 +65,6 @@ export class User {
@Field(() => [Comment], { nullable: true })
comments?: Array<Comment>;
@Field(() => UserCount, { nullable: false })
@HideField()
_count?: UserCount;
}

View File

@ -9,6 +9,7 @@ import { Comment } from '../comment/comment.model';
import { Pipeline } from '../pipeline/pipeline.model';
import { PipelineStage } from '../pipeline-stage/pipeline-stage.model';
import { WorkspaceCount } from './workspace-count.output';
import { HideField } from '@nestjs/graphql';
@ObjectType({})
export class Workspace {
@ -54,6 +55,6 @@ export class Workspace {
@Field(() => [PipelineStage], { nullable: true })
pipelineStages?: Array<PipelineStage>;
@Field(() => WorkspaceCount, { nullable: false })
@HideField()
_count?: WorkspaceCount;
}

View File

@ -1,5 +1,6 @@
import * as TypeGraphQL from '@nestjs/graphql';
import { CommentThread } from 'src/api/@generated/comment-thread/comment-thread.model';
import { Comment } from 'src/api/@generated/comment/comment.model';
import { Company } from 'src/api/@generated/company/company.model';
import { User } from 'src/api/@generated/user/user.model';
import { PrismaService } from 'src/database/prisma.service';
@ -40,4 +41,40 @@ export class CompanyRelationsResolver {
},
});
}
@TypeGraphQL.ResolveField(() => [Comment], {
nullable: false,
})
async comments(@TypeGraphQL.Root() company: Company): Promise<Comment[]> {
return this.prismaService.comment.findMany({
where: {
commentThread: {
commentThreadTargets: {
some: {
commentableId: company.id,
commentableType: 'Company',
},
},
},
},
});
}
@TypeGraphQL.ResolveField(() => TypeGraphQL.Int, {
nullable: false,
})
async _commentsCount(@TypeGraphQL.Root() company: Company): Promise<number> {
return this.prismaService.comment.count({
where: {
commentThread: {
commentThreadTargets: {
some: {
commentableId: company.id,
commentableType: 'Company',
},
},
},
},
});
}
}

View File

@ -1,5 +1,6 @@
import * as TypeGraphQL from '@nestjs/graphql';
import { CommentThread } from 'src/api/@generated/comment-thread/comment-thread.model';
import { Comment } from 'src/api/@generated/comment/comment.model';
import { Company } from 'src/api/@generated/company/company.model';
import { Person } from 'src/api/@generated/person/person.model';
import { PrismaService } from 'src/database/prisma.service';
@ -38,4 +39,40 @@ export class PersonRelationsResolver {
},
});
}
@TypeGraphQL.ResolveField(() => [Comment], {
nullable: false,
})
async comments(@TypeGraphQL.Root() person: Person): Promise<Comment[]> {
return this.prismaService.comment.findMany({
where: {
commentThread: {
commentThreadTargets: {
some: {
commentableId: person.id,
commentableType: 'Person',
},
},
},
},
});
}
@TypeGraphQL.ResolveField(() => TypeGraphQL.Int, {
nullable: false,
})
async _commentCount(@TypeGraphQL.Root() person: Person): Promise<number> {
return this.prismaService.comment.count({
where: {
commentThread: {
commentThreadTargets: {
some: {
commentableId: person.id,
commentableType: 'Person',
},
},
},
},
});
}
}