PopulatedDoc

Describes how to deal with a cosmos db field type of PopulatedDoc

Cosmos DB Model

/infrastructure/data-sources/cosmos-db/models/physician.ts
updatedBy: PopulatedDoc<Account>;

Domain Props

/domain/contexts/physician/physician.ts
readonly updatedBy: AccountProps;
setUpdatedByRef: (updatedBy: AccountEntityReference) => void;
  • Every PopulatedDoc field needs the read-only field with props type and a setRef field which is a method that takes in an entity reference of the domain object referenced in previous field

  • The argument of setRef method should be the same as the name of the field above it

Domain Entity Reference

/domain/contexts/physician/physician.ts
export interface PhysicianEntityReference 
extends Readonly<
    Omit<
        PhysicianProps,
        "updatedBy" | "setUpdatedByRef"
        >
    > {
    readonly updatedBy: AccountEntityReference;
}
  • Note: must include field name and setRef method name in the omit union of strings

Domain Class

Getter

/domain/contexts/physician/physician.ts
get updatedBy(): AccountEntityReference {
    return new Account(this.props.updatedBy, this.context);
}

Setter

/domain/contexts/physician/physician.ts
public requestSetUpdatedBy(updatedBy: AccountEntityReference) {
    this.setUpdatedByRef(updatedBy);
}
  • setRef method comes from field defined in Domain Props

  • Note: setRef method takes in entity reference of domain object as an argument

Domain Adapter

Getter

/domain/infrastructure/persistence/physician.domain-adapter.ts
get updatedBy(): AccountProps {
    if (this.doc.updatedBy) {
        return new AccountDomainAdapter(this.doc.updatedBy);
    }
}

Setter

/domain/infrastructure/persistence/physician.domain-adapter.ts
setUpdatedByRef(updatedBy: AccountEntityReference) {
    this.doc.set("updatedBy", updatedBy["props"]["doc"]);
}
  • Needs a setter for the setRef method created in domain props

  • takes in entity reference of domain object being stored in that field

  • Note: use exactly the notation below for setting the doc: first argument is the field name as a string and the second is the argument being passed in to the function with square bracket notation accessing the doc of that domain object

Last updated