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

@ -132,7 +132,6 @@ export type CommentScalarWhereInput = {
export type CommentThread = {
__typename?: 'CommentThread';
_count: CommentThreadCount;
commentThreadTargets?: Maybe<Array<CommentThreadTarget>>;
comments?: Maybe<Array<Comment>>;
createdAt: Scalars['DateTime'];
@ -141,12 +140,6 @@ export type CommentThread = {
updatedAt: Scalars['DateTime'];
};
export type CommentThreadCount = {
__typename?: 'CommentThreadCount';
commentThreadTargets: Scalars['Int'];
comments: Scalars['Int'];
};
export type CommentThreadCreateInput = {
commentThreadTargets?: InputMaybe<CommentThreadTargetCreateNestedManyWithoutCommentThreadInput>;
comments?: InputMaybe<CommentCreateNestedManyWithoutCommentThreadInput>;
@ -417,11 +410,12 @@ export enum CommentableType {
export type Company = {
__typename?: 'Company';
_count: CompanyCount;
_commentsCount: Scalars['Int'];
accountOwner?: Maybe<User>;
accountOwnerId?: Maybe<Scalars['String']>;
address: Scalars['String'];
commentThreads: Array<CommentThread>;
comments: Array<Comment>;
createdAt: Scalars['DateTime'];
deletedAt?: Maybe<Scalars['DateTime']>;
domainName: Scalars['String'];
@ -432,11 +426,6 @@ export type Company = {
updatedAt: Scalars['DateTime'];
};
export type CompanyCount = {
__typename?: 'CompanyCount';
people: Scalars['Int'];
};
export type CompanyCreateInput = {
accountOwner?: InputMaybe<UserCreateNestedOneWithoutCompaniesInput>;
address: Scalars['String'];
@ -785,8 +774,10 @@ export type NullableStringFieldUpdateOperationsInput = {
export type Person = {
__typename?: 'Person';
_commentCount: Scalars['Int'];
city: Scalars['String'];
commentThreads: Array<CommentThread>;
comments: Array<Comment>;
company?: Maybe<Company>;
companyId?: Maybe<Scalars['String']>;
createdAt: Scalars['DateTime'];
@ -997,7 +988,6 @@ export type PersonWhereUniqueInput = {
export type Pipeline = {
__typename?: 'Pipeline';
_count: PipelineCount;
createdAt: Scalars['DateTime'];
deletedAt?: Maybe<Scalars['DateTime']>;
icon: Scalars['String'];
@ -1027,15 +1017,8 @@ export type PipelineAssociation = {
updatedAt: Scalars['DateTime'];
};
export type PipelineCount = {
__typename?: 'PipelineCount';
pipelineAssociations: Scalars['Int'];
pipelineStages: Scalars['Int'];
};
export type PipelineStage = {
__typename?: 'PipelineStage';
_count: PipelineStageCount;
color: Scalars['String'];
createdAt: Scalars['DateTime'];
deletedAt?: Maybe<Scalars['DateTime']>;
@ -1048,11 +1031,6 @@ export type PipelineStage = {
updatedAt: Scalars['DateTime'];
};
export type PipelineStageCount = {
__typename?: 'PipelineStageCount';
pipelineAssociations: Scalars['Int'];
};
export type Query = {
__typename?: 'Query';
findManyCompany: Array<Company>;
@ -1136,7 +1114,6 @@ export type StringNullableFilter = {
export type User = {
__typename?: 'User';
_count: UserCount;
avatarUrl?: Maybe<Scalars['String']>;
comments?: Maybe<Array<Comment>>;
companies?: Maybe<Array<Company>>;
@ -1166,13 +1143,6 @@ export type UserCompaniesArgs = {
where?: InputMaybe<CompanyWhereInput>;
};
export type UserCount = {
__typename?: 'UserCount';
comments: Scalars['Int'];
companies: Scalars['Int'];
refreshTokens: Scalars['Int'];
};
export type UserCreateNestedOneWithoutCommentsInput = {
connect?: InputMaybe<UserWhereUniqueInput>;
};
@ -1309,7 +1279,6 @@ export type UserWhereUniqueInput = {
export type Workspace = {
__typename?: 'Workspace';
_count: WorkspaceCount;
commentThreads?: Maybe<Array<CommentThread>>;
comments?: Maybe<Array<Comment>>;
companies?: Maybe<Array<Company>>;
@ -1326,17 +1295,6 @@ export type Workspace = {
workspaceMember?: Maybe<Array<WorkspaceMember>>;
};
export type WorkspaceCount = {
__typename?: 'WorkspaceCount';
commentThreads: Scalars['Int'];
comments: Scalars['Int'];
companies: Scalars['Int'];
people: Scalars['Int'];
pipelineStages: Scalars['Int'];
pipelines: Scalars['Int'];
workspaceMember: Scalars['Int'];
};
export type WorkspaceMember = {
__typename?: 'WorkspaceMember';
createdAt: Scalars['DateTime'];

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',
},
},
},
},
});
}
}

View File

@ -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[]