Unable to store a customized class object in Parse database

I have been attempting to create a Customer class object that is linked one-to-one with the User class. However, despite my efforts, the object does not save and no error message appears. Here is the code I am working with:

 Parse.Cloud.afterSave(Parse.User, function(request) {
 user = request.object;
 role_name = user.get("role_name");
 user_name = user.get("user_name");
 user_id = user.get("objectId");

  if (role_name == "customer"){
    user = request.object;
    console.log(" I am inside if else");

    var Customer = Parse.Object.extend("Customer");
    var cus = new Customer();
    cus.set("name2" , "albert")
    var relation = cus.relation("userId");
    relation.add(user);
    cus.save(); // Saving the Customer object should take place here 

    cus.save(null, {
    success: function(cus) {
        // Implement any logic that needs to occur after object is saved.
        console.log("I am working")
        alert('New object created with objectId: ' + cus.objectId);
    },
      error: function(error) {
        // handleParseError(error);
        console.log(error)
        // Implementation of any necessary logic in case of save failure.
        // error represents a Parse.Error with an error code and message.
      }
    });
  }

});

Output received upon running this code:

  after_save triggered for _User for user qu808uKOgt:
  Input: {"object":{"createdAt":"2015-10-11T18:36:07.661Z","objectId":"qu808uKOgt","phone":"5678956475","role_name":"customer","updatedAt":"2015-10-11T18:36:07.661Z","username":"newuser16"}}
  Result: Success
  I am inside if else
  {"name2":"apple","userId":{"__op":"AddRelation","objects":      [{"__type":"Pointer","className":"_User","objectId":"qu808uKOgt"}]}}

Answer №1

To rectify this issue, I implemented a new cloud function that triggers immediately after the user signs up.

Parse.Cloud.define('functionName', function(request, response){
  var currentUser = Parse.User.current();
  var role_name =  currentUser.get("role_name");

  if (role_name == "customer"){
  // Implement customer-specific actions
  }
  else if (role_name == "service_provider"){
  // Implement service provider-specific actions 
  }
)};

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 is the best way to determine if a value from my array is present within a different object?

I have an array with oid and name data that I need to compare against an object to see if the oid value exists within it. Here is the array: const values = [ { "oid": "nbfwm6zz3d3s00", "name": "" ...

Switch the paper tab to a dropdown menu in Polymer.js

Can someone assist me in transforming the paper tab into a paper drop down menu in polymer JS? I want the drop-down to appear with a list of values when hovering over the Top menu. Activity Execution <paper-tab cla ...

Learn how to effectively declare data as global within Angular2 or Typescript

I am facing an issue with fetching the id inside the Apiservice despite being able to get it in the console. Can anyone provide assistance on how to solve this problem? TS: deleteProduct(index,product) { var token = this.auth.getAccessTokenId(); ...

What is the best way to concatenate a data object?

This task should be quite straightforward. Using Vanilla JS, I am trying to update the content of a span element with the session ID obtained from a function call. Here's an example: sessionId = 0_77b1f7b5-b6c8-49a0-adbc-7883d662ebba document.getEle ...

Encountering an unusual error while utilizing the Rails 3 form_for with the :remote option set to true

Encountering an error and seeking assistance: try { Element.update("status", "There seems to be an issue with this product."); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.update(\"status\", &bsol ...

Can you explain the meaning of the symbol '&$checked'?

import React from 'react'; import Checkbox from '@material-ui/core/Checkbox'; import { createMuiTheme, makeStyles, ThemeProvider } from '@material-ui/core/styles'; import { orange } from '@material-ui/core/colors'; ...

Set the display property of all child elements within the DIV to none

CSS <div class="container"> <span></span> <input type="text"> </div> JavaScript function hideElements(){ let container = document.querySelector(".container"); let elements = ...

Ways to validate an element in an Array using Cypress dynamically

I have a question regarding the dynamic verification of Array elements. For my project, I need to suggest a price that will increase over time, and I require a script that can verify these elements dynamically. In the screenshot provided, you can see what ...

Tips for referencing a string in JavaScript

I am trying to use the showmodal method, but I keep getting an error when passing a string. It works fine with integers, but how can I pass a string in JavaScript? <script> var table = ' <table id="example" class="table table-striped " w ...

Creating a simulated class within a function utilizing Jest

Currently, I am in the process of testing a controller that utilizes a class which functions like a Model. const getAllProductInfo = (request, response) => { const productInformation = new ProductModel().getAll(); response.status(200) resp ...

Locate items that possess identical property values and append them to a new array as a property

I am dealing with an array containing objects that have a specific property called "operationGroup" with the sub-property "groupId". Here is an example of the array structure: [{ operation: 11111, operationGroup: null }, { operation: 22222, ...

Solve problems with limitations on ng2-dnd drop zones

I successfully integrated drag and drop capabilities into my Angular 4 application using the ng2-dnd library. Within my application, I have containers that can be sorted, as well as individual items within each container that can also be sorted. My goal i ...

Encountering excessive re-renders while using MUI and styled components

Hey there! I recently worked on a project where I used MUI (Material-UI) and styled-components to render a webpage. To ensure responsiveness, I made use of the useTheme and useMediaQuery hooks in my web application. My goal was to adjust the font size for ...

Styled-components causing issues with conditional rendering

Within my React component, I have multiple properties and I want styles to only apply if a property has a value. I attempted the following code: export const Text = ({text, color, size, fontFamily}) => { const StyledParagraph = styled.p` m ...

Numerous links were chosen and multiple div elements were displayed on the screen

Currently, I have a setup where selecting one div will show its content. However, I am looking to enhance this by allowing multiple divs to be displayed simultaneously. For example, if 'Div 1' is selected and shown, I want the content of 'Di ...

Step-by-step guide on inserting a div element or hotspot within a 360 panorama image using three.js

As I work on creating a virtual tour using 360 images, I am looking to include hotspots or div elements within the image that can be clicked. How can I store data in my database from the event values such as angle value, event.clientX, and event.clientY wh ...

Preventing value alteration when input is blank

I recently wrote this code snippet for a form I was designing: <div class="col-md-6"> <label class="labels">Birthday:</label> <input method="POST" name="birthdate" class="form-contro ...

Overflow of Primary Text in Material UI List Item

I apologize if this question has already been asked, but I have searched and couldn't find the solution! I am facing an issue with a Material UI listview that has a fixed width within a sidebar. The titles of some options are not properly rendering a ...

While building with Next.js, a ReferenceError may occur if the sessionStorage is not defined

While using Next.js 13 App router, I encountered an issue with storing the JWT token received upon login in session storage. It all worked smoothly when accessing the token in my page.js pages across different routes as long as the page was a client compon ...

Using jQuery AJAX to add to a JSON response with the value "d:null"

Hey everyone, I'm encountering a strange issue with my callback function when using the AJAX POST method to call my webservice. The JSON response from the webservice looks like this: Dim ser As New System.Web.Script.Serialization.JavaScriptSerialize ...