Class: ModelUtils
Defined in: service-core/src/models/ModelUtils.ts:31
Utility class for working with data model classes.
Constructors
Constructor
new ModelUtils():
ModelUtils
Returns
ModelUtils
Accessors
orm
Get Signature
get
staticorm():any
Defined in: service-core/src/models/ModelUtils.ts:50
Returns the typeorm module, throwing an error if it has not been provided.
Returns
any
Methods
buildIdSearchQuery()
staticbuildIdSearchQuery<T>(repo,modelClass,id,version?,includeDeleted?):any
Defined in: service-core/src/models/ModelUtils.ts:142
Builds a query object for use with find functions of the given repository for retrieving objects matching the
specified unique identifier.
Type Parameters
T
T extends object
Parameters
repo
Repository<T> | MongoRepository<T> | undefined
The repository to build the query for.
modelClass
any
The class definition of the data model to build a search query for.
id
any
The unique identifier to search for.
version?
number
The version number of the document to search for.
includeDeleted?
boolean = true
Set to false to exclude soft-deleted RecoverableBaseEntity records from matching.
Defaults to true (matches regardless of deleted state) to preserve existing lookup/validation behavior;
callers that expose a record by id to an API client (e.g. findOne, exists) should pass false so a
soft-deleted record doesn't remain fully readable/resurrectable, the same way buildSearchQuery already
excludes deleted records by default for list-style queries.
Returns
any
An object that can be passed to a TypeORM find function.
buildIdSearchQueryMongo()
staticbuildIdSearchQueryMongo(modelClass,id,version?,includeDeleted?):any
Defined in: service-core/src/models/ModelUtils.ts:203
Builds a MongoDB compatible query object for use in find functions for retrieving objects matching the
specified unique identifier.
Parameters
modelClass
any
The class definition of the data model to build a search query for.
id
any
The unique identifier to search for.
version?
number
The version number of the document to search for.
includeDeleted?
boolean = true
Set to true to also match soft-deleted RecoverableBaseEntity records.
Returns
any
An object that can be passed to a MongoDB find function.
buildIdSearchQuerySQL()
staticbuildIdSearchQuerySQL(modelClass,id,version?,includeDeleted?):any
Defined in: service-core/src/models/ModelUtils.ts:165
Builds a TypeORM compatible query object for use in find functions for retrieving objects matching the
specified unique identifier.
Parameters
modelClass
any
The class definition of the data model to build a search query for.
id
any
The unique identifier to search for.
version?
number
The version number of the document to search for.
includeDeleted?
boolean = true
Returns
any
An object that can be passed to a TypeORM find function.
buildSearchQuery()
staticbuildSearchQuery<T>(modelClass,repo,query?,exactMatch?,user?):any
Defined in: service-core/src/models/ModelUtils.ts:521
Builds a query object for the given criteria and repository. Query params can have a value containing a
conditional operator to apply for the search. The operator is encoded with the format op(value). The following
operators are supported:
eq- Returns matches whose parameter exactly matches of the given value. e.g.param = valuegt- Returns matches whose parameter is greater than the given value. e.g.param > valuegte- Returns matches whose parameter is greater than or equal to the given value. e.g.param >= valuein- Returns matches whose parameter includes one of the given values. e.g.param in ('value1', 'value2', 'value3', ...)like- Returns matches whose parameter is lexographically similar to the given value.param like valuelt- Returns matches whose parameter is less than the given value. e.g.param < valuelte- Returns matches whose parameter is less than or equal to than the given value. e.g.param < valuenot- Returns matches whose parameter is not equal to the given value. e.g.param not valuerange- Returns matches whose parameter is greater than or equal to first given value and less than or equal to the second. e.g.param between(1,100)
When no operator is provided the comparison will always be evaluated as eq.
NOTE: The result of this function is only compatible with the aggregate() function when MongoDB is used.
Type Parameters
T
T extends object
Parameters
modelClass
any
The class definition of the data model to build a search query for.
repo
Repository<T> | MongoRepository<T> | undefined
The repository to build a search query for.
query?
any = {}
The search query parameters to include.
exactMatch?
boolean = false
Set to true to create a query where parameters are to be matched exactly, otherwise set to false to use a 'contains' search.
user?
any
The user that is performing the request.
Returns
any
The TypeORM compatible query object.
buildSearchQueryMongo()
staticbuildSearchQueryMongo(modelClass,query?,exactMatch?,user?):any
Defined in: service-core/src/models/ModelUtils.ts:702
Builds a MongoDB compatible query object for the given criteria. Query params can have a value containing a
conditional operator to apply for the search. The operator is encoded with the format op(value). The following
operators are supported:
eq- Returns matches whose parameter exactly matches of the given value. e.g.param = valuegt- Returns matches whose parameter is greater than the given value. e.g.param > valuegte- Returns matches whose parameter is greater than or equal to the given value. e.g.param >= valuein- Returns matches whose parameter includes one of the given values. e.g.param in ('value1', 'value2', 'value3', ...)like- Returns matches whose parameter is lexographically similar to the given value.param like valuelt- Returns matches whose parameter is less than the given value. e.g.param < valuelte- Returns matches whose parameter is less than or equal to than the given value. e.g.param < valuenot- Returns matches whose parameter is not equal to the given value. e.g.param not valuerange- Returns matches whose parameter is greater than or equal to first given value and less than or equal to the second. e.g.param between(1,100)
When no operator is provided the comparison will always be evaluated as eq.
NOTE: The result of this function is only compatible with the aggregate() function.
Parameters
modelClass
any
The class definition of the data model to build a search query for.
query?
any = {}
The search query parameters to include.
exactMatch?
boolean = false
Set to true to create a query where parameters are to be matched exactly, otherwise set to false to use a 'contains' search.
user?
any
The user that is performing the request.
Returns
any
The MongoDB compatible query object.
buildSearchQuerySQL()
staticbuildSearchQuerySQL(modelClass,query?,exactMatch?,user?):any
Defined in: service-core/src/models/ModelUtils.ts:565
Builds a TypeORM compatible query object for the given criteria. Query params can have a value containing a
conditional operator to apply for the search. The operator is encoded with the format op(value). The following
operators are supported:
eq- Returns matches whose parameter exactly matches of the given value. e.g.param = valuegt- Returns matches whose parameter is greater than the given value. e.g.param > valuegte- Returns matches whose parameter is greater than or equal to the given value. e.g.param >= valuein- Returns matches whose parameter includes one of the given values. e.g.param in ('value1', 'value2', 'value3', ...)like- Returns matches whose parameter is lexographically similar to the given value.param like valuelt- Returns matches whose parameter is less than the given value. e.g.param < valuelte- Returns matches whose parameter is less than or equal to than the given value. e.g.param < valuenot- Returns matches whose parameter is not equal to the given value. e.g.param not valuerange- Returns matches whose parameter is greater than or equal to first given value and less than or equal to the second. e.g.param between(1,100)
When no operator is provided the comparison will always be evaluated as eq.
Parameters
modelClass
any
The class definition of the data model to build a search query for.
query?
any = {}
The search query parameters to include.
exactMatch?
boolean = false
Set to true to create a query where parameters are to be matched exactly, otherwise set to false to use a 'contains' search.
user?
any
The user that is performing the request.
Returns
any
The TypeORM compatible query object.
getIdPropertyNames()
staticgetIdPropertyNames(modelClass):string[]
Defined in: service-core/src/models/ModelUtils.ts:65
Retrieves a list of all of the specified class's properties that have the
Parameters
modelClass
any
The class definition to search for identifiers from.
Returns
string[]
The list of all property names that have the
Identifier
decorator applied.
Identifier
decorator applied.
getReadOnlyPropertyNames()
staticgetReadOnlyPropertyNames(modelClass):string[]
Defined in: service-core/src/models/ModelUtils.ts:99
Retrieves a list of all of the specified class's properties that have the
Parameters
modelClass
any
The class definition to search for read-only properties from.
Returns
string[]
The list of all property names that have the
Read Only
decorator applied.
Read Only
decorator applied.
loadModels()
staticloadModels(src,result?):Promise<Map<string,any>>
Defined in: service-core/src/models/ModelUtils.ts:882
Loads all model schema files from the specified path and returns a map containing all the definitions.
Parameters
src
string
The path to the model files to load.
result?
Map<string, any> = ...
Returns
Promise<Map<string, any>>
A map containing of all loaded model names to their class definitions.
setTypeOrm()
staticsetTypeOrm(module):void
Defined in: service-core/src/models/ModelUtils.ts:43
Provides the typeorm module to use when building SQL queries. This is called automatically when a SQL
datasource connection is established.
Parameters
module
any
The typeorm module.
Returns
void