Implement comment count on person and company (#183)
This commit is contained in:
@ -33,6 +33,6 @@ export class CommentThread {
|
||||
@HideField()
|
||||
workspace?: Workspace;
|
||||
|
||||
@Field(() => CommentThreadCount, { nullable: false })
|
||||
@HideField()
|
||||
_count?: CommentThreadCount;
|
||||
}
|
||||
|
||||
@ -49,6 +49,6 @@ export class Company {
|
||||
@HideField()
|
||||
workspace?: Workspace;
|
||||
|
||||
@Field(() => CompanyCount, { nullable: false })
|
||||
@HideField()
|
||||
_count?: CompanyCount;
|
||||
}
|
||||
|
||||
@ -45,6 +45,6 @@ export class PipelineStage {
|
||||
@HideField()
|
||||
workspace?: Workspace;
|
||||
|
||||
@Field(() => PipelineStageCount, { nullable: false })
|
||||
@HideField()
|
||||
_count?: PipelineStageCount;
|
||||
}
|
||||
|
||||
@ -39,6 +39,6 @@ export class Pipeline {
|
||||
@HideField()
|
||||
workspace?: Workspace;
|
||||
|
||||
@Field(() => PipelineCount, { nullable: false })
|
||||
@HideField()
|
||||
_count?: PipelineCount;
|
||||
}
|
||||
|
||||
@ -65,6 +65,6 @@ export class User {
|
||||
@Field(() => [Comment], { nullable: true })
|
||||
comments?: Array<Comment>;
|
||||
|
||||
@Field(() => UserCount, { nullable: false })
|
||||
@HideField()
|
||||
_count?: UserCount;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -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',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,12 @@ generator nestgraphql {
|
||||
decorate_4_name = "HideField"
|
||||
decorate_4_from = "@nestjs/graphql"
|
||||
decorate_4_arguments = "[]"
|
||||
|
||||
decorate_5_type = "!(*Aggregate*|*GroupBy*|*OrderBy*)"
|
||||
decorate_5_field = "_count"
|
||||
decorate_5_name = "HideField"
|
||||
decorate_5_from = "@nestjs/graphql"
|
||||
decorate_5_arguments = "[]"
|
||||
}
|
||||
|
||||
model User {
|
||||
@ -153,7 +159,7 @@ model RefreshToken {
|
||||
|
||||
model CommentThread {
|
||||
id String @id
|
||||
createdAt DateTime @default(now())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
deletedAt DateTime?
|
||||
commentThreadTargets CommentThreadTarget[]
|
||||
|
||||
Reference in New Issue
Block a user