Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/740 fix mappings from prisma models to domain objects #775

Merged

Conversation

ognjenkurtic
Copy link
Collaborator

Description

Implement an example of prisma model -> domain object mapping that does not rely on automapper as the automapper pojos strategy is bolierplate heavy and does not solve some edge cases.

New approach uses Object.assign and requires a single method per model - domain object pair.

If this approach looks good, i ll apply it across the codebase in a separate PR.

Related Issue

#740

Motivation and Context

Mapping was not done properly

How Has This Been Tested

Tested locally with postman, trying to fetch BpiSubject by id with associated roles and verified all mappings correctly performed.
Ran all unit tests

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Request to be added as a Code Owner/Maintainer

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I commit to abide by the Responsibilities of Code Owners/Maintainers.

Kasshern
Kasshern previously approved these changes Jan 8, 2024
Copy link
Collaborator

@Kasshern Kasshern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this approach. It reflects the need for some amount of custom work to be done, which I think we should not shy away from at this point in the development process. Left a question.

import { BpiSubjectRole } from '../src/bri/identity/bpiSubjects/models/bpiSubjectRole';
import { IDomainObject } from '../src/shared/domainObject.interface';

// We do mapping from prisma models to domain objects using simple Object.assing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assing should be assign

import { BpiSubjectRole } from './bpiSubjectRole';

export class BpiSubject {
export class BpiSubject implements IDomainObject {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it necessary to have the implemented interface IDomainObject and private activator. Just to ensure a common inherited value of id?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface is not needed at all. I was following an article and thought that it might be a good idea in order to make sure only domain objects are accepted for activation but on second thought i think it is over engineering. Removed.
The activator is necessary to avoid instantiation of each domain object ctor by providing empty params. I was hoping for a fully generic solution (one method for any mapping pair) but couldn't make it work so stopped here for now.

@Kasshern
Copy link
Collaborator

Kasshern commented Jan 8, 2024

@ognjenkurtic please clear conflicts.

@ognjenkurtic ognjenkurtic force-pushed the feature/740-fix-mappings-from-prisma-models-to-domain-objects branch from c3e8ee2 to e0c9037 Compare January 8, 2024 21:15
@ognjenkurtic
Copy link
Collaborator Author

@ognjenkurtic please clear conflicts.

@Kasshern done and addressed all other comments, please rereview

@Kasshern
Copy link
Collaborator

Kasshern commented Jan 8, 2024

@ognjenkurtic e2e test failing

@ognjenkurtic
Copy link
Collaborator Author

e2e step is failing because of this #769

Copy link
Collaborator

@Therecanbeonlyone1969 Therecanbeonlyone1969 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ognjenkurtic
Copy link
Collaborator Author

LGTM

Gimme an approval please @Therecanbeonlyone1969

Copy link
Collaborator

@biscuitdey biscuitdey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach looks good to me.

@ognjenkurtic ognjenkurtic merged commit a184737 into main Jan 10, 2024
1 of 2 checks passed
@ognjenkurtic ognjenkurtic deleted the feature/740-fix-mappings-from-prisma-models-to-domain-objects branch January 10, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants