📝Core Entity
The contract that provides methods for entities.
This is an abstract class and is used as a base for other modules.
Imports
Method of Use
To implement this class, you will need an create entity.
Entities with relationships
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
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
get now
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.
unExpire
public
Set expired to false and set expiredAt to null.
unDelete
public
Set deleted to false and set deletedAt to null.
isEnable
public
Check if status is enable, 1 = enable.
isDisable
public
Check if status is disable, 0 = disable.
isExpired
public
Check if expired is true. true = expired.
isDeleted
public
Check if deleted is true. true = deleted.
isNotExpired
public
Check if expired is false. false = not expired.
isNotDeleted
public
Check if deleted is false. false = not deleted.
getCreatedAt
public
Get createdAt date.
getUpdatedAt
public
Get updatedAt date.
getExpiredAt
public
Get expiredAt date.
getDeletedAt
public
Get deletedAt date.
setCreatedAt
public
Set createdAt date.
setUpdatedAt
public
Set updatedAt date.
setExpiredAt
public
Set expiredAt date.
setDeletedAt
public
Set deletedAt date.
get
public
Get entity properties.
Last updated