I seem to be missing some properties in the request body schema. Why am I receiving an incomplete model for

Seeking assistance in grasping the working of models in loopback4. Here's a model I defined:

@model()
export class ProductViewConfig extends BaseConfig {
  @property({
    type: 'string',
    id: true,
    generated: true,
  })
  _id?: string;


  @property({
    type: 'array',
    itemType: 'object',
  })
  tiles: Array<TileOptions>;


  constructor(data?: Partial<ProductViewConfig>) {
    super(data);
  }
}

export interface ProductViewConfigRelations {
  // describe navigational properties here
}

export type ProductViewConfigWithRelations = ProductViewConfig & ProductViewConfigRelations;

The baseConfig class that it extends from has this structure:

@model({
  settings: {
    strict: true
  }
})
export class BaseConfig extends Entity {
  @property({
    type: 'object',
    required: true,
  })
  configMetadata: ConfigMetadata;

  @property({
    type: 'array',
    itemType: 'object',
  })
  sharedUsers: Array<SharedUsers>;

  @property({
    type: 'array',
    itemType: 'object',
  })
  sharedRoles: Array<SharedRoles>;

  constructor(data?: Partial<BaseConfig>) {
    super(data);
  }
}

export interface BaseConfigRelations {

  // describe navigational properties here
}

export type BaseConfigWithRelations = BaseConfig & BaseConfigRelations;

My ConfigMetadata Model is as follows:

@model({ settings: { strict: true } })
export class ConfigMetadata extends Entity {
  @property({
    type: 'string',
    required: true,
  })
  name: string;

  @property({
    type: 'string',
    required: true,
  })
  description: string;

  @property({
    type: 'date',
    required: true,
  })
  dateCreated: string;

  @property({
    type: 'date',
    required: true,
  })
  lastUpdatedOn: string;

  @property({
    type: 'string',
    required: true,
  })
  creatorId: string;

  @property({
    type: 'string',
    required: true,
  })
  creatorName: string;


  constructor(data?: Partial<ConfigMetadata>) {
    super(data);
  }
}

....

In my controller, there's a post endpoint with a request body using getModelSchemaRef(myObj)

 @post('/product-view-configs')
  @response(200, {
    description: 'ProductViewConfig model instance',
    content: { 'application/json': { schema: getModelSchemaRef(ProductViewConfig) } },
  })
  async create(
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(ProductViewConfig,
            {
              title: 'NewProductViewConfig',
            }),
        },
      },
    })
    productViewConfig: ProductViewConfig,
  ): Promise<ProductViewConfig> {

    return this.productViewConfigRepository.create(productViewConfig);
  }

Here's my question:

Why does the request body not match the expected object structure?

https://i.stack.imgur.com/jlM93.png

I expect the request body to look like this:

{
    "_id" : "string",
    "configMetadata" : {
       "name" : "string",
        "description" : "string",
        "createdOn" : "date",
        "lastUpdatedBy" : "date",
        "creatorId" : "string",
        "creatorName" : "string"
    },
    "sharedUsers" : [ 
        {...}
    ],
    "sharedRoles" : [ 
        {...}
    ],
    "tiles" : [ 
        {...}
    ]
}

So, why aren't the properties from baseConfig showing up? Any guidance would be appreciated as I couldn't find the answer in the loopback4 documentation! Thank you!

Answer №1

Utilizing relations is crucial for connecting models. Exploring concepts such as hasMany and hasOne within the loopback framework can be extremely beneficial in your research journey.

Explore more about relations in LoopBack

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using the concat operator along with the if statement in Angular to make sequential requests based on certain conditions

Managing multiple HTTP requests in a specific order is crucial for my event. To achieve this, I am utilizing the concat operator from rxjs. For instance, upon receiving data from the first request, I update local variables accordingly and proceed to the ne ...

Encountering an endless loop within a data rest API in a React application

Currently, I am in the process of learning React and attempting to utilize the Poke API with my application. Unfortunately, I seem to have run into an infinite loop issue and I am feeling quite lost in terms of troubleshooting it. Below is a snippet of my ...

Regular Expressions: Strategies for ensuring a secure password that meets specific criteria

Struggling to craft a regex for Angular Validators pattern on a password field with specific criteria: Minimum of 2 uppercase letters Minimum of 2 digits At least 1 special character. Currently able to validate each requirement individually (1 uppercase ...

What is the importance of including "declare var angular" while working with Typescript and AngularJS?

I've been working on an AngularJS 1.7 application that's coded entirely in TypeScript, and there's always been one thing bothering me. Within my app.module.ts file, I have this piece of code that doesn't sit right with me: declare va ...

What is the best way to send various parameters to a component using [routerLink] or router.navigate?

My app-routing.module.ts is configured as shown below: const routes: Routes = [ { path: "branches/:branch", component: BranchesComponent }, // ... ]; In addition, in my app.component.html, I have the following code: <li> ...

Pagination feature in MUI DataGrid table is malfunctioning

I'm struggling to get the pagination feature to work in my Material UI DataGrid component, but I'm hitting a roadblock: https://i.stack.imgur.com/eT7s7.gif The console is not showing any errors. Here is the code for my component: import { ...

Encountered a hiccup when attempting to include the DatePicker component in app.module.ts using

I'm encountering an issue with some providers in my app.module.ts file. Specifically, when trying to use the DatePicker component, I'm getting this error message: Type 'DatePickerOriginal' is not assignable to type 'Provider'. ...

Inheriting Angular components: How can the life cycle hooks of a parent component be triggered?

So I'm working with BaseComponent and a number of child components that extend it: export class Child1Component extends BaseComponent implements OnInit, AfterViewInit In the case of Child1Component, there is no explicit call to super.ngAfterViewInit ...

Implementing Typescript for React Navigation: Configuring navigationOptions effectively

Within a React Native app utilizing React Navigation, I am working on a screen component where I aim to set the title based on given parameters using the navigationOptions property like so: static navigationOptions = ({navigation}) => ({ title: nav ...

I am looking to personalize a Material UI button within a class component using TypeScript in Material UI v4. Can you provide guidance on how to achieve this customization?

const styling = { base: { background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)', border: 0, borderRadius: 3, boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)', color: 'white', height: 48, ...

What are the steps to troubleshoot a Node Package Manager library in Visual Studio Code?

I have created a Typescript library that I plan to use in various NodeJS projects. The source code is included in the NPM package, so when I install it in my projects, the source also gets added to the node_modules folder. Now, during debugging, I want to ...

Dividing a JSON object into arrays containing keys and values within an Angular framework

I have a code snippet that involves receiving a JSON object of type Tenant from an API. I need to separate this object into keys and values within my function called tenantParser(). However, when I try to log displayedValues and displayedKeys, both show ...

Retrieving display format or formatted value from an object with Moment.js

I am currently working on a project using Angular and Material2. Within this project, I have created a moment object in the following way: myDate = moment.utc(new Date()).format("YYYY-MM-DD HH:mm:ss"); This object is then passed as an argument to ano ...

Utilizing Pipes within a Method in Angular 2 along with Dependency Injection triggers an "Insufficient Number of Arguments" error

I am searching for a solution to incorporate a custom pipe into my class. The custom pipe itself ( referenced from this source, many thanks ) involves injecting a dependency (the DomSanitizationService). import { Pipe, Inject, Injectable } from '@ang ...

Stop Node Modules from Referencing Global Location

Recently, I ran into an issue after updating my project from Git. The problem arose when trying to use ngx-material-timepicker in conjunction with the luxon library. (It's important to note that ngx-material-timepicker isn't a new addition to th ...

Enhancing React with TypeScript: Best Practices for Handling Context Default Values

As I dive into learning React, TypeScript, and Context / Hooks, I have decided to create a simple Todo app to practice. However, I'm finding the process of setting up the context to be quite tedious. For instance, every time I need to make a change t ...

Troubleshooting a child process created by electron in Visual Studio Code

I am currently in the process of developing an electron application using typescript and webpack. I have encountered a specific debugging issue with vscode that I would like some assistance with: Context: The main process initiates a child process by call ...

The problem with MUI SwipeableDrawer not being recognized as a JSX.Element

Currently, I am implementing the SwipeableDrawer component in my project. However, an issue arises during the build process specifically related to the typings. I have made the effort to update both @types/react and @types/react-dom to version 18, but unf ...

Utilizing type arguments in JSX components when applying withStyles

When working with React and material-ui, I am attempting to create a JSX component that can accept generic parameters while also utilizing the withStyles Higher Order Component (HOC) to inject styles. The initial approach looked something like this: cons ...

Tips for retrieving both the ID and NAME values from Ionic's Dynamic Select Options

In my Ionic 3 project, I have successfully implemented a dynamic select option. However, I am facing an issue where I can only retrieve either the ID or the Name value of the selected option from the server, but not both. I have tried using JSON.parse and ...