mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-05-09 11:01:45 +00:00
Adiciona splitGroupId para vincular as duas shares de um lançamento dividido (schema + índice + migration 0026). Habilita: - Edição de par dividido com escolha de escopo (apenas este lado ou ambos) via novo SplitPairDialog e updateTransactionSplitPairAction - Filtro "Somente divididos" (isDivided) na tabela de lançamentos - Visibilidade de anexos para pessoas com acesso compartilhado via payerShares; upload e detach em massa expandem para shares irmãs - Cópia independente de anexos no fluxo "Importar para Minha Conta" (novo fileKey, novo userId, S3 CopyObject) com seção read-only "Anexos que serão copiados" no dialog de importação - Ícone de clipe na tabela de lançamentos da página da pessoa via EXISTS em fetchPagadorLancamentos Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import { eq } from "drizzle-orm";
|
|
import { attachments, transactionAttachments, transactions } from "@/db/schema";
|
|
import { db } from "@/shared/lib/db";
|
|
import { getPayerAccess } from "@/shared/lib/payers/access";
|
|
import { createPresignedGetUrl } from "@/shared/lib/storage/presign";
|
|
|
|
export type TransactionAttachmentListItem = {
|
|
attachmentId: string;
|
|
fileName: string;
|
|
fileSize: number;
|
|
mimeType: string;
|
|
createdAt: string;
|
|
url: string;
|
|
};
|
|
|
|
export async function fetchTransactionAttachments(
|
|
userId: string,
|
|
transactionId: string,
|
|
): Promise<TransactionAttachmentListItem[]> {
|
|
const [transaction] = await db
|
|
.select({
|
|
id: transactions.id,
|
|
userId: transactions.userId,
|
|
payerId: transactions.payerId,
|
|
})
|
|
.from(transactions)
|
|
.where(eq(transactions.id, transactionId));
|
|
|
|
if (!transaction) {
|
|
return [];
|
|
}
|
|
|
|
if (transaction.userId !== userId) {
|
|
if (!transaction.payerId) return [];
|
|
const access = await getPayerAccess(userId, transaction.payerId);
|
|
if (!access) return [];
|
|
}
|
|
|
|
const rows = await db
|
|
.select({
|
|
attachmentId: transactionAttachments.attachmentId,
|
|
fileName: attachments.fileName,
|
|
fileSize: attachments.fileSize,
|
|
mimeType: attachments.mimeType,
|
|
fileKey: attachments.fileKey,
|
|
createdAt: attachments.createdAt,
|
|
})
|
|
.from(transactionAttachments)
|
|
.innerJoin(
|
|
attachments,
|
|
eq(transactionAttachments.attachmentId, attachments.id),
|
|
)
|
|
.where(eq(transactionAttachments.transactionId, transactionId));
|
|
|
|
return Promise.all(
|
|
rows.map(async (row) => ({
|
|
attachmentId: row.attachmentId,
|
|
fileName: row.fileName,
|
|
fileSize: row.fileSize,
|
|
mimeType: row.mimeType,
|
|
createdAt: row.createdAt.toISOString(),
|
|
url: await createPresignedGetUrl(row.fileKey),
|
|
})),
|
|
);
|
|
}
|