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:
-
custObjects
ArrayThe array of custom objects to be sorted
-
sortOrder
ObjectThe 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:
-
type
Object | StringThe custom object type object or ID string
-
[where]
Object optionalThe criteria for which objects to count
-
cb
FunctionA 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:
-
errors
ArrayAn array of objects where each object has a "msg" and a "field" property
-
msg
String
Returns:
HTML formatted string representing the errors
deleteById
-
id
-
cb
Deletes a custom object by ID
Parameters:
-
id
String -
cb
Function(Error, *)
deleteForType
-
custObjType
-
cb
Deletes all custom objects of a specified type
Parameters:
-
custObjType
String | ObjectA string ID of the custom object type or the custom object type itself.
-
cb
Function(Error, *)
deleteTypeById
-
id
-
[options={}]
-
cb
Deletes a custom object type by id
Parameters:
-
id
String | ObjectID -
[options={}]
Object optional -
cb
Function(Error, *)
err
-
field
-
err
Creates a validation error field
Parameters:
-
field
StringThe field in the object that contains the error
-
err
StringA 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:
-
custObj
ObjectThe custom object to inspect
-
options
ObjectThe options specified for the retrieval
-
fetch_depth
IntegerThe number of levels of peer and child objects to retrieve
-
-
custObjType
Object | StringThe custom object type for the specified custom object. This can also be the ID string value.
-
cb
FunctionA 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:
-
type
Object | StringThe custom object type object or the ID of the object as a string
-
[options]
Object optionalSee DAO.q()
-
cb
FunctionA 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:
-
custObjType
Object | 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.
-
-
cb
FunctionA 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:
-
cb
FunctionA 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:
-
post
ObjectThe raw post object
-
custObjType
ObjectThe custom object type describes the data in the post obj.
formatRawSortOrdering
-
post
-
sortOrder
Formats the raw post data for a sort ordering
Parameters:
-
post
Object -
sortOrder
Objectthe 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:
-
name
String
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:
-
cb
FunctionA 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:
-
objType
String
Returns:
isReferenceFieldType
-
fieldType
Determines if a field type is reference to another object type
Parameters:
-
fieldType
String
Returns:
loadBy
-
type
-
where
-
[options]
-
cb
Loads a custom object by the specified where criteria
Parameters:
-
type
String | Null -
where
Object -
[options]
Object optional -
cb
Function
loadById
-
id
-
[options]
-
cb
Loads a custom object by ID
Parameters:
-
id
ObjectID | String -
[options]
Object optional -
cb
Function
loadByName
-
type
-
name
-
[options]
-
cb
Loads a custom object by name
Parameters:
-
type
StringThe ID string of the custom object type
-
name
StringThe unique name of the custom object
-
[options]
Object optional -
cb
Function
loadSortOrdering
-
custObjType
-
cb
Loads an ordering object for a specific custom object type.
Parameters:
-
custObjType
Object | String -
cb
FunctionA 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:
-
where
Object -
cb
Function
loadTypeById
-
id
-
cb
Loads a custom object type by ID
Parameters:
-
id
ObjectID | String -
cb
Function
loadTypeByName
-
name
-
cb
Loads a custom object type by name
Parameters:
-
name
String -
cb
Function
save
-
custObj
-
custObjType
-
cb
Validates and persists a custom object
Parameters:
-
custObj
ObjectThe object to validate
-
custObjType
ObjectThe custom object type to validate against
-
cb
FunctionA 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:
-
sortOrder
Object -
cb
Function
saveType
-
custObjType
-
cb
Validates and persists a custom object type
Parameters:
-
custObjType
ObjectThe object to persist
-
cb
FunctionA 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:
-
custObjTypes
ArrayThe array of custom object type objects to inspect
-
ls
Localization
typeExists
-
typeName
-
cb
Determines if a custom object type with the specified name (case insensitive) exists
Parameters:
-
typeName
String -
cb
Function(Error, Boolean)
validate
-
custObj
-
custObjType
-
cb
Validates a custom object
Parameters:
-
custObj
ObjectThe object to validate
-
custObjType
ObjectThe custom object type to validate against
-
cb
FunctionA 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:
-
custObj
ObjectThe object to validate
-
custObjType
ObjectThe custom object type to validate against
-
cb
FunctionA 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:
-
field
Object -
customTypes
Object
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:
-
sortOrder
Object -
cb
FunctionA 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:
-
custObjType
ObjectThe object to validate
-
cb
FunctionA 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.