refactor
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import 'package:backend_dart/common/extensions.dart';
|
||||
import 'package:backend_dart/domain/entities/project.dart';
|
||||
import 'package:backend_dart/domain/errors/error.dart';
|
||||
import 'package:backend_dart/infrastructure/data/db/model.dart';
|
||||
import 'package:backend_dart/infrastructure/data/db/prisma.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:orm/orm.dart';
|
||||
|
||||
class ProjectDboMapper {
|
||||
TaskEither<IError, Project> fromDbo(ProjectDbo dbo) {
|
||||
return TaskEither.of(Project(
|
||||
id: dbo.id!,
|
||||
name: dbo.name!,
|
||||
description: dbo.description,
|
||||
clientId: dbo.clientId,
|
||||
userId: dbo.userId!,
|
||||
createdAt: dbo.createdAt!,
|
||||
updatedAt: dbo.updatedAt!,
|
||||
));
|
||||
}
|
||||
|
||||
TaskEither<IError, List<Project>> listFrom(Iterable<ProjectDbo> dbos) {
|
||||
return TaskEither.traverseList(dbos.toList(), fromDbo);
|
||||
}
|
||||
|
||||
TaskEither<IError, ProjectDboCreateInput> fromCreatetoDbo(
|
||||
ProjectCreate project) {
|
||||
return TaskEither.of(ProjectDboCreateInput(
|
||||
id: project.id,
|
||||
name: project.name,
|
||||
description: project.description.let(PrismaUnion.$1),
|
||||
clientId: project.clientId.let(PrismaUnion.$1),
|
||||
user: UserDboCreateNestedOneWithoutProjectsInput(
|
||||
connect: UserDboWhereUniqueInput(id: project.userId),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
TaskEither<IError, ProjectDboUpdateInput> fromUpdateToDbo(
|
||||
ProjectUpdate project) {
|
||||
return TaskEither.of(ProjectDboUpdateInput(
|
||||
id: PrismaUnion.$1(project.id),
|
||||
name: project.name.let(PrismaUnion.$1),
|
||||
description: project.description.let(PrismaUnion.$1),
|
||||
clientId: project.clientId.let(PrismaUnion.$1),
|
||||
user: project.userId.let(
|
||||
(userId) => UserDboUpdateOneRequiredWithoutProjectsNestedInput(
|
||||
connect: UserDboWhereUniqueInput(id: userId),
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:backend_dart/common/extensions.dart';
|
||||
import 'package:backend_dart/domain/entities/project_task.dart';
|
||||
import 'package:backend_dart/domain/errors/error.dart';
|
||||
import 'package:backend_dart/infrastructure/data/db/model.dart';
|
||||
import 'package:backend_dart/infrastructure/data/db/prisma.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:orm/orm.dart';
|
||||
|
||||
class ProjectTaskDboMapper {
|
||||
TaskEither<IError, ProjectTask> from(ProjectTaskDbo target) =>
|
||||
TaskEither.of(ProjectTask(
|
||||
id: target.id!,
|
||||
name: target.name!,
|
||||
description: target.description,
|
||||
projectId: target.projectId!,
|
||||
createdAt: target.createdAt!,
|
||||
updatedAt: target.updatedAt!,
|
||||
));
|
||||
|
||||
TaskEither<IError, List<ProjectTask>> listFrom(
|
||||
Iterable<ProjectTaskDbo> targets) {
|
||||
return TaskEither.traverseList(targets.toList(), from);
|
||||
}
|
||||
|
||||
TaskEither<IError, ProjectTaskDboCreateInput> fromCreateTo(
|
||||
ProjectTaskCreate origin) =>
|
||||
TaskEither.of(ProjectTaskDboCreateInput(
|
||||
id: origin.id,
|
||||
name: origin.name,
|
||||
description: origin.description.let(PrismaUnion.$1),
|
||||
project: ProjectDboCreateNestedOneWithoutTasksInput(
|
||||
connect: ProjectDboWhereUniqueInput(
|
||||
id: origin.projectId,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
TaskEither<IError, ProjectTaskDboUpdateInput> fromUpdateTo(
|
||||
ProjectTaskUpdate origin) =>
|
||||
TaskEither.of(ProjectTaskDboUpdateInput(
|
||||
id: PrismaUnion.$1(origin.id),
|
||||
name: origin.name?.let(PrismaUnion.$1),
|
||||
description: origin.description?.let(PrismaUnion.$1),
|
||||
project: origin.projectId?.let(
|
||||
(projectId) => ProjectDboUpdateOneRequiredWithoutTasksNestedInput(
|
||||
connect: ProjectDboWhereUniqueInput(
|
||||
id: projectId,
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import 'package:backend_dart/common/extensions.dart';
|
||||
import 'package:backend_dart/domain/entities/time_entry.dart';
|
||||
import 'package:backend_dart/domain/errors/error.dart';
|
||||
import 'package:backend_dart/infrastructure/data/db/model.dart';
|
||||
import 'package:backend_dart/infrastructure/data/db/prisma.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:orm/orm.dart';
|
||||
|
||||
class TimeEntryDboMapper {
|
||||
TaskEither<IError, TimeEntry> from(TimeEntryDbo target) => TaskEither.of(
|
||||
TimeEntry(
|
||||
id: target.id!,
|
||||
startTime: target.startTime!,
|
||||
endTime: target.endTime,
|
||||
description: target.description,
|
||||
userId: target.userId!,
|
||||
projectId: target.projectId!,
|
||||
createdAt: target.createdAt!,
|
||||
updatedAt: target.updatedAt!,
|
||||
),
|
||||
);
|
||||
|
||||
TaskEither<IError, List<TimeEntry>> listFrom(Iterable<TimeEntryDbo> targets) {
|
||||
return TaskEither.traverseList(targets.toList(), from);
|
||||
}
|
||||
|
||||
TaskEither<IError, TimeEntryDboCreateInput> fromCreateTo(
|
||||
TimeEntryCreate origin) =>
|
||||
TaskEither.of(TimeEntryDboCreateInput(
|
||||
id: origin.id,
|
||||
startTime: origin.startTime,
|
||||
endTime: origin.endTime.let(PrismaUnion.$1),
|
||||
description: origin.description.let(PrismaUnion.$1),
|
||||
user: UserDboCreateNestedOneWithoutTimeEntriesInput(
|
||||
connect: UserDboWhereUniqueInput(
|
||||
id: origin.userId,
|
||||
),
|
||||
),
|
||||
project: ProjectDboCreateNestedOneWithoutTimeEntriesInput(
|
||||
connect: ProjectDboWhereUniqueInput(
|
||||
id: origin.projectId,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
TaskEither<IError, TimeEntryDboUpdateInput> fromUpdateTo(
|
||||
TimeEntryUpdate origin) =>
|
||||
TaskEither.of(TimeEntryDboUpdateInput(
|
||||
id: PrismaUnion.$1(origin.id),
|
||||
startTime: origin.startTime?.let(PrismaUnion.$1),
|
||||
endTime: origin.endTime?.let(PrismaUnion.$1),
|
||||
description: origin.description?.let(PrismaUnion.$1),
|
||||
user: origin.userId?.let(
|
||||
(userId) => UserDboUpdateOneRequiredWithoutTimeEntriesNestedInput(
|
||||
connect: UserDboWhereUniqueInput(
|
||||
id: userId,
|
||||
),
|
||||
),
|
||||
),
|
||||
project: origin.projectId?.let(
|
||||
(projectId) =>
|
||||
ProjectDboUpdateOneRequiredWithoutTimeEntriesNestedInput(
|
||||
connect: ProjectDboWhereUniqueInput(
|
||||
id: projectId,
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:backend_dart/common/extensions.dart';
|
||||
import 'package:backend_dart/common/secure_hash.dart';
|
||||
import 'package:backend_dart/domain/entities/user.dart';
|
||||
import 'package:backend_dart/domain/errors/error.dart';
|
||||
import 'package:backend_dart/infrastructure/data/db/model.dart';
|
||||
import 'package:backend_dart/infrastructure/data/db/prisma.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:orm/orm.dart';
|
||||
|
||||
class UserDboMapper {
|
||||
TaskEither<IError, User> from(UserDbo target) => TaskEither.of(User(
|
||||
id: target.id!,
|
||||
name: target.name!,
|
||||
email: target.email!,
|
||||
passwordHash: target.password,
|
||||
createdAt: target.createdAt,
|
||||
updatedAt: target.updatedAt,
|
||||
));
|
||||
|
||||
TaskEither<IError, List<User>> listFrom(Iterable<UserDbo> targets) {
|
||||
return TaskEither.traverseList(targets.toList(), from);
|
||||
}
|
||||
|
||||
TaskEither<IError, UserDboUpdateInput> fromUpdateTo(UserUpdate origin) =>
|
||||
TaskEither.of(UserDboUpdateInput(
|
||||
id: PrismaUnion.$1(origin.id),
|
||||
name: origin.name.let(PrismaUnion.$1),
|
||||
email: origin.email.let(PrismaUnion.$1),
|
||||
password: origin.password.let(generateSecureHash).let(PrismaUnion.$1),
|
||||
));
|
||||
|
||||
TaskEither<IError, UserDboCreateInput> fromCreateTo(UserCreate origin) =>
|
||||
TaskEither.of(UserDboCreateInput(
|
||||
id: origin.id,
|
||||
name: origin.name,
|
||||
email: origin.email,
|
||||
password: generateSecureHash(origin.password),
|
||||
));
|
||||
}
|
||||
Reference in New Issue
Block a user