What is the best way to standardize data using normalizr?

After receiving the User object:

{
  "id": "123",
  "username": "TestUser",
  "group": 
    {
      "id": "324",
      "name": "My Group"
    }
}

I am interested in executing: normalize(user);

Is it possible to achieve this result? I want to separate the group from the user and store it as a different entity.

{
  result: "123",
  entities: {
    "users": { 
      "123": { 
        id: "123",
        group: "1",
        username: "TestUser
      }
    },  
    "groups": {
      "1": { "id": "324", "name": "My Group" },
    }
  }
}

I need help defining the schemas for this desired outcome.

Answer №1

Finally understood the solution. It's actually quite simple.

const team = new schema.Entity('teams', {}, {
  keyAttribute: 'key'
});

const player = new schema.Entity(
  'players',
  {
    team: team
  },
  {
    keyAttribute: 'key'
  }
);

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

Issue with React's handleChange function in two separate components

I need assistance with calling the event handleChange from a second Component This is my principal component: const [mainState, setMainState] = useState({ stepValue: 1, saleDateVal: new Date(), customerVal: '' }); function moveNextStep() { ...

What is the best way to ensure my fetchMovieDescription function is executed only after the story state has been updated?

I am facing a challenge with the fetchMovieDescription function. It is being called simultaneously with fetchBotReply instead of after my story state is updated. As a result, it generates a random image rather than using the one from the story result. impo ...

Execute a series of repetitive HTTP GET requests and remain patient for all of them to complete

I am working with a REST service that provides a list of 'Json' objects, where each object may contain a link to another resource of the same class. To fetch all these resources recursively starting from a specific one, I have written the followi ...

Building a Node.js view to display an OpenLayers map

I'm new to working with node.js and am currently trying to incorporate an OpenLayers map onto a webpage. However, I'm facing an issue where the map is not displaying as expected. Code: app.js var express = require('express'); var ap ...

v-for loop to populate dropdown menu with identical values

Recently, I started working on a points counter app using Vue.js and encountered some issues with the v-for loop and dropdown menu functionality. Within my Vue.js application, I have an array of players as shown below: var app = new Vue({ el: '#l ...

iOS CORS ajax request is stuck at state 0 during processing

I am facing an issue with making a CORS login AJAX call from my iPhone using $.ajax. The request fails and reaches the fail callback, showing the jqXHR object state as: { readyState: 0, status: 0, statusText: "error" } Strangely, on my PC the request ...

Steps for choosing all choices in a multi-select menu without changing the order

What is the best way to choose all the options from a multiselect box using Java Script? ...

Utilizing $index in AngularJS while iterating through ng-repeat items

Here is an example of an unordered list: <ul class="dropdown-menu inner" role="menu"> <li ng-repeat="availableAlphaName in availableAlphaNames" data-original-index="0" data-optgroup="1" class=""> <a tabindex="0" class="opt " st ...

The lazy loading feature in Jquery seems to be malfunctioning silently without displaying any errors in the console

I have added a Jquery loader to my function that is triggered on button click. Here is an example of the code: function fnLoadVendorData() { var vendorSel = $("#ddlVendorName option:selected").text(); var strCircle = $("#lblRole").text(); ...

Attempting to establish an Observable in Angular 2/4 by subscribing to a JavaScript array object

I have a Service file where I am attempting to set as an observable, with a component that I would like to subscribe to it. Unfortunately, it doesn't seem to be working as expected. Can you please help me figure out what I am doing wrong? Service: Tr ...

Track the Mouse with Three.js - Dynamic Object Movement

I'm currently working on a Three.js project where I need to create a sphere that follows the mouse cursor, similar to the functionality demonstrated in this example. The code snippet responsible for handling the mouse movement is as follows: function ...

I'm facing an issue here: the function this.props.onSave is not defined

One issue I am facing is that the save action is not functioning properly. Function to handle save : handleSave = () => { this.setState({ loading: true }) const { category } = this.state this.props.onSave(category) } Save action button ...

Can I restrict the translation of the educational institution's name on my website into a different language?

As I develop a website for a training facility, I have encountered an issue with the translated versions of the site. The training center's name is in English, and when the site is translated into another language, it alters the appearance of the name ...

Reflecting feature for performing the reverse action

For my event, I need to fade out my music gradually. $(bgMusic).on('timeupdate', function () { var vol = 1, interval = 250; if (bgMusic.volume == 1) { var intervalID = setInterval(function () { if (vol > ...

Issue with Vue Loading Overlay Component functionality in nuxt2 .0

I've integrated the vue-loading-overlay plugin into my project. plugins/vueloadingoverlaylibrary.js import Vue from 'vue'; import Loading from 'vue-loading-overlay'; // import 'vue-loading-overlay/dist/vue-loading.css'; ...

Sending asynchronous requests to handle data within various functions based on different links

I'm currently facing a major roadblock when it comes to resolving my issues with callbacks. I've gone through resources like How to return value from an asynchronous callback function? and How to return the response from an Ajax call?, among seve ...

Steps for generating a current date and a date one year in the past

In my WebService, I need to update the DATEFIN to today's date and the DATEDEBUT to a date that is one year prior. Currently, the setup looks like this: see image here At the moment, I am manually inputting the dates. How can I automate this proces ...

Aligning a div in the middle of an absolutely positioned div vertically

Currently, I am facing an issue with the layout of my website's main body content section. There is a specific element positioned absolutely towards the bottom, with some space between it and the footer. I have tried various approaches and exhausted ...

Troubleshooting a Compatibility Problem Between Django and JavaScript

I am trying to dynamically insert a variable into a URL within the code snippet provided, but I keep encountering an error. function initializeDataTable(id){ var columnSize = $('table th').size(); $('#table').dataTable({ ...

Having trouble with an unexpected value in your Angular2 Service? Don't forget to add

I encountered an error in my Angular2 app: Error: (SystemJS) Unexpected value 'ReleasesService' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation. Here is my AppModule code: import { NgModule } fr ...