* feat: Activity log for uploading attachments (closes #354) * chore: fix coding style * revert: upload spinning icon patch * refactor: add fallbacks, extended card_activity
This commit is contained in:
@@ -142,9 +142,18 @@ export const attachmentRouter = createTRPCRouter({
|
||||
createdBy: userId,
|
||||
});
|
||||
|
||||
if (!attachment) {
|
||||
throw new TRPCError({
|
||||
message: "Failed to create attachment",
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
});
|
||||
}
|
||||
|
||||
await cardActivityRepo.create(ctx.db, {
|
||||
type: "card.updated.attachment.added",
|
||||
cardId: card.id,
|
||||
attachmentId: attachment.id,
|
||||
toTitle: input.originalFilename,
|
||||
createdBy: userId,
|
||||
});
|
||||
|
||||
@@ -206,6 +215,8 @@ export const attachmentRouter = createTRPCRouter({
|
||||
await cardActivityRepo.create(ctx.db, {
|
||||
type: "card.updated.attachment.removed",
|
||||
cardId: attachment.cardId,
|
||||
attachmentId: attachment.id,
|
||||
fromTitle: attachment.originalFilename,
|
||||
createdBy: userId,
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
ALTER TABLE "card_activity" ADD COLUMN "attachmentId" bigint;--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "card_activity" ADD CONSTRAINT "card_activity_attachmentId_card_attachment_id_fk" FOREIGN KEY ("attachmentId") REFERENCES "public"."card_attachment"("id") ON DELETE cascade ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
3430
packages/db/migrations/meta/20260208033314_snapshot.json
Normal file
3430
packages/db/migrations/meta/20260208033314_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -183,6 +183,13 @@
|
||||
"when": 1770500457005,
|
||||
"tag": "20260207214056_AddNotificationsTable",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 26,
|
||||
"version": "7",
|
||||
"when": 1770521594167,
|
||||
"tag": "20260208033314_AddAttachmentToActivity",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -33,6 +33,7 @@ export const create = async (
|
||||
fromDueDate?: Date;
|
||||
toDueDate?: Date;
|
||||
sourceBoardId?: number;
|
||||
attachmentId?: number;
|
||||
},
|
||||
) => {
|
||||
const [result] = await db
|
||||
@@ -58,6 +59,7 @@ export const create = async (
|
||||
fromDueDate: activityInput.fromDueDate,
|
||||
toDueDate: activityInput.toDueDate,
|
||||
sourceBoardId: activityInput.sourceBoardId,
|
||||
attachmentId: activityInput.attachmentId,
|
||||
})
|
||||
.returning({ id: cardActivities.id });
|
||||
|
||||
@@ -83,6 +85,7 @@ export const bulkCreate = async (
|
||||
fromDueDate?: Date;
|
||||
toDueDate?: Date;
|
||||
sourceBoardId?: number;
|
||||
attachmentId?: number;
|
||||
}[],
|
||||
) => {
|
||||
const activitiesWithPublicIds = activityInputs.map((activity) => ({
|
||||
@@ -191,6 +194,13 @@ export const getPaginatedActivities = async (
|
||||
deletedAt: true,
|
||||
},
|
||||
},
|
||||
attachment: {
|
||||
columns: {
|
||||
publicId: true,
|
||||
filename: true,
|
||||
originalFilename: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: asc(cardActivities.createdAt), // required for merging and pagination
|
||||
limit: limit + 1, // fetch one extra to check if there are more
|
||||
|
||||
@@ -147,6 +147,10 @@ export const cardActivities = pgTable("card_activity", {
|
||||
() => boards.id,
|
||||
{ onDelete: "set null" },
|
||||
),
|
||||
attachmentId: bigint("attachmentId", { mode: "number" }).references(
|
||||
() => cardAttachments.id,
|
||||
{ onDelete: "cascade" },
|
||||
),
|
||||
}).enableRLS();
|
||||
|
||||
export const cardActivitiesRelations = relations(cardActivities, ({ one }) => ({
|
||||
@@ -190,6 +194,11 @@ export const cardActivitiesRelations = relations(cardActivities, ({ one }) => ({
|
||||
references: [comments.id],
|
||||
relationName: "cardActivitiesComment",
|
||||
}),
|
||||
attachment: one(cardAttachments, {
|
||||
fields: [cardActivities.attachmentId],
|
||||
references: [cardAttachments.id],
|
||||
relationName: "cardActivitiesAttachment",
|
||||
}),
|
||||
}));
|
||||
|
||||
export const cardsToLabels = pgTable(
|
||||
|
||||
Reference in New Issue
Block a user