Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.check = functions.https.onRequest(async (req, res) => {
- name = req.form.get('name');
- var currentTime = Math.floor(Date.now() / 1000);
- const client = new OneSignal.Client('b76a6035-dc17-4e9b-810f-8b0ef2d50774', 'ZDY1YmQyZGQtMGNhYS00ZTMwLTgxNWItM2M0ZDU4YjYxMjJi');
- const risultati = await firestore.collection("Risultati").doc("risultati").get();
- const ref1 = await firestore.collection("Schedine").get();
- const notification1 = {
- headings: {
- 'en' : 'Schedina vinta!'
- },
- contents: {
- 'en': 'Hai vinto una schedina. Controlla il tuo nuovo saldo.',
- },
- include_external_user_ids: [name],
- android_accent_color:"F44336",
- };
- const notification2 = {
- headings: {
- 'en' : 'Schedina persa!'
- },
- contents: {
- 'en': 'Hai perso una schedina.',
- },
- include_external_user_ids: [name],
- android_accent_color:"F44336",
- };
- const ref2 = await firestore.collection("Schedine").doc(name).collection("in corso").get();
- await ref2.forEach(async doc2 => {
- var i =0;
- var j = 0;
- for(matchId in doc2.data()["Match"]){
- j++;
- try {
- for(id in risultati.data()){
- if(matchId == id && risultati.data()[id]["status"]!=0 && doc2.data()["Match"][matchId]["status"]==0){
- if((doc2.data()["Match"][matchId]["Bet"]==1 || doc2.data()["Match"][matchId]["Bet"]==2 || doc2.data()["Match"][matchId]["Bet"]==3) && doc2.data()["Match"][matchId]["Bet"]==risultati.data()[id].ris){
- await firestore.collection('Schedine').doc(name).collection("in corso").doc(doc2.id).update({
- ['Match.'+matchId+'.status'] : 1,
- });
- } else if(doc2.data()["Match"][matchId]["Bet"]==4 && risultati.data()[id].goal ==1){
- await firestore.collection('Schedine').doc(name).collection("in corso").doc(doc2.id).update({
- ['Match.'+matchId+'.status'] : 1,
- });
- } else if(doc2.data()["Match"][matchId]["Bet"]==5 && risultati.data()[id].goal ==0){
- await firestore.collection('Schedine').doc(name).collection("in corso").doc(doc2.id).update({
- ['Match.'+matchId+'.status'] : 1,
- });
- } else if(doc2.data()["Match"][matchId]["Bet"]==6 && risultati.data()[id].over ==1){
- await firestore.collection('Schedine').doc(name).collection("in corso").doc(doc2.id).update({
- ['Match.'+matchId+'.status'] : 1,
- });
- } else if(doc2.data()["Match"][matchId]["Bet"]==7 && risultati.data()[id].over ==0){
- await firestore.collection('Schedine').doc(name).collection("in corso").doc(doc2.id).update({
- ['Match.'+matchId+'.status'] : 1,
- });
- } else {
- await firestore.collection('Schedine').doc(name).collection("in corso").doc(doc2.id).update({
- ['Match.'+matchId+'.status'] : 2,
- });
- await firestore.collection('Schedine').doc(name).collection("finite").doc(doc2.id).set(doc2.data());
- await firestore.collection('Schedine').doc(name).collection("finite").doc(doc2.id).update({
- "esito" : 2, "timestamp": currentTime
- });
- await firestore.collection('Schedine').doc(name).collection("in corso").doc(doc2.id).delete();
- try {
- const response = await client.createNotification(notification2);
- } catch (e) {}
- }
- }
- }
- } catch (e) {}
- try {
- if(doc2.data()["Match"][matchId]["status"]==1 ){
- i++;
- }
- } catch (e) {}
- }
- if(i==j && i!=0){
- await firestore.collection("Users").doc(name).update({ "vinte" : fieldValue.increment(1)});
- await firestore.collection('Schedine').doc(name).collection("finite").doc(doc2.id).set(doc2.data());
- await firestore.collection('Schedine').doc(name).collection("finite").doc(doc2.id).update({
- "esito" : 1, "timestamp": currentTime,
- });
- try {
- const response = await client.createNotification(notification1);
- } catch (e) {}
- const refuser = await firestore.collection("Users").doc(name).get();
- var newbalance = refuser.data()["balance"] + doc2.data()["vincita"];
- await firestore.collection("Users").doc(name).update({
- "balance" : newbalance
- });
- await firestore.collection('Schedine').doc(name).collection("in corso").doc(doc2.id).delete();
- }
- });
- res.end();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement