Chore(backend): Enable attaching attachments to companies and people (backend) (#1726)

Enable attaching attachments to companies and people (backend)

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
This commit is contained in:
gitstart-twenty
2023-09-26 10:39:13 +01:00
committed by GitHub
parent ba86be2c5b
commit f60c209e39
5 changed files with 91 additions and 11 deletions

View File

@ -33,9 +33,11 @@ export class AttachmentResolver {
async uploadAttachment(
@AuthUser() user: User,
@AuthWorkspace() workspace: Workspace,
@Args('activityId') activityId: string,
@Args({ name: 'file', type: () => GraphQLUpload })
{ createReadStream, filename, mimetype }: FileUpload,
@Args('activityId') activityId?: string,
@Args('companyId') companyId?: string,
@Args('personId') personId?: string,
): Promise<string> {
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,
},

View File

@ -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;

View File

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