Skip to content

ModelService

Mihael Safaric edited this page Aug 10, 2020 · 6 revisions

Your resource services must extend abstract ModelService class. ModelService gives a communication interface for HTTP requests.

constructor(protected datastore: DatastoreService, private modelClass: {new(...args): Model });

Methods

findOne

findOne(modelId: string, includeRelationships: Array<string | RelationshipRequestDescriptor>, requestOptions: RequestOptions = {}, subsequentRequestsOptions: RequestOptions): Observable<Model>
  • modelId: string

  • includeRelationships

  • requestOptions: RequestOptions

    • optional
    • additional request options
    • those options will be used only for the main request, custom options for relationship calls can be set via subsequentRequestsOptions
  • subsequentRequestsOptions: RequestOptions

    • optional
    • when specified, the specified request options will be used for the relationship calls which do not have request options specified through includeRelationships parameter
    • if the specific relationship has request options specified in includeRelationships, subsequentRequestsOptions will be ignored for that API call

find

find(params: object | { [param: string]: string | string[] } | HttpParams): Observable<Array<Model>>;
find(params: object | { [param: string]: string | string[] } | HttpParams, includeMeta: false): Observable<Array<Model>>;
find(params: object | { [param: string]: string | string[] } | HttpParams, includeMeta: true): Observable<HalDocument<Model>>;
find(params: object | { [param: string]: string | string[] } | HttpParams, includeMeta: boolean, includeRelationships: Array<string | RelationshipRequestDescriptor>, requestOptions: RequestOptions, subsequentRequestsOptions?: RequestOptions, customUrl?: string, storePartialModels?: string): Observable<HalDocument<Model>>;
  • params: object | { [param: string]: string | string[] } | HttpParams

    • optional
    • parameters which will be send in the request
      • requestOptions.params is ignored in favor of params (TODO: change that in future versions of the lib)
  • includeMeta: boolean

    • optional
    • if omitted or falsy, Observable<Array<Model>> is returned
    • if truthy, Observable<HalDocument<Model>> is returned (see HalDocument)
  • requestOptions: RequestOptions

    • optional
    • additional request options
    • those options will be used only for the main request, custom options for relationship calls can be set via subsequentRequestsOptions
    • requestOptions.params is ignored in favor of params (TODO: change that in future versions of the lib)
  • subsequentRequestsOptions: RequestOptions

    • optional
    • when specified, the specified request options will be used for the relationship calls which do not have request options specified through includeRelationships parameter
    • if the specific relationship has request options specified in includeRelationships, subsequentRequestsOptions will be ignored for that API call
  • storePartialModels: boolean

createNewModel

createNewModel(recordData: object = {}): Model
  • locally creates an instance of a model class which is passed through the constructor, modelClass
  • NOTE: it does not tigger saving of newly created model