Skip to content

Instantly share code, notes, and snippets.

View ziedHamdi's full-sized avatar
💭
Exploring opportunities

Zied Hamdi ziedHamdi

💭
Exploring opportunities
View GitHub Profile
const complaintUpdateById = updateById.wrapResolve(next => async rp => {
const {user} = rp.context
const {_id, record} = rp.args;
let state = record['state'];
// allows us to save draft and then only throw auth error
let throwAuthError = false
if (isPublished(state) && (!user || !user.id) ) {
//do not save as published if error will be thrown
state = 'DRAFT'
import ExtendableError from './ExtendableError'
import {error} from "winston";
const AuthenticationErrors = {
NOT_AUTHENTICATED: 401,
BAD_CREDENTIALS: 402
}
class AuthenticationError extends ExtendableError {
static errors = AuthenticationErrors
class ExtendableError extends Error {
constructor(message, errorCode) {
super(JSON.stringify( {text:message, code:errorCode} ))
this.name = this.constructor.name;
// this.errorCode = errorCode
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = (new Error(message)).stack;
}
import {useMemo} from 'react'
import {ApolloClient, gql} from '@apollo/client'
// import {HttpLink} from '@apollo/client/link/http'
import {from, HttpLink} from '@apollo/client'
import { onError } from "@apollo/client/link/error";
import merge from 'deepmerge'
import {createCache} from './cache'
import {isSSR} from "../constants/util";
import isEqual from 'lodash/isEqual'
import logger from "../lib/logger";
import {setUserAccessToken} from "../facebook";
import {Session, User} from '../db'
import jwt from 'jsonwebtoken'
import {TOKEN_SECRET} from "../constants/other";
import logger from "../../lib/logger";
const GraphQlSchema = require('../graphql').default
const {graphqlHTTP} = require('express-graphql');
import {useContext} from 'react';
import {ToastContext} from '../ToastContextProvider';
function useToast(timeout) {
const {toasts, addToast: originalAddToast, removeToast} = useContext(ToastContext);
function addToast(toast) {
originalAddToast(toast)
let appliedTimeout = toast.timeout ?? timeout
if (appliedTimeout > 0)
/**
* inspired from https://www.yld.io/blog/global-notifications-with-reacts-context-api/
*/
import React, { useState, useCallback } from 'react';
export const ToastContext = React.createContext({
toasts: null,
addToast: () => {},
removeToast: () => {},
});
#!/bin/bash
# GRAPHQL_SERVER_VERSION=$1
# NEXT_SERVER_VERSION=$2
# set variables from .env to system: https://gist.github.com/mihow/9c7f559807069a03e302605691f85572
if [ -f .env ]
then
export $(cat .env | sed 's/#.*//g' | xargs)
fi
#!/bin/bash
# GRAPHQL_SERVER_VERSION=$1
# NEXT_SERVER_VERSION=$2
# set variables from .env to system: https://gist.github.com/mihow/9c7f559807069a03e302605691f85572
if [ -f .env ]
then
export $(cat .env | sed 's/#.*//g' | xargs)
fi
version: "3.9"
services:
nginx:
container_name: nginx
image: 'nginx:0.1'
ports:
- "80:80"
- "443:443"
volumes: