Entity Service
Entities in stack9 have actions avaivable to be used.
Stack9-core
The service EntityService
implements IEntityService
which has the following actions available:
index: Search
/** * @param entityName = entity name * @param query = Stack9 Query Object */ index(entityName: string, query?: any): Promise<any>
details: Get entity details
/** * @param entityName = entity name * @param id = entity ID * @param options = query options */ details(entityName: string, id: number, options?: { $withRelated: Array<string>; applyFunction: string }): Promise<any>
getAttachments: Get all attachments
/** * @param entityName = entity name * @param id = entity ID */ getAttachments(entityName: string, id: number }): Promise<any[]>
downloadAttachment: Download attachment by ID
/** * @param entityName = entity name * @param attachmentId = attachment ID */ downloadAttachment(entityName: string, attachmentId: number): Promise<Buffer>
insertAttachment: Insert attachment(s)
/** * @param entityName = entity name * @param id = attachment ID * @param files = files array */ insertAttachment(entityName: string, id: number, files: File[]): Promise<Buffer>
deleteAttachment: Delete attachment by ID
/** * @param entityName = entity name * @param id = attachment ID * @param attachmentId = attachment ID */ deleteAttachment(entityName: string, id: number, attachmentId: number): Promise<void>
getHistory: Get entity history by ID
/** * @param entityName = entity name * @param id = entity ID */ getHistory(entityName: string, id: number): Promise<any[]>
getComments: Get entity comments by ID
/** * @param entityName = entity name * @param id = entity ID */ getComments(entityName: string, id: number): Promise<EntityComment[]>
insertComment: Insert comment by ID
/** * @param entityName = entity name * @param id = entity ID * @param comment = entity ID */ insertComment(entityName: string, id: number, comment: any): Promise<{ id: any; }>
searchWithRelated: Search with related entities
/** * @param entityName = entity name * @param criterion = Stack9 Query Object * @param options = query options */ searchWithRelated(entityName: string, criterion: any, options: { limit?: number; page?: number }): Promise<any>
search: Search without related entities
/** * @param entityName = entity name * @param criterion = Stack9 Query Object * @param options = query options */ search(entityName: string, criterion: any, options: { limit?: number; page?: number }): Promise<any>
bulkSearch: Bulk search
export interface MultiCriterion { $queries: { entityName: string; criterion: any }; } /** * @param multiCriterion = MultiCriterion * @param options = query options */ bulkSearch(multiCriterion: MultiCriterion, options: { limit?: number; page?: number }): Promise<Array<any>>
find: Find entity
/** * @param entityName = entity name * @param criterion = Stack9 Query Object */ find(entityName: string, criterion: any): Promise<any>
insert: Insert entity
/** * @param entityName = entity name * @param data = data */ insert(entityName: string, data: any): Promise<any>
update: Update entity
export interface IUpdateWorkflowRequest { step: number; action: WorkflowActionType | string; outcome?: WorkFlowOutcome; owner?: number; outcomeReason?: string; } /** * @param entityName = entity name * @param id = entity ID * @param data = data * @param operation = HookOperation * @param workflowData = IUpdateWorkflowRequest */ update(entityName: string, id: number, data: any, operation: HookOperation, workflowData?: IUpdateWorkflowRequest): Promise<{ entity: any; }>
delete: Delete entity
/** * @param entityName = entity name * @param id = entity ID */ delete(entityName: string, id: string): Promise<number>
export: Export entity to Excel
/** * @param entityName = entity name * @param criterion = Stack9 Query Object * @param options = query options */ export(entityName: string, criterion: any, options?: { limit?: number; page?: number }): Promise<Buffer>
renderDocDetails: Render entity as a printable document
/** * @param entityName = entity name * @param entityId = entity ID * @param documentId = printable document ID */ renderDocDetails(entityName: string, entityId: number, documentId: number): Promise<string>
renderDocListing: Render various entities as a printable document
/** * @param entityName = entity name * @param documentId = printable document ID * @param options = query options */ renderDocListing(entityName: string, documentId: number, options?: { criterion?: any; limit?: number }): Promise<string>
Usage
Stack9 Query Object to be passed as parameter in some actions