Skip to content

Instantly share code, notes, and snippets.

View kartikpandey2's full-sized avatar

Kartik Pandey kartikpandey2

View GitHub Profile
const useZingCash = (userId, amountToPay) => {
//Find all zingcash document which {userId: userId, isExpired: false, status: ACTIVE, transactionType: CREDIT} and sort in ascending order by expiryDate
data = Date from db
let remainingAmountToPay = amountToPay
const transactionToUpdate = [] // will contain all transaction id which will be completely used to pay amountToPay
const breakTransaction = { _id: null, updateBody: {}}
for (let i=0; i<data.length; ++i) {
const {amount} = data[i]
@kartikpandey2
kartikpandey2 / PrivateRoute,js
Created June 20, 2019 11:44
Trying to make Protected Route which will retrieve JWT token from localstorage and will make fetch call to the server to verify is token valid. If the token is valid Route is returned else user will be redirected to the login page.
import React, { Component, Fragment } from "react";
import { Route, Redirect } from "react-router-dom";
import Fetch from "./fetch";
class PrivateRoute extends Component {
constructor(props) {
super(props);
this.state = {
isValidToken: false,
loading: true
// I think we should create 2 entries for same product one in english and another in spanish
// For example: Product is IphoneX,
// Save one entry in english Language
{
name: "IphoneX",
price: x,
lang: "en",
const fetch1 = fetch(url).then((res) => res.json()). then((data) => {// do required things after fetch call and return Promise.resoove(true)})
const fetch2 = fetch(url).then((res) => res.json()). then((data) => {// do required things after fetch call and return Promise.resolve(true)})
const fetch3 = fetch(url).then((res) => res.json()). then((data) => {// do required things after fetch call return Promise.resolve(true)})
const allFetchDone = Promise.all([fetch1, fetch2, fetch3]).then(() => {// this function will be called after all fetch request is completed with success})
// this can be also done using async and await. This will make code Readable
// function for fetch call
const multipleFetch = async () => {
const Fetch1 = await fetch(url, options)
/*
* Fetch1 has completed, Do required things after fetch1
*/
const Fetch2 = await fetch(url, options)
/*
* Fetch1 and Fetch2 has completed, Do required things after fetch2
*/
const Fetch3 = await fetch(url, options)
import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";
import CardCase1 from "./CardCase1.js";
import CardCase2 from "./CardCase2.js";
import CardCase3 from "./CardCase3.js";
import CardCase4 from "./CardCase4.js";
import CardCase5 from "./CardCase5.js";
import CardCase6 from "./CardCase6.js";
import BillCard1 from "./BillCard1.js";
/*
* @params
* @profit array of profit for each day
* @ L, R range
*/
let count = 0;
for(let i=0; i<profit.length; ++i) {
const value = profit[i]
if(value >= L || value <=R) {
++count
@kartikpandey2
kartikpandey2 / isArraySimilar.js
Created January 4, 2019 18:23
Checks if array is similar or not
mapArray = (array) => {
const mapObj = {}
if(array.length === 0) {
return mapObj
}
for(let i=0; i<array.length; ++i) {
const value = array[i]
if(mapObj[value]) {
++mapObj[value]
}else{