Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Zack laere

🎯
Focusing
View GitHub Profile
View 1 Validation Schema
const Joi = require("joi");
const registerValidationSchema = Joi.object().keys({
name: Joi.string()
.min(2)
.max(30)
.required(),
email: Joi.string()
.email()
.required(),
View 1 Register Route
router.post("/register", (req, res) => {
const userProps = req.body;
const { email } = userProps;
User.findOne({ email })
.then(user => {
if (user) {
return res.status(400).json({ errormessage: "User already exists." });
} else {
const avatar = gravatar.url(email, {
View 1 Parent.js
import React from 'react';
import { addBudget } from 'actions';
import { connect } from 'react-redux';
import BudgetForm 'components/Budgets/BudgetForm';
class BudgetCreate extends React.Component {
onSubmit = formValues => {
this.props.addBudget(formValues);
}
View Budget.js
const mongoose = require('mongoose');
const { Schema } = mongoose;
const TransactionSchema = require('./Transaction');
const budgetSchema = new Schema({
title: String,
description: String,
amount: { type: Number, default: 0 },
startDate: Date,
endDate: Date,
@laere
laere / FetchActionCreators.js
Created Mar 14, 2016 — forked from l0gicgate/FetchActionCreators.js
Reusable action creators / reducers.
View FetchActionCreators.js
import axios from 'axios';
class FetchActionCreators {
constructor(endpoint, actions) {
const [REQUEST, SUCCESS, FAILURE] = actions;
this.actions = {
REQUEST,
SUCCESS,
FAILURE,
View addtodo.jsx
///Click func
handleOnClick(e) {
e.preventDefault();
//save input value
let inputValue = this.refs.inputfield.value;
if(inputValue === '') return;
//pass input value to callback
this.props.addTodo(inputValue)
}
View server.js
// Dependencies
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
// Define our Todo Model
var Todo = mongoose.model('Todo', {
text: String
});
View 1Reducer.jsx
import dotProp from 'dot-prop-immutable';
//save string values to vars
const ADD_TODO = 'ADD_TODO';
let nextId = 0;
//the action is whats performed to alter state
//addItem is an action creator and nees to return an action
export const AddTodo = (text) => {
return {
type: ADD_TODO,
View List (dumb component)
import React, { Component } from 'react';
import ListItem from '../components/ListItem';
export default class List extends Component {
// renderTodos() {
// return this.props.items.map((item) => {
// return (
// <Listitem key={item.id}>
// {item.text}
View gist:8597038a19e99f632784
filterMovies: function() {
var moviePosters = [];
for (var i; i <= 5; i++) {
if(apiData.rating >= 8) {
return moviePosters.push(apiData.Poster[i]);
} else {
return;
}
}
},
You can’t perform that action at this time.