CustomObjectService Class
Provides a service to do the heavy lifting of retrieving custom objects with the ability to eagerly fetch the related objects.
Constructor
CustomObjectService
()
Item Index
Methods
- applyOrder static
- countByType
- createErrorStr static
- deleteById
- deleteForType
- deleteTypeById
- err static
- fetchChildren
- findByType
- findByTypeWithOrdering
- findTypes
- formatRawForType static
- formatRawSortOrdering static
- getCustTypeSimpleName static
- getFieldTypes static
- getReferenceTypes
- getStaticReferenceTypes static
- isCustomObjectType static
- isReferenceFieldType static
- loadBy
- loadById
- loadByName
- loadSortOrdering
- loadTypeBy
- loadTypeById
- loadTypeByName
- save
- saveSortOrdering
- saveType
- setFieldTypesUsed static
- typeExists
- validate
- validateCustObjFields
- validateFieldDescriptor
- validateSortOrdering
- validateType
Properties
- AVAILABLE_FIELD_TYPES static
- AVAILABLE_REFERENCE_TYPES static
- CHILD_OBJECTS_TYPE static
- CUST_OBJ_COLL static
- CUST_OBJ_SORT_COLL static
- CUST_OBJ_TYPE_COLL static
- CUST_OBJ_TYPE_PREFIX static
- NAME_FIELD static
- PEER_OBJECT_TYPE static
Methods
applyOrder
-
custObjects -
sortOrder
Orders the custom objects based on the provided sort order
Parameters:
-
custObjectsArrayThe array of custom objects to be sorted
-
sortOrderObjectThe object describing the ordering of the objects
Returns:
A refernce to the sorted array of custom objects. The reference is the same as provided to the function.
countByType
-
type -
[where] -
cb
Retrieves a count based the specified criteria and type
Parameters:
-
typeObject | StringThe custom object type object or ID string
-
[where]Object optionalThe criteria for which objects to count
-
cbFunctionA callback that takes two parameters. The first is an error, if occurred. The second is the number of objects that match the specified criteria.
createErrorStr
-
errors -
msg
Creates an HTML formatted error string out of an array of error objects.
Parameters:
-
errorsArrayAn array of objects where each object has a "msg" and a "field" property
-
msgString
Returns:
HTML formatted string representing the errors
deleteById
-
id -
cb
Deletes a custom object by ID
Parameters:
-
idString -
cbFunction(Error, *)
deleteForType
-
custObjType -
cb
Deletes all custom objects of a specified type
Parameters:
-
custObjTypeString | ObjectA string ID of the custom object type or the custom object type itself.
-
cbFunction(Error, *)
deleteTypeById
-
id -
[options={}] -
cb
Deletes a custom object type by id
Parameters:
-
idString | ObjectID -
[options={}]Object optional -
cbFunction(Error, *)
err
-
field -
err
Creates a validation error field
Parameters:
-
fieldStringThe field in the object that contains the error
-
errStringA string description of the error
Returns:
An object that describes the validation error
fetchChildren
-
custObj -
options -
custObjType -
cb
Coordinates the eager fetching of peer and child objects for the specified custom object.
Parameters:
-
custObjObjectThe custom object to inspect
-
optionsObjectThe options specified for the retrieval
-
fetch_depthIntegerThe number of levels of peer and child objects to retrieve
-
-
custObjTypeObject | StringThe custom object type for the specified custom object. This can also be the ID string value.
-
cbFunctionA callback function that takes two parameters. The first is an Error, if occurred. The second is the specified custom object.
findByType
-
type -
[options] -
cb
Finds custom objects by the specified type.
Parameters:
-
typeObject | StringThe custom object type object or the ID of the object as a string
-
[options]Object optionalSee DAO.q()
-
cbFunctionA callback that takes two arguments. The first is an error, if occurred. The second is an array of custom objects that match the specified criteria.
findByTypeWithOrdering
-
custObjType -
[options={}] -
cb
Retrieves custom objects of the specified type based on the specified options.
Parameters:
-
custObjTypeObject | StringThe custom object type descriptor object or the ID string of the type descriptor.
-
[options={}]Object optionalThe filters and other flags. The options object supports the same fields as the DAO.query function.
-
[fetch_depth=0]Integer optionalThe depth indicates how many levels of referenced child and peer objects to load. At the bottom level the references will be left as ID strings.
-
-
cbFunctionA callback that takes two parameters. The first is any error, if occurred. The second is an array of objects sorted by the ordering assigned for the custom object or by name if no ordering exists.
findTypes
-
cb
Retrieves all of the custom object types in the system
Parameters:
-
cbFunctionA callback that takes two parameters. The first is an error, if occurred. The second is an array of custom object type objects.
formatRawForType
-
post -
custObjType
Formats the object by ensuring that each field is in the correct data type.
Parameters:
-
postObjectThe raw post object
-
custObjTypeObjectThe custom object type describes the data in the post obj.
formatRawSortOrdering
-
post -
sortOrder
Formats the raw post data for a sort ordering
Parameters:
-
postObject -
sortOrderObjectthe existing sort order object that the post data will be merged with
Returns:
The formatted sort ordering object
getCustTypeSimpleName
-
name
Gets the simple custom object name. The simple name is one that is not prefixed to indicate that it is custom
Parameters:
-
nameString
Returns:
getFieldTypes
()
Array
static
Provides the various types of fields that are allowed for a custom object (number, boolean, string, etc).
Returns:
getReferenceTypes
-
cb
Retrieves an array of all of the available object types that can be referenced as a child or peer object.
Parameters:
-
cbFunctionA callback that takes two parameters: The first, an error, if occurs. The second is an array of all of the available object types that can be referenced as a peer or child object.
getStaticReferenceTypes
()
Array
static
Retrieves the objects types that can be referenced by custom objects
Returns:
isCustomObjectType
-
objType
Determines if the field type is a custom object type or a system reference
Parameters:
-
objTypeString
Returns:
isReferenceFieldType
-
fieldType
Determines if a field type is reference to another object type
Parameters:
-
fieldTypeString
Returns:
loadBy
-
type -
where -
[options] -
cb
Loads a custom object by the specified where criteria
Parameters:
-
typeString | Null -
whereObject -
[options]Object optional -
cbFunction
loadById
-
id -
[options] -
cb
Loads a custom object by ID
Parameters:
-
idObjectID | String -
[options]Object optional -
cbFunction
loadByName
-
type -
name -
[options] -
cb
Loads a custom object by name
Parameters:
-
typeStringThe ID string of the custom object type
-
nameStringThe unique name of the custom object
-
[options]Object optional -
cbFunction
loadSortOrdering
-
custObjType -
cb
Loads an ordering object for a specific custom object type.
Parameters:
-
custObjTypeObject | String -
cbFunctionA callback that takes two parameters. The first is an error, if occurred. The second is the sort ordering object if found.
loadTypeBy
-
where -
cb
Loads a custom object type by the specified where criteria
Parameters:
-
whereObject -
cbFunction
loadTypeById
-
id -
cb
Loads a custom object type by ID
Parameters:
-
idObjectID | String -
cbFunction
loadTypeByName
-
name -
cb
Loads a custom object type by name
Parameters:
-
nameString -
cbFunction
save
-
custObj -
custObjType -
cb
Validates and persists a custom object
Parameters:
-
custObjObjectThe object to validate
-
custObjTypeObjectThe custom object type to validate against
-
cbFunctionA callback that takes two parameters. The first is an error if occurred. The second is an array of validation error objects or the result of the persistence operation.
saveSortOrdering
-
sortOrder -
cb
Validates and persists a sort ordering for custom objects of a specific type
Parameters:
-
sortOrderObject -
cbFunction
saveType
-
custObjType -
cb
Validates and persists a custom object type
Parameters:
-
custObjTypeObjectThe object to persist
-
cbFunctionA callback that takes two parameters. The first is an error if occurred. The second is an array of validation error objects or the result of the persistence operation.
setFieldTypesUsed
-
custObjTypes -
ls
Discovers the field types used for each entry in the provided array and sets the "fieldTypesUsed" property for the object.
Parameters:
-
custObjTypesArrayThe array of custom object type objects to inspect
-
lsLocalization
typeExists
-
typeName -
cb
Determines if a custom object type with the specified name (case insensitive) exists
Parameters:
-
typeNameString -
cbFunction(Error, Boolean)
validate
-
custObj -
custObjType -
cb
Validates a custom object
Parameters:
-
custObjObjectThe object to validate
-
custObjTypeObjectThe custom object type to validate against
-
cbFunctionA callback that takes two parameters. The first is an error if occurred. The second is an array of validation error objects. If the array is empty it is safe to assume that the object is valid.
validateCustObjFields
-
custObj -
custObjType -
cb
Validates the fields of a custom object
Parameters:
-
custObjObjectThe object to validate
-
custObjTypeObjectThe custom object type to validate against
-
cbFunctionA callback that takes two parameters. The first is an error if occurred. The second is an array of validation error objects. If the array is empty it is safe to assume that the object is valid.
validateFieldDescriptor
-
field -
customTypes
Validates that the field descriptor for a custom object type.
Parameters:
-
fieldObject -
customTypesObject
Returns:
An array of objects that contain two properties: field and error
validateSortOrdering
-
sortOrder -
cb
Validates a sort ordering for custom objects of a specific type
Parameters:
-
sortOrderObject -
cbFunctionA callback that takes two parameters. The first is an error, if occurred and the second is an array of validation error objects. If the array is empty them it is safe to assume that the object is valid.
validateType
-
custObjType -
cb
Validates a Custom Object Type.
Parameters:
-
custObjTypeObjectThe object to validate
-
cbFunctionA callback function that provides two parameters: The first, an error, if exists. The second is an array of objects that represent validation errors. If the 2nd parameter is an empty array it is safe to assume that validation passed.
