Skip to content

@sourceloop/core / Exports / HasOneRestResolver

Class: HasOneRestResolver<Source, Target>

Type parameters

Name Type
Source extends Entity
Target extends Entity

Implements

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new HasOneRestResolver<Source, Target>(context)

Type parameters

Name Type
Source extends Entity<Source>
Target extends Entity<Target>

Parameters

Name Type
context Context

Defined in

packages/core/src/components/proxy-builder/services/rest-resolvers/has-one-resolver.service.ts:29

Properties

context

Private context: Context

Defined in

packages/core/src/components/proxy-builder/services/rest-resolvers/has-one-resolver.service.ts:31


type

type: RelationType = RelationType.hasOne

Implementation of

IRestResolver.type

Defined in

packages/core/src/components/proxy-builder/services/rest-resolvers/has-one-resolver.service.ts:28

Methods

addConditionToScope

Private addConditionToScope(keyTo, ids, scope?): Promise<{ where: Where<AnyObject> }>

Parameters

Name Type
keyTo keyof Target
ids Source[keyof Source][]
scope? Filter<Target>

Returns

Promise<{ where: Where<AnyObject> }>

Defined in

packages/core/src/components/proxy-builder/services/rest-resolvers/has-one-resolver.service.ts:98


findRelatedData

Private findRelatedData(service, filter, token?, config?): Promise<Target[]>

Parameters

Name Type
service ModifiedRestService<Target>
filter Filter<Target>
token? string
config? RestRelationConfig

Returns

Promise<Target[]>

Defined in

packages/core/src/components/proxy-builder/services/rest-resolvers/has-one-resolver.service.ts:116


getKeyFrom

Private getKeyFrom(relationMetadata): keyof Source

Parameters

Name Type
relationMetadata HasOneDefinition

Returns

keyof Source

Defined in

packages/core/src/components/proxy-builder/services/rest-resolvers/has-one-resolver.service.ts:125


getService

Private getService(config): Promise<ModifiedRestService<Target>>

Parameters

Name Type
config RestRelationConfig

Returns

Promise<ModifiedRestService<Target>>

Defined in

packages/core/src/components/proxy-builder/services/rest-resolvers/has-one-resolver.service.ts:142


link(-): Promise<Source>

It takes a parent object, looks up the foreign key on the parent, and then uses that foreign key to look up and link the related object in the resolvedDataMap

Parameters

Name Type Description
- RestLinkerParams<Source, Target> & { relationMetadata: HasOneDefinition } relationMetadata is the metadata for the relation being linked.

Returns

Promise<Source>

The parent object with the relationName property set to the resolvedDataMap.get(parent[keyFrom])

Implementation of

IRestResolver.link

Defined in

packages/core/src/components/proxy-builder/services/rest-resolvers/has-one-resolver.service.ts:83


resolve

resolve(-): Promise<Map<Target[keyof Target] | Source[keyof Source], Target>>

It takes the results of the query, finds the foreign key in each result, and then uses that key to find the related record in the related service

Parameters

Name Type Description
- RestResolverParams<Source, Target> & { relationMetadata: HasOneDefinition } relationConfig is the configuration object for the relation.

Returns

Promise<Map<Target[keyof Target] | Source[keyof Source], Target>>

A map of related records.

Implementation of

IRestResolver.resolve

Defined in

packages/core/src/components/proxy-builder/services/rest-resolvers/has-one-resolver.service.ts:39


toPascalCase

Private toPascalCase(str): string

Parameters

Name Type
str string

Returns

string

Defined in

packages/core/src/components/proxy-builder/services/rest-resolvers/has-one-resolver.service.ts:134