Skip to main content

Abstract Class: CRUDRoute<T>

Defined in: service-core/src/routes/CRUDRoute.ts:55

The CRUDRoute provides a base implementation of all CRUD endpoint behaviors that ModelRoute offers for a given data model class. This class provides the most common default settings for each route handler. If you desire additional functionality you may override the handler function and add desired functionality via additional decorators or override existing decorator behavior.

The route endpoints provided by this class do not explicitly require authentication. However, if the RBAC system is enabled these handlers will still validate permissions appropriately.

Included Endpoints:

NameHTTP MethodWhat it does
countHEAD /Counts the number of objects matching the provided set of criteria in the request's query parameters. Returns the count as the value of the Content-Length header.
createPOST /Adds one or more new objects to the datasource.
deleteDELETE /:idRemoves an existing object from the datasource.
existsHEAD /:idChecks if the object with the given ID exists in the datasource. Sets Content-Length header to 1 if the object exists, otherwise 0.
findGET /Returns all objects matching the provided set of criteria in the request's query parameters.
findByIdGET /:idReturns a single object with a specified unique identifier.
truncateDELETE /Removes all objects from the datasource.
updatePUT /:idModifies an existing object in the datasource.
updateBulkPUT /Modifies multiple existing objects in the datasource.
updatePropertyPUT /:id/:propertyModifies an single property of the given name of an existing object in the datasource.

Extends​

Extended by​

Type Parameters​

T​

T extends BaseEntity | SimpleEntity

Constructors​

Constructor​

new CRUDRoute<T>(): CRUDRoute<T>

Returns​

CRUDRoute<T>

Inherited from​

ModelRoute.constructor

Properties​

_objectFactory?​

protected optional _objectFactory?: ObjectFactory

Defined in: service-core/src/routes/ModelRoute.ts:120

Inherited from​

ModelRoute._objectFactory


aclUtils?​

protected optional aclUtils?: ACLUtils

Defined in: service-core/src/routes/ModelRoute.ts:123

Inherited from​

ModelRoute.aclUtils


config?​

protected optional config?: any

Defined in: service-core/src/routes/ModelRoute.ts:127

The global application configuration.

Inherited from​

ModelRoute.config


defaultACLUid​

protected defaultACLUid: string = ""

Defined in: service-core/src/routes/ModelRoute.ts:130

The unique identifier of the default ACL for the model type.

Inherited from​

ModelRoute.defaultACLUid


logger​

protected logger: any

Defined in: service-core/src/routes/ModelRoute.ts:133

Inherited from​

ModelRoute.logger


notificationUtils?​

protected optional notificationUtils?: NotificationUtils

Defined in: service-core/src/routes/ModelRoute.ts:136

Inherited from​

ModelRoute.notificationUtils


repoUtils?​

protected optional repoUtils?: RepoUtils<T>

Defined in: service-core/src/routes/ModelRoute.ts:142

The repository utility class to use for common operations.

Inherited from​

ModelRoute.repoUtils


repoUtilsClass​

protected readonly repoUtilsClass: any = RepoUtils

Defined in: service-core/src/routes/CRUDRoute.ts:56

The class of the RepoUtils to use when instantiating the utility.

Overrides​

ModelRoute.repoUtilsClass


trackChanges​

protected trackChanges: 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.

Inherited from​

ModelRoute.trackChanges


trustedRoles​

protected trustedRoles: string[]

Defined in: service-core/src/routes/ModelRoute.ts:151

Inherited from​

ModelRoute.trustedRoles

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

Inherited from​

ModelRoute.modelClass

Methods​

count()​

count(params, query, res, user?): Promise<any>

Defined in: service-core/src/routes/CRUDRoute.ts:65

Parameters​

params​

any

query​

any

res​

HttpResponse

user?​

JWTUser

Returns​

Promise<any>


create()​

create(obj, req, user?): Promise<T | T[]>

Defined in: service-core/src/routes/CRUDRoute.ts:128

Parameters​

obj​

T | T[]

req​

HttpRequest

user?​

JWTUser

Returns​

Promise<T | T[]>


delete()​

delete(id, version, purge, req, user?): Promise<void>

Defined in: service-core/src/routes/CRUDRoute.ts:137

Parameters​

id​

string

version​

string | undefined

purge​

string | undefined

req​

HttpRequest

user?​

JWTUser

Returns​

Promise<void>


doBulkCreate()​

protected doBulkCreate(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​

CreateRequestOptions

The options to process the request using.

Returns​

Promise<T[]>

Inherited from​

ModelRoute.doBulkCreate


doBulkUpdate()​

protected doBulkUpdate(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​

UpdateRequestOptions<T>

The options to process the request using.

Returns​

Promise<T[]>

Inherited from​

ModelRoute.doBulkUpdate


doCount()​

protected doCount(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​

FindRequestOptions

The options to process the request using.

Returns​

Promise<HttpResponse>

Inherited from​

ModelRoute.doCount


doCreate()​

protected doCreate(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​

CreateRequestOptions

The options to process the request using.

Returns​

Promise<T | T[]>

Inherited from​

ModelRoute.doCreate


doCreateObject()​

protected doCreateObject(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​

CreateRequestOptions

The options to process the request using.

Returns​

Promise<T>

Inherited from​

ModelRoute.doCreateObject


doDelete()​

protected doDelete(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​

DeleteRequestOptions

The options to process the request using.

Returns​

Promise<void>

Inherited from​

ModelRoute.doDelete


doExists()​

protected doExists(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​

FindRequestOptions

The options to process the request using.

Returns​

Promise<any>

Inherited from​

ModelRoute.doExists


doFind()​

protected doFind(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​

FindRequestOptions

The options to process the request using.

Returns​

Promise<T[]>

Inherited from​

ModelRoute.doFind


doFindById()​

protected doFindById(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​

FindRequestOptions

The options to process the request using.

Returns​

Promise<T | null>

Inherited from​

ModelRoute.doFindById


doTruncate()​

protected doTruncate(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​

TruncateRequestOptions

The options to process the request using.

Returns​

Promise<void>

Inherited from​

ModelRoute.doTruncate


doUpdate()​

protected doUpdate(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​

UpdateRequestOptions<T>

The options to process the request using.

Returns​

Promise<T>

Inherited from​

ModelRoute.doUpdate


doUpdateProperty()​

protected doUpdateProperty(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​

UpdateRequestOptions<T>

The options to process the request using.

Returns​

Promise<T>

Inherited from​

ModelRoute.doUpdateProperty


exists()​

exists(id, query, res, user?): Promise<any>

Defined in: service-core/src/routes/CRUDRoute.ts:154

Parameters​

id​

string

query​

any

res​

HttpResponse

user?​

JWTUser

Returns​

Promise<any>


find()​

find(params, query, user?): Promise<T[]>

Defined in: service-core/src/routes/CRUDRoute.ts:167

Parameters​

params​

any

query​

any

user?​

JWTUser

Returns​

Promise<T[]>


findById()​

findById(id, query, user?): Promise<T | null>

Defined in: service-core/src/routes/CRUDRoute.ts:175

Parameters​

id​

string

query​

any

user?​

JWTUser

Returns​

Promise<T | null>


truncate()​

truncate(params, query, user?): Promise<void>

Defined in: service-core/src/routes/CRUDRoute.ts:184

Parameters​

params​

any

query​

any

user?​

JWTUser

Returns​

Promise<void>


update()​

update(id, obj, req, user?): Promise<T>

Defined in: service-core/src/routes/CRUDRoute.ts:203

Parameters​

id​

string

obj​

UpdateObject<T>

req​

HttpRequest

user?​

JWTUser

Returns​

Promise<T>


updateBulk()​

updateBulk(obj, req, user?): Promise<T[]>

Defined in: service-core/src/routes/CRUDRoute.ts:226

Parameters​

obj​

UpdateObject<T>[]

req​

HttpRequest

user?​

JWTUser

Returns​

Promise<T[]>


updateProperty()​

updateProperty(id, propertyName, obj, user?): Promise<T>

Defined in: service-core/src/routes/CRUDRoute.ts:236

Parameters​

id​

string

propertyName​

string

obj​

any

user?​

JWTUser

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>

Inherited from​

ModelRoute.validate


validateCreate()​

protected validateCreate(obj, user?): Promise<void>

Defined in: service-core/src/routes/CRUDRoute.ts:78

Override this function to perform additional custom validation of object creation. This is called for each object passed to the create() operation.

Parameters​

obj​

Partial<T>

user?​

JWTUser

Returns​

Promise<void>


validateUpdate()​

protected validateUpdate(id, obj, user?): Promise<void>

Defined in: service-core/src/routes/CRUDRoute.ts:193

Override this function to perform additional custom validation of object updates. This is called for update() and updateBulk() operations. updateBulk() calls this function for each update object.

Parameters​

id​

string

obj​

UpdateObject<T>

user?​

JWTUser

Returns​

Promise<void>