feat: implement payment service with error handling and validation

Add new payment service with repository, error handling, and validation
Add exceptions package with database and validation utilities
Update database package with new schema and zod types
Add turbo start script for development
This commit is contained in:
Yuu Ottosoka
2025-07-11 13:54:55 +03:00
parent 49f0385d00
commit 084b100589
23 changed files with 792 additions and 13 deletions

View File

@@ -0,0 +1,25 @@
import { ResultAsync, err, ok } from 'neverthrow';
import { AppError } from '../types';
/**
* Wraps a database operation in a Result type to handle errors gracefully
* @param operation - The database operation to execute
* @param errorFactory - Function to create a custom error if the operation fails
* @returns Result containing the operation result or error
*/
export const wrapDbOperation = <T, E extends AppError<unknown>>(
operation: () => Promise<T>,
errorFactory: (error: unknown) => E
): ResultAsync<T, E> => {
return ResultAsync.fromPromise(operation(), errorFactory);
};
export const wrapDbOperationWithNull = <T, E extends AppError<unknown>>(
operation: () => Promise<T | null>,
notFoundError: E,
dbErrorFactory: (error: unknown) => E
): ResultAsync<T, E> => {
return ResultAsync.fromPromise(operation(), (error) =>
dbErrorFactory(error)
).andThen((result) => (result === null ? err(notFoundError) : ok(result)));
};