How can I get the Current Month Start and End Date of Fullcalendar with Vue3 - fullcalendar

I have loaded 500+ events on the calendar but since this causes some performance problems, I just want to use the start and end date of the current month and add them as params to the get request.
note: I'm using vue3 and fullcalendar v5
getData(Seckey, view) {
let eventGuid = 0;
this.data = [];
this.log1 = [];
this.log2 = [];
this.events = [];
this.logs = [];
console.log("Start date:", view.activeStart.toISOString());
axios
.get(
"http://example:3333/getkamusinglogs?secretkey=" +
Seckey +
"&filter=zip",
{
params: {
start: view.activeStart,
end: view.activeEnd,
},
}
)
In this way, it is reflected to the console as undefined. I couldn't understand why I couldn't access activestart and activeEnd date information even though I looked at the documentation and some examples.

Related

Ignore firebase.firestore.timestamp

My project used #Nativescript/firebase(https://github.com/EddyVerbruggen/nativescript-plugin-firebase) ignores methods of firebase.firestore.timestamp, and returns undefined by properties.
The below is minimum reproduction
app.js
import Vue from "nativescript-vue";
import Home from "./components/Home";
var firebase = require("#nativescript/firebase").firebase;
firebase
.init({})
.then(
function () {
console.log("firebase.init done");
},
function (error) {
console.log("firebase.init error: " + error);
}
);
new Vue({
render: (h) => h("frame", [h(Home)]),
}).$start();
Home.vue
import { firebase } from "#nativescript/firebase";
export default {
computed: {
async message() {
const Ref = firebase.firestore
.collection("comments")
.doc("07bhQeWDf3u1j0B4vNwG");
const doc = await Ref.get();
const hoge = doc.data();
console.log("hoge.commented_at", hoge.commented_at); // CONSOLE LOG: hoge.commented_at Sat Oct 23 2021 22:44:48 GMT+0900 (JST)
console.log("hoge.commented_at.seconds", hoge.commented_at.seconds); // CONSOLE LOG: hoge.commented_at.seconds undefined
const hogeToDate = hoge.toDate();
console.log("hogeToDate", hogeToDate); // no console.log appear
return hogeToDate; // simulator shows "object Promise"
},
},
};
I also tried const hogeTimestampNow = firebase.firestore.Timestamp.now(); then no console.log appear...
Environment
vue.js
Node.js v14.17.6
nativescript v8.1.2
nativescript-vue v2.9.0
#nativescript/firebase v11.1.3
If you dive into the source of #nativescript/firebase, in particular looking at /src/firebase-common.ts, you can see that firebase is a custom implementation and not the object/namespace normally exported by the ordinary Firebase Web SDK.
It uses a custom implementation so that it can be transformed depending on the platform the code is running on as shown in /src/firebase.android.ts and /src/firebase.ios.ts.
Of particular importance, is that Firestore's Timestamp objects are internally converted to JavaScript Date objects when exposed to your code as each platform has its own version of a Timestamp object. Because the exposed JavaScript Date object doesn't have a seconds property, you get undefined when attempting to access hoge.commented_at.seconds.
The equivalent of Timestamp#seconds would be Math.floor(hoge.commented_at / 1000) (you could also be more explicit with Math.floor(hoge.commented_at.getTime() / 1000) if you don't like relying on JavaScript's type coercion).
function getSeconds(dt: Date) {
return Math.floor(dt.getTime() / 1000)
}
While you can import the Timestamp object from the Modular Web SDK (v9+), when passed into the NativeScript plugin, it would be turned into an ordinary object (i.e. { seconds: number, nanoseconds: number } rather than a Timestamp).
import { Timestamp } from 'firebase/firestore/lite';
const commentedAtTS = Timestamp.fromDate(hoge.commented_at);
docRef.set({ commentedAt: commentedAtTS.toDate() }) // must turn back to Date object before writing!
firebase.firestore.timestamp does not work via #nativescript/firebase as #samthecodingman said.(https://stackoverflow.com/a/69853638/15966408)
Just use ordinally javascript methods and edit.
I tried
get timestamp from firestore then convert to milliseconds
get date with new Date() then convert to milliseconds
and same miliseconds logged.
via firestore
const Ref = firebase.firestore.collection("comments").doc("07bhQeWDf3u1j0B4vNwG");
const doc = await Ref.get();
const hoge = doc.data();
console.log("hoge.commented_at in milliseconds: ", Math.floor(hoge.commented_at / 1000));
// CONSOLE LOG: hoge.commented_at in milliseconds: 1634996688
via javascript methods
const getNewDate = new Date("October 23, 2021, 22:44:48 GMT+0900");
// same as hoge.commented_at
console.log("getNewDate in milliseconds: ", getNewDate.getTime() / 1000);
// CONSOLE LOG: getNewDate in milliseconds: 1634996688

Firebase/Firestore no matching index found but no option to create one

I'm trying to run a firestore query in my app which is is throwing up an error that an index is missing.
Firestore always used to also include a link to click for the console to create the missing index, but it's not there this time so I'm stuck!
Not sure what I've done differently this time.
This is the console error:
prebuilt-d16b955d-cdb9e87f.js:188 Uncaught (in promise) FirebaseError: no matching index found.
at new e (prebuilt-d16b955d-cdb9e87f.js:188)
at prebuilt-d16b955d-cdb9e87f.js:10416
at prebuilt-d16b955d-cdb9e87f.js:10414
at e.onMessage (prebuilt-d16b955d-cdb9e87f.js:10403)
at prebuilt-d16b955d-cdb9e87f.js:10356
at prebuilt-d16b955d-cdb9e87f.js:10387
at prebuilt-d16b955d-cdb9e87f.js:15180
This is my JS function:
loadcatalogues() {
console.log(this.clubID);
this.showspinner = true;
this.catalogues = [];
var today = moment().utc().unix();
let self = this;
fb.catalogueCollection
.where("clubID", "==", this.clubID)
.where("expiry", ">", today)
.orderBy("expiry", "asc")
.orderBy("price", "asc")
.get()
.then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
if (
doc.data().members &&
doc.data().members.indexOf(self.userProfile.id) !== -1
) {
return false;
}
var starttime = moment.unix(doc.data().start).utc();
var endtime = moment.unix(doc.data().expiry).utc();
var tempdata = {
title: doc.data().title,
description: doc.data().description,
start: starttime.format("DD-MM-YYYY"),
expiry: endtime.format("DD-MM-YYYY"),
price: doc.data().price,
purchased: false,
stripeid: doc.data().stripeid,
catalogueid: doc.id,
limited: doc.data().limited,
};
self.catalogues.push(tempdata);
});
if (self.catalogues.length == 0) {
self.shownooptions = true;
}
self.showspinner = false;
});
},
If I remove the first where clause (.where("clubID", "==", this.clubID)) then the query runs fine, so I'm guessing an index already exists for that query.
I've only recently added the clubID field, so could that be missing an index?
Thanks!!
Looks like there's currently a problem with Google firestore.
Raised a support call and they have confirmed they have received several other reports of this and their engineering team are investigating.

How to efficiently query from Firebase Realtime Database using query or specific path

We have infrequently property modification("price") on Firebase Realtime Database which is structure like this:
../currencies/<currency>/value/
"price":343
every player that log in will listen to only one and specific currency. our client will pick the right currency path based on the player preferences.
so if player is set to currency USD the firebase client will listen to this path
../currencies/USD/value/
"price":343
Those currencies prices are changed infrequently
due to this structure our server side need to modify and denormalized the data to all currencies when it changes (we can have ten's of currencies)
because of that we add to the leaf even more properties which are identical at all currencies
which I find redudent like:
../currencies/USD/value/
"price":343
"currency-source":"fx" . //this property will be copied to all
currencies vals because the client listen to only one path and it needs this data aswell
instead if manitain this on path's perhaps we can use some query where each client will be able to pick it's currency based on property name?
something like that:
../currencies/value/
"USD_price":343
"EUR_price":343
...
thoughts about design? and if sounds better how can be achieved with Firebase Realtime Database query?
I don't know which language (which Client SDK) you use in your app, but here is a solution with the JavaScript SDK.
Let's imagine you have a Relatime Database structure as follows
"parentnode" : {
"currencies" : {
"EUR" : {
"value" : {
"price" : 201
}
},
"USD" : {
"value" : {
"price" : 343
}
},
"value" : {
"EUR_price" : 201,
"USD_price" : 343,
"currency-source" : "fx"
}
}
}
Under a parentnode you have a currencies node which corresponds to the examples in your question.
In case you want to listen to /currencies/<currency>/value, you would do as follows:
var db = firebase.database();
var currency = 'EUR';
var ref = db.ref().child('parentnode/currencies/' + currency);
ref.on('value', function(snapshot) {
var data = snapshot.val();
console.log(data);
});
In case you want to listen to /currencies/value/<currency>_price and get the price and the currency-source values, you would do as follows:
var db = firebase.database();
var currency = 'EUR';
var ref = db.ref().child('parentnode/currencies/value');
ref.on('value', function(snapshot) {
var data = snapshot.val();
var price = data[currency + '_price'];
var source = data['currency-source'];
console.log(price);
console.log(source);
});
As mentioned in your comment, the second approach implies that "we will download all the data leaf under /currencies/value/".
I can think of two other possible approaches. Choosing one over the other really depends on your functional requirements, i.e. what you do with these values in your front-end.
1/ Set two listeners
The idea is to set one listener for 'parentnode/currencies/value/' + currency + '_price' and one for 'parentnode/currencies/value/currency-source', as follows:
var currency = 'EUR';
var ref2 = db
.ref()
.child('parentnode/currencies/value/' + currency + '_price');
ref2.on('value', function(snapshot) {
var data = snapshot.val();
console.log(data);
});
var ref3 = db.ref().child('parentnode/currencies/value/currency-source');
ref3.on('value', function(snapshot) {
var data = snapshot.val();
console.log(data);
});
2/ Query the currency-source value within the listener
With this second approach, in the listener to 'parentnode/currencies/value/' + currency + '_price', we query the database with the once() method to get the value of currency-source:
var ref4 = db
.ref()
.child('parentnode/currencies/value/' + currency + '_price');
ref4.on('value', function(snapshot) {
var data = snapshot.val();
console.log(data);
db.ref()
.child('parentnode/currencies/value/currency-source')
.once('value')
.then(function(dataSnapshot) {
console.log(dataSnapshot.val());
});
});
Note that if you do not need to set a listener, i.e. you want to fetch the data once (e.g. by triggering the fetch from a button, or on page loading, etc..) you should only use the once() method and then you can chain the two calls as follows:
var currency = 'EUR';
var ref5 = db.ref().child('parentnode/currencies/value/' + currency + '_price');
var ref6 = db.ref().child('parentnode/currencies/value/currency-source');
ref5
.once('value')
.then(function(dataSnapshot) {
console.log(dataSnapshot.val());
return ref6.once('value');
})
.then(function(dataSnapshot) {
console.log(dataSnapshot.val());
});

Cloud Functions for Firebase - get database value 'synchronously'

My realtime db has this structure
- userId1
- meta
- name
- data
- dataId1
- description
- dataId2...
- userId2....
I'm trying to monitor additions to dataIdx but want to get the name field too. I tried the following, but was misusing the parent method. So I thought about the line commented out, but .once is asynchronous, which starts to make my code more complex, while in the examples there are calls to set that are more or less synchronous
exports.sendNotification = functions.database.ref('/{userId}/presents/{dataId}')
.onWrite(event => {
var eventSnapshot = event.data;
var person = eventSnapshot.parent().parent().child("meta").child("name").val();
// var person = admin.database().ref('/' + event.params.userId + '/meta/name').once().val();
let p = eventSnapshot.child("description").val();
console.log(`${person} added ${p}`);
What would be the correct way to do this
This is what I came up with using chained promises to build my data
exports.sendNotification = functions.database.ref('/{userId}/presents/{presentId}')
.onWrite(event => {
let p = eventSnapshot.child("description").val();
return event.data.ref.parent.parent.child('meta/name').once("value")
.then(snapshot => {
let person = snapshot.val();
var payload = {
data: {
person: person,
...
}
};

Meteor return response from server method to client

I am trying to integrate a payment API. The method I'm using to create a payment should return an object. And in fact it does, but it's just that I can't get the object back to the client.
I know that this happens because the method to API is executed asynchronously, while method on server is executed synchronously (If I'm not mistaken). But still I can't figure out how to do it, and I am hoping you guys can help me out.
Client side call to server:
Meteor.call('createPaymentLink',NewBooking, TotalAmount ,function(result) {
console.log(result);
});
Server side call to API:
Meteor.methods({
'createPaymentLink': function(bookingID, amount) {
//Create Booking No.
// First two digits = First two digits of booking ID
// Last two digits = Last two digits of Customer ID
var CustomerId = Bookings.findOne({_id: bookingID}).CustomerID;
var FirstPart = CustomerId.substring(0,2);
var LastPart = bookingID.slice(-2);
var rightNow = new Date();
var OrderDate = rightNow.toISOString().slice(0,10).replace(/-/g,"");
var CustomerBookingCode = (FirstPart + OrderDate + LastPart).toUpperCase();
mollieClient.payments.create({
amount: amount,
description: "Booking code: "+bookingID,
redirectUrl: "https://webshop.example.org/order/12345/"
}, Meteor.bindEnvironment(function(payment) {
return payment;
//Bookings.update({_id: bookingID}, {$set: {payment_id : PaymentUrl}});
}));
}
});
The first argument to the callback is the error, which will be null if everything worked! Try this:
Meteor.call('createPaymentLink',NewBooking, TotalAmount ,function(err, result) {
console.log(result);
});

Resources