Abstract Class: ModelRoute<T>
Defined in: service-core/src/routes/ModelRoute.ts:118
The ModelRoute is an abstract base class that provides a set of built-in route behavior functions for handling
requests for a given data model that is managed by a persistent datasource. This class does not provide route
handlers for the defined behaviors. This class is intended to serve as a base class for you to extend and hook
up your own route handlers that use the included functionality as desired so that you only expose the CRUD
endpoints for your model that you desire. If you desire a fully functional set of route handlers that implements
all of these behaviors you should extend the CRUDRoute class instead.
Provided behaviors:
doCount: Counts the number of objects matching the provided set of criteria in the request's query parameters. Returns the count as the value of theContent-Lengthheader.doCreate: Adds one or more new objects to the datasource.doDelete: Removes an existing object from the datasource.doExists: Checks if the object with the given ID exists in the datasource. SetsContent-Lengthheader to1if the object exists, otherwise0.doFind: Returns all objects matching the provided set of criteria in the request's query parameters.doFindById: Returns a single object with a specified unique identifier.doTruncate: Removes all objects from the datasource.doUpdate: Modifies an existing object in the datasource.doUpdateBulk: Modifies multiple existing objects in the datasource.doUpdateProperty: Modifies an single property of the given name of an existing object in the datasource.
Extended by
Type Parameters
T
T extends BaseEntity | SimpleEntity
Constructors
Constructor
new ModelRoute<
T>():ModelRoute<T>
Returns
ModelRoute<T>
Properties
_objectFactory?
protectedoptional_objectFactory?:ObjectFactory
Defined in: service-core/src/routes/ModelRoute.ts:120
aclUtils?
protectedoptionalaclUtils?:ACLUtils
Defined in: service-core/src/routes/ModelRoute.ts:123
config?
protectedoptionalconfig?:any
Defined in: service-core/src/routes/ModelRoute.ts:127
The global application configuration.
defaultACLUid
protecteddefaultACLUid:string=""
Defined in: service-core/src/routes/ModelRoute.ts:130
The unique identifier of the default ACL for the model type.
logger
protectedlogger:any
Defined in: service-core/src/routes/ModelRoute.ts:133
notificationUtils?
protectedoptionalnotificationUtils?:NotificationUtils
Defined in: service-core/src/routes/ModelRoute.ts:136
repoUtils?
protectedoptionalrepoUtils?:RepoUtils<T>
Defined in: service-core/src/routes/ModelRoute.ts:142
The repository utility class to use for common operations.
repoUtilsClass
abstractprotectedreadonlyrepoUtilsClass:any
Defined in: service-core/src/routes/ModelRoute.ts:139
The class of the RepoUtils to use when instantiating the utility.
trackChanges
protectedtrackChanges:number=0
Defined in: service-core/src/routes/ModelRoute.ts:148
The number of previous document versions to store in the database. A negative value indicates storing all
versions, a value of 0 stores no versions.
trustedRoles
protectedtrustedRoles:string[]
Defined in: service-core/src/routes/ModelRoute.ts:151
Accessors
modelClass
Get Signature
get modelClass():
any
Defined in: service-core/src/routes/ModelRoute.ts:156
The class type of the model this route is associated with.
Returns
any
Methods
doBulkCreate()
protecteddoBulkCreate(objs,options):Promise<T[]>
Defined in: service-core/src/routes/ModelRoute.ts:253
Attempts to store a collection of objects provided in options.req.body into the datasource. Upon success, sets the newly persisted
object(s) to the result property of the options.res argument, otherwise sends a 400 BAD REQUEST response to the
client.
Parameters
objs
Partial<T>[]
The object(s) to store in the database.
options
The options to process the request using.
Returns
Promise<T[]>
doBulkUpdate()
protecteddoBulkUpdate(objs,options):Promise<T[]>
Defined in: service-core/src/routes/ModelRoute.ts:500
Attempts to modify a collection of existing data model objects.
Parameters
objs
UpdateObject<T>[]
The object(s) to bulk update in the database.
options
The options to process the request using.
Returns
Promise<T[]>
doCount()
protecteddoCount(options):Promise<HttpResponse>
Defined in: service-core/src/routes/ModelRoute.ts:188
Attempts to retrieve the number of data model objects matching the given set of criteria as specified in the
request query. Any results that have been found are set to the content-length header of the res argument.
Parameters
options
The options to process the request using.
Returns
Promise<HttpResponse>
doCreate()
protecteddoCreate(obj,options):Promise<T|T[]>
Defined in: service-core/src/routes/ModelRoute.ts:283
Attempts to store one or more objects provided in options.req.body into the datasource. Upon success, sets the newly persisted
object(s) to the result property of the options.res argument, otherwise sends a 400 BAD REQUEST response to the
client.
Parameters
obj
Partial<T> | Partial<T>[]
The object(s) to store in the database.
options
The options to process the request using.
Returns
Promise<T | T[]>
doCreateObject()
protecteddoCreateObject(obj,options):Promise<T>
Defined in: service-core/src/routes/ModelRoute.ts:223
Attempts to store an object provided in options.req.body into the datasource. Upon success, sets the newly persisted
object(s) to the result property of the options.res argument, otherwise sends a 400 BAD REQUEST response to the
client.
Parameters
obj
Partial<T>
The object to store in the database.
options
The options to process the request using.
Returns
Promise<T>
doDelete()
protecteddoDelete(id,options):Promise<void>
Defined in: service-core/src/routes/ModelRoute.ts:312
Attempts to delete an existing data model object with a given unique identifier encoded by the URI parameter
id.
Parameters
id
string
The unique identifier of the object to delete.
options
The options to process the request using.
Returns
Promise<void>
doExists()
protecteddoExists(id,options):Promise<any>
Defined in: service-core/src/routes/ModelRoute.ts:365
Attempts to determine if an existing object with the given unique identifier exists.
Parameters
id
string
The unique identifier of the object to verify exists.
options
The options to process the request using.
Returns
Promise<any>
doFind()
protecteddoFind(options):Promise<T[]>
Defined in: service-core/src/routes/ModelRoute.ts:403
Attempts to retrieve all data model objects matching the given set of criteria as specified in the request
query. Any results that have been found are set to the result property of the res argument. result is
never null.
Parameters
options
The options to process the request using.
Returns
Promise<T[]>
doFindById()
protecteddoFindById(id,options):Promise<T|null>
Defined in: service-core/src/routes/ModelRoute.ts:427
Attempts to retrieve a single data model object as identified by the id parameter in the URI.
Parameters
id
string
options
The options to process the request using.
Returns
Promise<T | null>
doTruncate()
protecteddoTruncate(options):Promise<void>
Defined in: service-core/src/routes/ModelRoute.ts:464
Attempts to remove all entries of the data model type from the datasource matching the given parameters and query.
Parameters
options
The options to process the request using.
Returns
Promise<void>
doUpdate()
protecteddoUpdate(id,obj,options):Promise<T>
Defined in: service-core/src/routes/ModelRoute.ts:529
Attempts to modify an existing data model object as identified by the id parameter in the URI.
Parameters
id
string
obj
UpdateObject<T>
The object to update in the database
options
The options to process the request using.
Returns
Promise<T>
doUpdateProperty()
protecteddoUpdateProperty(id,propertyName,value,options):Promise<T>
Defined in: service-core/src/routes/ModelRoute.ts:581
Attempts to modify a single property of an existing data model object as identified by the id parameter in the URI.
Note that this effectively bypasses optimistic locking and can cause unexpected data overwrites. Use with care.
Parameters
id
string
The unique identifier of the object to update.
propertyName
string
The name of the property to update.
value
any
The value of the property to set.
options
The options to process the request using.
Returns
Promise<T>
validate()
validate(
objs,options?):Promise<void>
Defined in: service-core/src/routes/ModelRoute.ts:623
Calls repoUtils.validate() to validate the object(s) provided.
Parameters
objs
Partial<T> | Partial<T>[]
options?
CreateRequestOptions | UpdateRequestOptions<T>
Returns
Promise<void>