Entity Creation Guidelines


Averos framework declares a set of guidelines that will lead you through the right way of managing averos entities.
Averos entity guidelines defines the following conventions when dealing with entities:

  • An averos entity should be decorated with @AverosEntity
  • An averos entity unique id should be decorated by @ID
  • Composite entity members defining relationships should be decorated by one of the available averos relationship decorators:
    • A One-To-One relationship should be annotated/decorated with @OneToOne
    • A Many-To-One relationship should be annotated/decorated with the @ManyToOne
    • A One-To-Many relationship should be annotated/decorated with the @OneToMany
  • An averos entity should be managed by an averos service. The entity service should be passed as a parameter in the @AverosEntity decorator.

Below is an example of a generated averos entity named ToDoArea:

@AverosEntity(ToDoAreaService)
export class ToDoArea {
    public static entityViewLayout$: Observable<EntityViewLayout<ToDoArea>>;
    public static entityViewLayout : EntityViewLayout<ToDoArea>;
    public static entityName = 'ToDoArea';
    public static instanceMetadata: ToDoArea = null;

    @ID()
    id: number;
    name: string;
    description: string;
    createdAt: Date = null;
    updatedAt: Date = null;
 

    @OneToMany('ToDoTask', import('./to-do-task')) 
    toDoTasks: ToDoTask[];
    @OneToOne('User', import('@wiforge/averos/core/_models/user')) createdBy?: User;
    @OneToOne('User', import('@wiforge/averos/core/_models/user')) updatedBy?: User;

    static getEntityViewLayout(): Observable<EntityViewLayout<ToDoArea>> {
        return ToDoArea.entityViewLayout$;
    }

    static getUseCaseViewLayout(useCase: UseCase): Observable<UseCaseViewLayout<ToDoArea>>{
        return getUseCaseViewLayout(MyAverosEntity, useCase);
    }

    static instanceMetadata(){
        if (!ToDoArea.instance){
            ToDoArea.instance = new ToDoArea();
        }
        return MyAverosEntity.instance;
    }

}

๐Ÿ™‹โ€โ™‚๏ธ Though averos entity members, could be added manually, we recommend using the averos workflow ng g @wiforge/averos:add-simple-member for adding simple typed members and ng g @wiforge/averos:add-composite-member for adding composite members to the averos business entity. Using the predefined workflow will unlock all averos features by allowing users to define other entity aspects related to the update strategy, view layout types, view metadata along with setting possible default values. Do not hesitate to use averos workflow when possible in order to leverage the framework capabilities.