Tips for handling Google Spanner Date type in JavaScript

I am facing a challenge with Google Cloud Spanner as I work with multiple tables containing columns of type Date. While inserting entries with specified dates works fine, the issue arises when trying to retrieve these entries in the JavaScript frontend. The problem lies in understanding the format of these date fields.

My Google Cloud Functions code retrieves a customer from the database in the following manner:

async function fetch(database, query) {
  query.json = true;
  try {
    const [rows] = await database.run(query);
    return rows;
  } catch (error) {
    console.error("ERROR:", error);
    throw error;
  } finally {
    database.close();
  }
}

exports.fetchCustomer = functions.https.onCall(async (data, context) => {
  const database = instance.database(data.dataset);
  let address = fetch(database, {
    sql: `SELECT * FROM addresses WHERE addressId = '${data.id}'`,
  });
  let customer = fetch(database, {
    sql: `SELECT * FROM customers WHERE customerId = '${data.id}'`,
  });

  try {
    [address, customer] =
      await Promise.all([address, customer]);
    return [address[0], customer[0]];
  } catch (error) {
    console.error("ERROR:", error);
    throw error;
  }
});

On the frontend, I have the following code:

const fetchCustomer = httpsCallable(firebaseFunctions, 'fetchCustomer');
await fetchCustomer({dataset: this.dataset, id: this.customerId})
.then((res) => {
  this.address = res.data[0];
  this.customer = res.data[1];
}

The object this.customer appears to have a nested property dateOfBirth that is difficult to decipher due to its structure. How can I convert this property into a string with the format 'yyyy-mm-dd' or any other appropriate date format?

Any guidance or insights on this will be greatly appreciated. Thank you!

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

Unable to utilize navigator.camera.getPicture in iOS while using PhoneGap Adobe Build

I've spent hours searching, trying to troubleshoot my PhoneGap app (compiled by Adobe PhoneGap Build) and I suspect there's something crucial about PhoneGap that I'm missing. I've added the following lines to the config.xml file: <f ...

Why is the 3rd argument necessary when using useReducer?

According to the information provided in the documentation: [init, the 3d argument] allows you to separate the logic for determining the initial state outside of the reducer. This is particularly useful for resetting the state later in response to an ac ...

Tips for finding the position of a specific object within an array of objects using JavaScript when it is an exact match

I am working with an array of objects and need to find the index of a specific object within the array when there is a match. Here is an example of my current array: let x = [ {name: "emily", info: { id: 123, gender: "female", age: 25}}, {name: "maggie", ...

Using ng-disabled on input elements within an ng-repeat directive

Showing different inputs based on an array looks like this <div data-ng-repeat="n in langInput.values"> <input type="text" id="auction_name_{{n.selected}}" class="form-control" name="auction_name_{{$index}}" ...

When saving a canvas as an image, it only results in a blank, transparent image

I have a situation where I am iterating through an array of image elements sourced from a local folder, attaching them to a canvas. However, when attempting to save the canvas as an image, it is not being saved correctly. The resulting image appears to mat ...

Is your YQL JSON script failing to provide the expected output?

Here is a script that I have copied almost directly from this. Why is it that the code below does not seem to return anything? ajax.html: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html dir="lt ...

Discover the Magic of CSS Animation

I am not experienced in CSS animations and have limited knowledge about animations. I am trying to create an animation where a grey box slides down from the top line above the login/register section, but currently it only fades in. If anyone can provide an ...

`"Error in accessing array index" occurred while trying to retrieve array data for the dataTable jQuery plugin`

Incorporating an ajax json response that will populate the dataTable jquery plugin with data retrieved from a server. The unique identifier for the table is #dataTable. Below is the code snippet for initializing the dataTable plugin: $(document).ready(fu ...

The isInvalid property fails to apply red highlighting to the input box in a react-bootstrap form

Working on creating forms using React and react-bootstrap. Currently, my form includes an email field structured like this - https://i.sstatic.net/dlbWn.png Here's the code snippet of how it looks: <Form noValidate autoComplete="off&quo ...

Ways to adjust the size or customize the appearance of a particular text in an option

I needed to adjust the font size of specific text within an option tag in my code snippet below. <select> <?php foreach($dataholder as $key=>$value): ?> <option value='<?php echo $value; ?>' ><?php echo ...

Issue encountered while generating a package using npm init in Node.js

I am currently in the learning process of NodeJs from tutorialspoint(TP). Following instructions provided in this link, I tried to create a package by running the following command: C:\Program Files (x86)\nodejs>npm init This utility will w ...

How to iterate dynamically over arrays using JavaScript

I am working on a JavaScript project where I need to create a graph with 25 different data points. While my current JavaScript method is effective, I am facing an issue - I have multiple arrays and I am looking for a solution that allows me to use a for lo ...

The issue persists with the addEventListener function not working multiple times

My issue is that the addEventListener function is only working for the 'scroll' event and not for 'addMoreFields' or 'removeFields'. If I move the scroll section down, then it works for 'addMoreFields' and 'remo ...

An error of TypeError is being encountered in AngularJS

Hello, I am new to creating mobile apps with Ionic and Angular. Currently, I have a simple login form and a corresponding login button that triggers a controller. Here is the code snippet for the controller: angular.module('starter.controllers', ...

Stream-Awesome #12: The Return of Duplexer in Nodesville

For days, I've been attempting different methods to solve this exercise. It's frustrating because no matter what I try, I keep encountering a "write after end" error. But here's the thing - I'm using the "end" event and not writing anyt ...

What steps do I need to follow in order to perform a particle design simulation on my laptop

Recently, I attempted to utilize some of the particle designs featured on this website https://speckyboy.com/particle-animation-code-snippets/, but encountered difficulties. I have included both the stylesheet and javascript files, yet the design does not ...

Setting the font-size in HTML/CSS to dynamically adjust and fill the entire width and height of its

I'm trying to make a <div> element adjust its size based on the browser window. Within this <div>, there is a paragraph of text: <div style="width:80%; height:80%; margin:10%;"> <p>Paragraph of text. Paragraph of text. Pa ...

Error: Trying to access the 'title' property of an undefined variable in Vue.js

Creating a replica of hackernews by utilizing the axios API. The NewItem.vue component is not receiving any data, resulting in an error — TypeError: Cannot read property 'title' of undefined. Can you identify what's causing this issue in t ...

The lightbox is triggered by clicking on a different div to display its content

Great news - my lightbox is up and running! Each image on my website corresponds to a different organization, and clicking on the image opens a specific lightbox. My question is: how can I have a lightbox configured so that only the trigger image is displ ...

Is it necessary for Webpack to process the index.html file for Vue applications?

I am facing an issue with my index.html file where the assets inside the head tag are not loading as images but as the index.html file itself. I have included the following links in my head tag: <link rel="apple-touch-icon" sizes="60x60" href="./assets ...