Class: ModelUtils
Defined in: service-core/src/models/ModelUtils.ts:28
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:47
Returns the typeorm module, throwing an error if it has not been provided.
Returns
any
Methods
buildIdSearchQuery()
staticbuildIdSearchQuery<T>(repo,modelClass,id,version?):any
Defined in: service-core/src/models/ModelUtils.ts:134
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.
Returns
any
An object that can be passed to a TypeORM find function.
buildIdSearchQueryMongo()
staticbuildIdSearchQueryMongo(modelClass,id,version?):any
Defined in: service-core/src/models/ModelUtils.ts:182
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.
Returns
any
An object that can be passed to a MongoDB find function.
buildIdSearchQuerySQL()
staticbuildIdSearchQuerySQL(modelClass,id,version?):any
Defined in: service-core/src/models/ModelUtils.ts:156
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.
Returns
any
An object that can be passed to a TypeORM find function.
buildSearchQuery()
staticbuildSearchQuery<T>(modelClass,repo,params?,queryParams?,exactMatch?,user?):any
Defined in: service-core/src/models/ModelUtils.ts:472
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.
params?
any
The URI parameters for the endpoint that was requested.
queryParams?
any
The URI query parameters that were included in the request.
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,params?,queryParams?,exactMatch?,user?):any
Defined in: service-core/src/models/ModelUtils.ts:662
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.
params?
any
The URI parameters for the endpoint that was requested.
queryParams?
any
The URI query parameters that were included in the request.
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.
buildSearchQuerySQL()
staticbuildSearchQuerySQL(modelClass,params?,queryParams?,exactMatch?,user?):any
Defined in: service-core/src/models/ModelUtils.ts:518
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.
params?
any
The URI parameters for the endpoint that was requested.
queryParams?
any
The URI query parameters that were included in the request.
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:62
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:96
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:822
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:40
Provides the typeorm module to use when building SQL queries. This is called automatically when a SQL
datastore connection is established.
Parameters
module
any
The typeorm module.
Returns
void