feat(anotações): permite anexos em notas

This commit is contained in:
Felipe Coutinho
2026-06-21 11:54:05 -03:00
parent 129295d2e2
commit d363662548
17 changed files with 3942 additions and 90 deletions

View File

@@ -847,11 +847,12 @@ export const budgetsRelations = relations(budgets, ({ one }) => ({
}),
}));
export const notesRelations = relations(notes, ({ one }) => ({
export const notesRelations = relations(notes, ({ one, many }) => ({
user: one(user, {
fields: [notes.userId],
references: [user.id],
}),
noteAttachments: many(noteAttachments),
}));
export const savedInsightsRelations = relations(savedInsights, ({ one }) => ({
@@ -972,6 +973,24 @@ export const transactionAttachments = pgTable(
}),
);
export const noteAttachments = pgTable(
"anotacao_anexos",
{
noteId: uuid("anotacao_id")
.notNull()
.references(() => notes.id, { onDelete: "cascade" }),
attachmentId: uuid("anexo_id")
.notNull()
.references(() => attachments.id, { onDelete: "cascade" }),
},
(table) => ({
pk: primaryKey({ columns: [table.noteId, table.attachmentId] }),
attachmentIdIdx: index("anotacao_anexos_anexo_id_idx").on(
table.attachmentId,
),
}),
);
export const importCategoryMappings = pgTable(
"import_category_mappings",
{
@@ -1044,6 +1063,7 @@ export const attachmentsRelations = relations(attachments, ({ one, many }) => ({
references: [user.id],
}),
transactionAttachments: many(transactionAttachments),
noteAttachments: many(noteAttachments),
}));
export const transactionAttachmentsRelations = relations(
@@ -1060,8 +1080,23 @@ export const transactionAttachmentsRelations = relations(
}),
);
export const noteAttachmentsRelations = relations(
noteAttachments,
({ one }) => ({
note: one(notes, {
fields: [noteAttachments.noteId],
references: [notes.id],
}),
attachment: one(attachments, {
fields: [noteAttachments.attachmentId],
references: [attachments.id],
}),
}),
);
export type Attachment = typeof attachments.$inferSelect;
export type TransactionAttachment = typeof transactionAttachments.$inferSelect;
export type NoteAttachment = typeof noteAttachments.$inferSelect;
export const establishmentLogosRelations = relations(
establishmentLogos,