Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/backend/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "6",
"dialect": "sqlite",
"id": "e239fb7b-54dd-48a9-bad4-fb13d27d0fa1",
"id": "b3626041-a73e-4294-b580-3c53764e0f43",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"accounts": {
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "6",
"when": 1773222725992,
"tag": "0000_overconfident_glorian",
"when": 1776091943739,
"tag": "0000_keen_gertrude_yorkes",
"breakpoints": true
}
]
Expand Down
15 changes: 8 additions & 7 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@
"build": "pnpm clean && tsc",
"start": "node --experimental-specifier-resolution=node dist/index.js",
"migrateOld": "drizzle-kit push --config=drizzle.config.ts",
"migrate": "drizzle-kit migrate --config=drizzle.config.ts",
"db:seed": "tsx src/db/scripts/seed.ts",
"studio": "pnpm drizzle-kit studio",
"db:push": "npx drizzle-kit push",
"db:generate": "npx drizzle-kit generate",
"generateCustom": "drizzle-kit --config=drizzle.config.ts generate --custom --name",
"drop:tables": "tsx src/db/scripts/drop-tables.ts",
"ts-check": "tsc -b --noEmit",
"db:seed": "tsx src/db/scripts/seed.ts",
"db:reseed": "pnpm db:reset && pnpm db:seed",
"db:push": "npx drizzle-kit push",
"db:generate": "npx drizzle-kit generate",
"db:migrate": "drizzle-kit migrate --config=drizzle.config.ts",
"db:delete": "rm -rf ./data/* && mkdir -p ./data",
"db:migrations:delete": "rm -rf ./drizzle",
"db:regenerate": "pnpm db:migrations:delete && pnpm db:generate",
"db:delete:all": "pnpm delete:db && pnpm delete:migrations",
"db:full-reset": "pnpm delete:all && pnpm generate && pnpm migrate",
"db:delete:all": "pnpm db:delete && pnpm db:migrations:delete",
"db:full-reset": "pnpm db:delete:all && pnpm db:generate && pnpm db:migrate",
"testDB": "tsx src/db/test-db.ts",
"seed:currencies": "tsx src/db/scripts/currenciesSeed.ts",
"db:reset": "pnpm delete:db && pnpm migrate",
"db:reset": "pnpm db:delete && pnpm db:migrate",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"check": "pnpm ts-check && pnpm lint:fix",
Expand Down
45 changes: 0 additions & 45 deletions apps/backend/src/application/dto/entry.dto.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/backend/src/application/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './transaction.dto';
export * from './entry.dto';
export * from './operation.dto';
export * from './currency.dto';
export * from './user.dto';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export type OperationRepositoryInterface = {
save(
userId: UUID,
operations: OperationDbRow[],
snapshots: Map<UUID, OperationSnapshot>,
snapshots?: Map<UUID, OperationSnapshot>,
): Promise<void>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { Transaction } from 'src/domain';
import { OperationRepositoryInterface } from './OperationRepository.interface';

export type TransactionRepositoryInterface = {
rootSave(userId: UUID, transaction: Transaction): Promise<void>;
update(userId: UUID, transaction: Transaction): Promise<void>;
create(userId: UUID, transaction: Transaction): Promise<void>;
getById(userId: UUID, transactionId: UUID): Promise<Transaction | null>;
delete(userId: UUID, transactionId: UUID): Promise<void>;
softDelete(userId: UUID, transaction: Transaction): Promise<void>;
readonly operationsRepository: OperationRepositoryInterface;
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export class TransactionViewMapper {
currency: transaction.currency,
description: transaction.description,
id: transaction.id,
operations: transaction.operations.map(this.mapOperation.bind(this)),
operations: transaction.operations
.filter((op) => !op.isTombstone)
.map(this.mapOperation.bind(this)),
postingDate: transaction.postingDate,
transactionDate: transaction.transactionDate,
updatedAt: transaction.updatedAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class CreateTransactionUseCase {
createTransactionProps,
);

await this.transactionRepository.rootSave(
await this.transactionRepository.create(
user.getId().valueOf(),
transaction,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class UpdateTransactionUseCase {
);

if (isUpdated) {
await this.transactionRepository.rootSave(
await this.transactionRepository.update(
user.getId().valueOf(),
transaction,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('CreateTransactionUseCase', () => {
let user: User;

const mockTransactionRepository = {
rootSave: vi.fn(),
create: vi.fn(),
};

const transactionManager = {
Expand Down Expand Up @@ -83,12 +83,12 @@ describe('CreateTransactionUseCase', () => {

expect(transactionManager.run).toHaveBeenCalled();

expect(mockTransactionRepository.rootSave).toHaveBeenCalled();
expect(mockTransactionRepository.create).toHaveBeenCalled();

const savedTransaction = mockTransactionRepository.rootSave.mock
const savedTransaction = mockTransactionRepository.create.mock
.calls[0][1] as unknown as Transaction;

const savedUserId = mockTransactionRepository.rootSave.mock
const savedUserId = mockTransactionRepository.create.mock
.calls[0][0] as unknown as User;

expect(savedUserId).toBe(user.getId().valueOf());
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('CreateTransactionUseCase', () => {

it('should propagate error when rootSave fails', async () => {
const dbError = new Error('Database error');
mockTransactionRepository.rootSave.mockRejectedValue(dbError);
mockTransactionRepository.create.mockRejectedValue(dbError);

const { transactionContext, transactionDTO } = TransactionBuilder.create(
user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,8 @@ describe('UpdateTransactionUseCase', () => {

const mockTransactionRepository = {
getById: vi.fn(),
getDB: vi.fn().mockReturnValue({
transaction: <T>(cb: (trx: unknown) => T): T => cb({}),
}),
rootSave: vi.fn(),
};

const mockEntriesService = {
updateEntriesWithOperations: vi.fn(),
};
update: vi.fn(),
} satisfies Partial<TransactionRepositoryInterface>;

const mockEnsureEntityExistsAndOwned = vi.fn();

Expand Down Expand Up @@ -133,14 +126,10 @@ describe('UpdateTransactionUseCase', () => {
expect(updatedTransaction.postingDate).toBe(data.postingDate);
expect(updatedTransaction.transactionDate).toBe(data.transactionDate);

expect(mockTransactionRepository.rootSave).toHaveBeenCalledWith(
expect(mockTransactionRepository.update).toHaveBeenCalledWith(
user.getId().valueOf(),
transaction,
);

expect(
mockEntriesService.updateEntriesWithOperations,
).not.toHaveBeenCalled();
});

it('should update transaction and its entries correctly', async () => {
Expand Down Expand Up @@ -234,7 +223,7 @@ describe('UpdateTransactionUseCase', () => {
...data.operations.update,
]);

expect(mockTransactionRepository.rootSave).toHaveBeenCalledWith(
expect(mockTransactionRepository.update).toHaveBeenCalledWith(
user.getId().valueOf(),
transaction,
);
Expand Down Expand Up @@ -280,7 +269,7 @@ describe('UpdateTransactionUseCase', () => {
mockTransactionContextLoader.loadContext,
).toHaveBeenCalledExactlyOnceWith(user, []);

expect(mockTransactionRepository.rootSave).not.toHaveBeenCalled();
expect(mockTransactionRepository.update).not.toHaveBeenCalled();

initialTransactionResponse.operations.forEach((opDTO) => {
const updatedOpDTO = updatedTransaction.operations.find(
Expand Down
Loading
Loading