@aoss-comm/service-module-common v0.0.2
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
Property | Type | Description |
---|---|---|
id | string | Unique identifier for the user |
code | string | Code representing the user |
name | string | User’s name |
dept | object | User’s department information: id: string - Department IDname: string - Department name |
tenant | object | User’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
Property | Type | Description |
---|---|---|
actAs | CommonUser | (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
Property | Type | Description |
---|---|---|
service | T | Injected service instance |
logger | any | Logger, based on log4js |
Constructor
Parameter | Type | Description |
---|---|---|
service | T | Injected service instance |
2. CommonController
Features
CommonController
extends BaseController
, adding entity validation and implementing basic CRUD operation interfaces.
New Properties
Property | Type | Description |
---|---|---|
rules | ValidationRules | Validation rules for entities, optional |
Methods
Method Name | Return Type | Description |
---|---|---|
validateEntity(data) | void | Validates entity data against rules |
createNew() | RestfulFunction | Provides an interface for creating entities |
update() | RestfulFunction | Provides an interface for updating entities |
del() | RestfulFunction | Provides an interface for deleting entities |
checkInterface(name) | void | Verifies the existence of a service interface |
invokeServiceInterface(name, args) | Promise | Calls a service interface method |
_createNew(req) | Promise | Implements the logic for creating entities |
_update(req) | Promise | Implements the logic for updating entities |
_del(req) | Promise | Implements 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 Name | Return Type | Description |
---|---|---|
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 Name | Return Type | Description |
---|---|---|
search() | (req) => any | Provides 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 Name | Return Type | Description |
---|---|---|
getLoggedUser(req) | CommonUser | Retrieves 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 Name | Return Type | Description |
---|---|---|
search() | (req) => any | Provides an interface for querying entities |