API Docs for: 0.8.0
Show:

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

()

Methods

applyOrder

(
  • custObjects
  • sortOrder
)
Array static

Orders the custom objects based on the provided sort order

Parameters:

  • custObjects Array

    The array of custom objects to be sorted

  • sortOrder Object

    The object describing the ordering of the objects

Returns:

Array:

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 | String

    The custom object type object or ID string

  • [where] Object optional

    The criteria for which objects to count

  • cb Function

    A 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
)
String static

Creates an HTML formatted error string out of an array of error objects.

Parameters:

  • errors Array

    An array of objects where each object has a "msg" and a "field" property

  • msg String

Returns:

String:

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 | Object

    A 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
)
Object static

Creates a validation error field

Parameters:

  • field String

    The field in the object that contains the error

  • err String

    A string description of the error

Returns:

Object:

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 Object

    The custom object to inspect

  • options Object

    The options specified for the retrieval

    • fetch_depth Integer

      The number of levels of peer and child objects to retrieve

  • custObjType Object | String

    The custom object type for the specified custom object. This can also be the ID string value.

  • cb Function

    A 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 | String

    The custom object type object or the ID of the object as a string

  • [options] Object optional

    See DAO.q()

  • cb Function

    A 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 | String

    The custom object type descriptor object or the ID string of the type descriptor.

  • [options={}] Object optional

    The filters and other flags. The options object supports the same fields as the DAO.query function.

    • [fetch_depth=0] Integer optional

      The 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 Function

    A 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 Function

    A 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
)
static

Formats the object by ensuring that each field is in the correct data type.

Parameters:

  • post Object

    The raw post object

  • custObjType Object

    The custom object type describes the data in the post obj.

formatRawSortOrdering

(
  • post
  • sortOrder
)
Object static

Formats the raw post data for a sort ordering

Parameters:

  • post Object
  • sortOrder Object

    the existing sort order object that the post data will be merged with

Returns:

Object:

The formatted sort ordering object

getCustTypeSimpleName

(
  • name
)
String static

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:

String:

getFieldTypes

() Array static

Provides the various types of fields that are allowed for a custom object (number, boolean, string, etc).

Returns:

Array:

getReferenceTypes

(
  • cb
)

Retrieves an array of all of the available object types that can be referenced as a child or peer object.

Parameters:

  • cb Function

    A 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:

Array:

isCustomObjectType

(
  • objType
)
Boolean static

Determines if the field type is a custom object type or a system reference

Parameters:

  • objType String

Returns:

Boolean:

isReferenceFieldType

(
  • fieldType
)
Boolean static

Determines if a field type is reference to another object type

Parameters:

  • fieldType String

Returns:

Boolean:

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 String

    The ID string of the custom object type

  • name String

    The 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 Function

    A 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 Object

    The object to validate

  • custObjType Object

    The custom object type to validate against

  • cb Function

    A 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 Object

    The object to persist

  • cb Function

    A 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
)
static

Discovers the field types used for each entry in the provided array and sets the "fieldTypesUsed" property for the object.

Parameters:

  • custObjTypes Array

    The 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 Object

    The object to validate

  • custObjType Object

    The custom object type to validate against

  • cb Function

    A 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 Object

    The object to validate

  • custObjType Object

    The custom object type to validate against

  • cb Function

    A 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
)
Array

Validates that the field descriptor for a custom object type.

Parameters:

  • field Object
  • customTypes Object

Returns:

Array:

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 Function

    A 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 Object

    The object to validate

  • cb Function

    A 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.

Properties

AVAILABLE_FIELD_TYPES

Object private static

AVAILABLE_REFERENCE_TYPES

Object private static

CHILD_OBJECTS_TYPE

String private static

CUST_OBJ_COLL

String static

CUST_OBJ_SORT_COLL

String static

CUST_OBJ_TYPE_COLL

String static

CUST_OBJ_TYPE_PREFIX

String private static

NAME_FIELD

String private static

PEER_OBJECT_TYPE

String private static