made use of first class citizen objects as json validator functions

This commit is contained in:
2025-01-03 13:32:42 +00:00
parent 2210fe4bb1
commit aac9c8af4f
21 changed files with 122 additions and 92 deletions
@@ -45,9 +45,13 @@ class PrismaUserDataSource implements UserDataSource {
message: 'Failed to find user by email: ${error.toString()}',
),
)
.flatMap(errorOnNull(AppError.notFound(
'User with email $email found',
)))
.flatMap(
errorOnNull(
AppError.notFound(
'User with email $email found',
),
),
)
.flatMap(mapper.from);
}
@@ -63,9 +67,13 @@ class PrismaUserDataSource implements UserDataSource {
message: 'Failed to find user by ID: ${error.toString()}',
),
)
.flatMap(errorOnNull(AppError.notFound(
"User with id $id not found",
)))
.flatMap(
errorOnNull(
AppError.notFound(
"User with id $id not found",
),
),
)
.flatMap(mapper.from);
}
@@ -104,15 +112,24 @@ class PrismaUserDataSource implements UserDataSource {
}
@override
TaskEither<IError, void> delete(String id) {
return TaskEither.tryCatch(
TaskEither<IError, User> delete(String id) {
return TaskEither<IError, UserDbo?>.tryCatch(
() async {
await prisma.userDbo.delete(where: UserDboWhereUniqueInput(id: id));
return await prisma.userDbo
.delete(where: UserDboWhereUniqueInput(id: id));
},
(error, _) => AppError.databaseError(
message: 'Failed to delete user: ${error.toString()}',
),
);
)
.flatMap(
errorOnNull(
AppError.notFound(
'User not found',
),
),
)
.flatMap(mapper.from);
}
@override