I am uncertain about the current status of this project; it functions correctly on my local machine but is encountering issues when deployed on the server

I'm facing an issue while transferring a project from local to server. The project works fine locally but not on the server, specifically when I try to edit products. The database is not displaying the correct information, as it shows two crucial numbers as 0 even though they are not supposed to be 0 in the database. These numbers are essential for calculating the price.

Here is the information being displayed for a product:

[ { "country": { "id": 1, "name": "COSTA RICA", "currency_symbol": "CRC" }, "country_id": 1, "margin": 0, "fi": 0 }, 
{ "country": { "id": 2, "name": "NICARAGUA", "currency_symbol": "COR" }, "country_id": 2, "margin": 0, "fi": 0 }, 
{ "country": { "id": 3, "name": "HONDURAS", "currency_symbol": "HNL" }, "country_id": 3, "margin": 0, "fi": 0 } ]

However, in the database, the product should have the following margin and fi values:

product_id: 1
country_id: 1
margin: 0.65
fi: 0.50

product_id: 1
country_id: 2
margin: 0.65
fi: 0.50

product_id: 1
country_id: 3
margin: 0.65
fi: 0.50

The edit product function is supposed to mirror the create model, but for some reason, it is not displaying the correct information.

Below is the function responsible for opening the create and edit dialogs:

showDialog(model) {
    // Function code here
}

What could be causing this discrepancy between the local environment and the server?

Answer №1

It seems like there could be an issue with how you are comparing values in the filter function. To resolve this, consider parsing the IDs into integers when comparing them. Here is a corrected version of your _formatModel function:

_formatModel(model) {
this.productCategories = [];

this.loadingResource = true;
this.$http.post(this.baseUrl + '/show/' + model.id).then(
    (res) => {
        this.model.export_factors = this.countries.map((country) => {
        let result = res.body.export_factors.filter((item) => parseInt(item.country_id) === parseInt(country.id));
        let margin = 0;
        let fi = 0;

        if (result.length > 0) {
            margin = result[0].margin;
            fi = result[0].fi;
        }
        return {
            country: country,
            country_id: country.id,
            margin: margin,
            fi: fi,
        }
    });
    this.model.prices = this.countries.map((country) => {
        let result = res.body.prices.filter((item) => parseInt(item.country_id) === parseInt(country.id));
        let resultExport = res.body.export_factors.filter((item) => parseInt(item.country_id) === parseInt(country.id));
        let price = 0;

        if (result.length > 0) {
            price = (this.form.cif / resultExport[0].margin) / resultExport[0].fi;
        }
        return {
            country: country,
            country_id: country.id,
            price: price.toFixed(2),
        }
    });
    this.productCategories = res.body.categories.map((category) => {
        category.fields = category.fields.map(item => {
            item.allFields = [item.field];
            return item;
        });
        return category;
    });
    this.form.tags = res.body.tags;
    this.form.sizes = res.body.sizes;
    this.loadingResource = false;
},
(res) => {
    this.loadingResource = false;
    this.dialogVisible = false;
    this.$message.error(parseError(res)[0])
}

) },

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

What are the steps to utilize an npm package effectively?

Although I have a great appreciation for npm and nodejs, I am struggling to understand css, let alone JavaScript. I know that this is a big part of the problem. My main question is: when I use npm to install a package, how can I Find ALL available comma ...

Problem with OnClick function in Firefox

I have implemented the following code in an external JavaScript file: $( document ).ready(function() { var elem='<img class="imgload" src="/common/images/spinLoader/transperent.png">'; $('.imgchange').append(elem); }); $(func ...

I'm looking to achieve a horizontal wrapping alignment of cards in Vuetify 2. How can I accomplish this?

In my current project using vuetify 2, I am facing an issue where all my cards are displaying vertically within a col of width 7 instead of in a horizontal overflow. My goal is to have the cards arranged vertically with five counts on each row, and any ov ...

To utilize the span and input text increment functionality, simply use the required input type number and hold either the up or down arrow

Is it possible to increment the value of an input type number by 1 when holding down on a mobile device? <input type="text" id="number" value="1"> <span id="upSpan"> Up </span> $('#upSpan').on('touchstart', function ...

Mastering the ins and outs of ngStorage in AngularJS

Imagine a web page featuring a form that allows users to input multiple entries before submitting. As each entry is added, a summary of the data entered is displayed in a table at the top. Once all entries are completed, the user can then proceed to submit ...

"Implementing conditional evaluation for pixel units in AngularJS using ng-style

Looking to adjust the style of an element based on its height. For example, if the height is less than X, apply 'style 1'; otherwise, apply 'style 2'. The syntax appears to be correct, but accurately evaluating the height property in p ...

Guide to delivering a PDF document from a controller

In my pursuit to send a PDF file from a Controller Endpoint using NestJs, I encountered an interesting issue. Without setting the Content-type header, the data returned by getDocumentFile function is successfully delivered to the user. However, when I do ...

Discovering a particular element involves iterating through the results returned by the findElements method in JavaScript

I am attempting to locate and interact with a specific item by comparing text from a list of items. The element distinguished by .list_of_items is a ul that consists of a list of li>a elements. I am uncertain about how to transfer the determined elemen ...

Error occurred during Apple Login using Next_Auth: OAuthCallback issue

Attempting to log in with Apple using NextAuth. Authentication is successful, but it redirects to /?error=OAuthCallback. The URL being used is: https://appleid.apple.com/auth/authorize?client_id=com.wheeleasy.org&scope=name%20email&response_type= ...

What is the best approach for making a drawer resizable?

I am interested in making the material ui drawer resizable width using a draggable handle. Currently, I have implemented a solution that involves adding a mouse event listener to the entire application and updating the width based on the position of the ...

Lost item phenomenon: conceal information below until it emerges

I'm attempting to create a garage door effect on my website, where upon loading the page, a garage door is displayed. Upon hovering over the door, it lifts up to reveal the content behind it. The challenge I'm facing is keeping the content hidden ...

Placing a dropdown menu on top of an image

I currently have a slightly rotated menu bar with two buttons as an example: https://i.stack.imgur.com/0sI2P.jpg Due to the rotation, normal HTML handling is not feasible. I am considering using a <map> element to create hyperlinks over the menu it ...

Steps for initiating a $.ajax POST request from a client to a server

Currently, I am working on a phonegap application where I need to transfer some data from an HTML file to a server and receive a response in return. Everything works fine when all the files are on the same server. However, once I separate the files between ...

Setting headers in Node.js after they have already been sent to the client is not allowed

I'm currently enrolled in a node.js course on Udemy which seems to be outdated. I've encountered some errors that I'm struggling to resolve. Here's what I've tried so far: using next(); adding return res inside all if statements ...

Mapping URLs to objects in JavaScript, TypeScript, and Angular4

I have implemented a class called SearchFilter class SearchFilter { constructor(bucket: string, pin: number, qty: number, category: string) { } } When the user performs a search, I populate the filter i ...

When using `shallowMount` in @Vue/test-utils, it displays the message "[Vue warn]: Unknown custom element" when working with Vuetify

When running my unit test in Vue, I encounter a warning message that appears not only for <v-col>, but for every Vuetify component: [Vue warn]: Unknown custom element: < v-col> - did you register the component correctly? For recursive comp ...

React Router relies on a DOM for Browser History to function properly

I am currently developing my app using React.js and express. My main focus right now is setting up react-router-dom for the application. Unfortunately, I encountered a warning when attempting to run the app: Invariant Violation: Browser history needs a ...

Error: Unable to locate module '@/components/Header' in Next.js project

I'm currently facing an issue while working on my Next.js project. The problem arises when I attempt to import a component into my 'page.js' file. In the 'src' folder, I have a subdirectory named 'components' which contai ...

Guide on creating a cookie in express following a successful API call

Throughout my entire application, I utilize the /api route to conceal the actual API URL and proxy it in express using the following code: // Proxy api calls app.use('/api', function (req, res) { let url = config.API_HOST + req.url // This ret ...

Managing State with Vuex: Storing Getter Results in the State

I'm encountering an issue with my Vuex.Store: My goal is to retrieve an object (getter.getRecipe) by using two state entries as search criteria (state.array & state.selected) through a getter. Then, I want to store the outcome in my state (state. ...