We know that in the development of clean architecture, we should not have coupling between entities, even if one depends on the other. Here is an example using two entities, users and files, and how we can create a type that creates a union between them so that this type can be used by ORMs.
First, let's create the entities.
Now we will create the type to join the entities.
Let's choose Prisma as the ORM to implement our database contract.
Our implementation is complete.
Properties
Property
Scope
Description
id
public
Unique identifier for the entity.
status
public
Status of the entity. 1 = enable, 0 = disable.
expired
public
Expired status of the entity. true = expired, false = not expired.
deleted
public
Deleted status of the entity. true = deleted, false = not deleted.
createdAt
public
Date when the entity was created.
updatedAt
public
Date when the entity was updated.
expiredAt
public
Date when the entity was expired.
deletedAt
public
Date when the entity was deleted.
Methods
Method
Scope
Description
getnow
private
Get current date.
enable
public
Set status to enable, 1 = enable.
disable
public
Set status to disable, 0 = disable.
expire
public
Set expired to true and set expiredAt to current date.
delete
public
Set deleted to true and set deletedAt to current date.