diff --git a/front/src/generated/graphql.tsx b/front/src/generated/graphql.tsx index cd5e4087f..c5dae4f7d 100644 --- a/front/src/generated/graphql.tsx +++ b/front/src/generated/graphql.tsx @@ -447,14 +447,18 @@ export type Analytics = { export type Attachment = { __typename?: 'Attachment'; - activity: Activity; - activityId: Scalars['String']; + activity?: Maybe; + activityId?: Maybe; author: User; authorId: Scalars['String']; + company?: Maybe; + companyId?: Maybe; createdAt: Scalars['DateTime']; fullPath: Scalars['String']; id: Scalars['ID']; name: Scalars['String']; + person?: Maybe; + personId?: Maybe; type: AttachmentType; updatedAt: Scalars['DateTime']; workspace: Workspace; @@ -466,6 +470,14 @@ export type AttachmentCreateNestedManyWithoutActivityInput = { connect?: InputMaybe>; }; +export type AttachmentCreateNestedManyWithoutCompanyInput = { + connect?: InputMaybe>; +}; + +export type AttachmentCreateNestedManyWithoutPersonInput = { + connect?: InputMaybe>; +}; + export type AttachmentListRelationFilter = { every?: InputMaybe; none?: InputMaybe; @@ -498,6 +510,18 @@ export type AttachmentUpdateManyWithoutAuthorNestedInput = { set?: InputMaybe>; }; +export type AttachmentUpdateManyWithoutCompanyNestedInput = { + connect?: InputMaybe>; + disconnect?: InputMaybe>; + set?: InputMaybe>; +}; + +export type AttachmentUpdateManyWithoutPersonNestedInput = { + connect?: InputMaybe>; + disconnect?: InputMaybe>; + set?: InputMaybe>; +}; + export type AttachmentUpdateManyWithoutWorkspaceMemberAuthorNestedInput = { connect?: InputMaybe>; disconnect?: InputMaybe>; @@ -515,13 +539,15 @@ export type AttachmentWhereInput = { NOT?: InputMaybe>; OR?: InputMaybe>; activity?: InputMaybe; - activityId?: InputMaybe; + activityId?: InputMaybe; author?: InputMaybe; authorId?: InputMaybe; + companyId?: InputMaybe; createdAt?: InputMaybe; fullPath?: InputMaybe; id?: InputMaybe; name?: InputMaybe; + personId?: InputMaybe; type?: InputMaybe; updatedAt?: InputMaybe; workspaceMemberAuthor?: InputMaybe; @@ -665,6 +691,7 @@ export type CommentWhereUniqueInput = { export type Company = { __typename?: 'Company'; ActivityTarget?: Maybe>; + Attachment?: Maybe>; Favorite?: Maybe>; PipelineProgress?: Maybe>; _activityCount: Scalars['Int']; @@ -690,6 +717,7 @@ export type Company = { export type CompanyCreateInput = { ActivityTarget?: InputMaybe; + Attachment?: InputMaybe; Favorite?: InputMaybe; PipelineProgress?: InputMaybe; accountOwner?: InputMaybe; @@ -748,6 +776,7 @@ export type CompanyOrderByRelationAggregateInput = { export type CompanyOrderByWithRelationInput = { ActivityTarget?: InputMaybe; + Attachment?: InputMaybe; Favorite?: InputMaybe; PipelineProgress?: InputMaybe; accountOwner?: InputMaybe; @@ -793,6 +822,7 @@ export enum CompanyScalarFieldEnum { export type CompanyUpdateInput = { ActivityTarget?: InputMaybe; + Attachment?: InputMaybe; Favorite?: InputMaybe; PipelineProgress?: InputMaybe; accountOwner?: InputMaybe; @@ -842,6 +872,7 @@ export type CompanyUpdateOneWithoutPipelineProgressNestedInput = { export type CompanyWhereInput = { AND?: InputMaybe>; ActivityTarget?: InputMaybe; + Attachment?: InputMaybe; Favorite?: InputMaybe; NOT?: InputMaybe>; OR?: InputMaybe>; @@ -1375,7 +1406,9 @@ export type MutationUpdateWorkspaceArgs = { export type MutationUploadAttachmentArgs = { activityId: Scalars['String']; + companyId: Scalars['String']; file: Scalars['Upload']; + personId: Scalars['String']; }; @@ -1555,6 +1588,7 @@ export type PaginatedUniversalEntity = { export type Person = { __typename?: 'Person'; ActivityTarget?: Maybe>; + Attachment?: Maybe>; Favorite?: Maybe>; PipelineProgress?: Maybe>; _activityCount: Scalars['Int']; @@ -1580,6 +1614,7 @@ export type Person = { export type PersonCreateInput = { ActivityTarget?: InputMaybe; + Attachment?: InputMaybe; Favorite?: InputMaybe; PipelineProgress?: InputMaybe; avatarUrl?: InputMaybe; @@ -1642,6 +1677,7 @@ export type PersonOrderByRelationAggregateInput = { export type PersonOrderByWithRelationInput = { ActivityTarget?: InputMaybe; + Attachment?: InputMaybe; Favorite?: InputMaybe; PipelineProgress?: InputMaybe; avatarUrl?: InputMaybe; @@ -1686,6 +1722,7 @@ export enum PersonScalarFieldEnum { export type PersonUpdateInput = { ActivityTarget?: InputMaybe; + Attachment?: InputMaybe; Favorite?: InputMaybe; PipelineProgress?: InputMaybe; avatarUrl?: InputMaybe; @@ -1729,6 +1766,7 @@ export type PersonUpdateOneWithoutPipelineProgressNestedInput = { export type PersonWhereInput = { AND?: InputMaybe>; ActivityTarget?: InputMaybe; + Attachment?: InputMaybe; Favorite?: InputMaybe; NOT?: InputMaybe>; OR?: InputMaybe>; @@ -3306,6 +3344,8 @@ export type UpdateActivityMutation = { __typename?: 'Mutation', updateOneActivit export type UploadAttachmentMutationVariables = Exact<{ file: Scalars['Upload']; activityId: Scalars['String']; + companyId: Scalars['String']; + personId: Scalars['String']; }>; @@ -4424,8 +4464,13 @@ export type UpdateActivityMutationHookResult = ReturnType; export type UpdateActivityMutationOptions = Apollo.BaseMutationOptions; export const UploadAttachmentDocument = gql` - mutation UploadAttachment($file: Upload!, $activityId: String!) { - uploadAttachment(file: $file, activityId: $activityId) + mutation UploadAttachment($file: Upload!, $activityId: String!, $companyId: String!, $personId: String!) { + uploadAttachment( + file: $file + activityId: $activityId + companyId: $companyId + personId: $personId + ) } `; export type UploadAttachmentMutationFn = Apollo.MutationFunction; @@ -4445,6 +4490,8 @@ export type UploadAttachmentMutationFn = Apollo.MutationFunction GraphQLUpload }) { createReadStream, filename, mimetype }: FileUpload, + @Args('activityId') activityId?: string, + @Args('companyId') companyId?: string, + @Args('personId') personId?: string, ): Promise { const stream = createReadStream(); const buffer = await streamToBuffer(stream); @@ -53,7 +55,9 @@ export class AttachmentResolver { fullPath: path, type: this.attachmentService.getFileTypeFromFileName(filename), name: filename, - activityId: activityId, + activityId, + companyId, + personId, authorId: user.id, workspaceId: workspace.id, }, diff --git a/server/src/database/migrations/20230925153619_add_company_and_person_to_attachment/migration.sql b/server/src/database/migrations/20230925153619_add_company_and_person_to_attachment/migration.sql new file mode 100644 index 000000000..12f941b0d --- /dev/null +++ b/server/src/database/migrations/20230925153619_add_company_and_person_to_attachment/migration.sql @@ -0,0 +1,10 @@ +-- AlterTable +ALTER TABLE "attachments" ADD COLUMN "companyId" TEXT, +ADD COLUMN "personId" TEXT, +ALTER COLUMN "activityId" DROP NOT NULL; + +-- AddForeignKey +ALTER TABLE "attachments" ADD CONSTRAINT "attachments_personId_fkey" FOREIGN KEY ("personId") REFERENCES "people"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "attachments" ADD CONSTRAINT "attachments_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/server/src/database/schema.prisma b/server/src/database/schema.prisma index d5d8058a1..932a4886b 100644 --- a/server/src/database/schema.prisma +++ b/server/src/database/schema.prisma @@ -270,6 +270,7 @@ model Company { ActivityTarget ActivityTarget[] PipelineProgress PipelineProgress[] Favorite Favorite[] + Attachment Attachment[] @@map("companies") } @@ -322,6 +323,7 @@ model Person { ActivityTarget ActivityTarget[] PipelineProgress PipelineProgress[] Favorite Favorite[] + Attachment Attachment[] @@map("people") } @@ -580,8 +582,15 @@ model Attachment { workspaceMemberAuthor WorkspaceMember? @relation(fields: [workspaceMemberAuthorId], references: [id], name: "authoredAttachments", onDelete: Cascade) workspaceMemberAuthorId String? - activity Activity @relation(fields: [activityId], references: [id], onDelete: Cascade) - activityId String + activity Activity? @relation(fields: [activityId], references: [id], onDelete: Cascade) + activityId String? + + /// @TypeGraphQL.omit(input: true, output: false) + person Person? @relation(fields: [personId], references: [id], onDelete: Cascade) + personId String? + /// @TypeGraphQL.omit(input: true, output: false) + company Company? @relation(fields: [companyId], references: [id], onDelete: Cascade) + companyId String? /// @TypeGraphQL.omit(input: true, output: false) workspace Workspace @relation(fields: [workspaceId], references: [id])