0.0.2 • Published 10 months ago

@aoss-comm/service-module-common v0.0.2

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

Core Modules

This is the foundational library of the entire application support system. It serves as the base common library to avoid version conflicts by including @ticatec/node-common-library via peerDependencies.

Installation

npm i @aoss-comm/service-module-common

Entity Class CommonUser

The CommonUser interface represents a generic user object that includes essential user details such as ID, code, name, department, and tenant.

Property Details

PropertyTypeDescription
idstringUnique identifier for the user
codestringCode representing the user
namestringUser’s name
deptobjectUser’s department information: id: string - Department IDname: string- Department name
tenantobjectUser’s tenant information:code:code: string - Tenant codename: string - Tenant name

Entity Class LoggedUser

The LoggedUser interface extends CommonUser, representing the currently logged-in user. It adds an optional property actAs for scenarios where the user operates as another user.

Property Details

PropertyTypeDescription
actAsCommonUser(Optional) Represents the user being impersonated

Controller Abstract Controller Classes

This set of controller classes provides an abstract implementation for service-layer-based controllers, mainly used for managing entities (create, update, delete) and performing queries. The classes have an inheritance hierarchy, and developers can override or extend methods to implement specific business logic.


1. BaseController

Features

BaseController is the base class for all controllers, responsible for initializing the service and logging functionalities.

Properties

PropertyTypeDescription
serviceTInjected service instance
loggeranyLogger, based on log4js

Constructor

ParameterTypeDescription
serviceTInjected service instance

2. CommonController

Features

CommonController extends BaseController, adding entity validation and implementing basic CRUD operation interfaces.

New Properties

PropertyTypeDescription
rulesValidationRulesValidation rules for entities, optional

Methods

Method NameReturn TypeDescription
validateEntity(data)voidValidates entity data against rules
createNew()RestfulFunctionProvides an interface for creating entities
update()RestfulFunctionProvides an interface for updating entities
del()RestfulFunctionProvides an interface for deleting entities
checkInterface(name)voidVerifies the existence of a service interface
invokeServiceInterface(name, args)PromiseCalls a service interface method
_createNew(req)PromiseImplements the logic for creating entities
_update(req)PromiseImplements the logic for updating entities
_del(req)PromiseImplements the logic for deleting entities (requires subclass implementation)
getCreateNewArguments(req)Array<any>Abstract method, must be implemented by subclass to extract arguments for creation
getUpdateArguments(req)Array<any>Abstract method, must be implemented by subclass to extract arguments for update

3. AdminBaseController

Features

AdminBaseController is a foundational class for platform management controllers unrelated to tenants. It provides default logic for extracting arguments for creating and updating entities.

Methods

Method NameReturn TypeDescription
getCreateNewArguments(req)Array<any>Default implementation extracts creation arguments from the request body
getUpdateArguments(req)Array<any>Default implementation extracts update arguments from the request body

4. AdminSearchController

Features

AdminSearchController extends AdminBaseController, adding functionality for conditional queries.

Methods

Method NameReturn TypeDescription
search()(req) => anyProvides an interface for querying entities

5. TenantBaseController

Features

TenantBaseController is designed for managing tenant-related entities. It provides default logic for extracting arguments for creating and updating entities and supports scenarios where the user operates as another user.

Methods

Method NameReturn TypeDescription
getLoggedUser(req)CommonUserRetrieves the current user, including impersonated users
getCreateNewArguments(req)Array<any>Extracts creation arguments, including the logged-in user
getUpdateArguments(req)Array<any>Extracts update arguments, including the logged-in user

6. TenantSearchController

Features

TenantSearchController extends TenantBaseController, adding functionality for tenant-related conditional queries.

Methods

Method NameReturn TypeDescription
search()(req) => anyProvides an interface for querying entities