Defining the schema
Schemas are grouping of resources that will be used to provide behaviors and states for business rules
Creating the Schema
To create aschema
for theCategory
entity, we will create aCategorySchema.js
file within the domain'sSchema
folder (src/domains/General/Category/Schema/CategorySchema.js
) This file should extend theSchema
class. The initial result will be a document like the one below.
Importing resources
This definition is the most basic that we can do for this class because theconstruct
method must be implemented even in this first version. In addition to this method, we will make some more configurations, informing the class structure the properties: domain
, path
and service
.
The static domain and path properties are imported from thesettings.js
that we defined in Configuring the domain and theservice
property is theCategoryService.js
file that we created in Preparing access to the API.
Creating thename
field
name
fieldWith our schema started we will configure the fields that will be used by the entity. For this we will use theaddField
method that must be called within theconstruct
.
In the code snippet above we declare that ourschema
will work with thename
field. By default, a created field is not displayed in thetable
and is displayed on theform
with a width that occupies 100% of the line in a text field. TheprimaryKey
field is loaded implicitly in all children ofSchema
. Therefore, our class is mapping two fields: id
and name
. Later on we will see the settings of the fields and everything we can do with them, in addition to other configurable features in ourschema
.
In the next step we will see how to add some routes so that we can see our screen being rendered.
Last updated
Was this helpful?