Skip to content

Instantly share code, notes, and snippets.

View victorsteven's full-sized avatar

Victor Steven victorsteven

View GitHub Profile
@victorsteven
victorsteven / newarrivals.blade.php
Created April 15, 2019 19:45
newarrivals emails file
@component('mail::layout')
{{-- Header --}}
@slot('header')
@component('mail::header', ['url' => config('app.url')])
Wonderful Company
@endcomponent
@endslot
Dear {{$user->name}}
@victorsteven
victorsteven / models_index.js
Created April 20, 2019 17:14
models index.js
import fs from 'fs';
import path from 'path';
import Sequelize from 'sequelize';
import configJson from '../config/config';
const basename = path.basename(__filename);
const env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
const config = configJson[env];
@victorsteven
victorsteven / config.js
Last active April 20, 2019 17:35
The config.js file
require('dotenv').config();
module.exports = {
// If using onine database
// development: {
// use_env_variable: 'DATABASE_URL'
// },
@victorsteven
victorsteven / Book.js
Created April 20, 2019 18:04
Book Model
module.exports = (sequelize, DataTypes) => {
const Book = sequelize.define('Book', {
title: {
type: DataTypes.STRING,
allowNull: false,
},
price: {
type: DataTypes.STRING,
allowNull: false,
},
@victorsteven
victorsteven / create-book.js
Created April 20, 2019 18:12
Book Migration file
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Books', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
title: {
@victorsteven
victorsteven / BookService.js
Created April 20, 2019 18:26
BookService file
import database from '../src/models';
class BookService {
static async getAllBooks() {
try {
return await database.Book.findAll();
} catch (error) {
throw error;
}
}
@victorsteven
victorsteven / BookController.js
Created April 20, 2019 18:32
BookController file
import BookService from '../services/BookService';
import Util from '../utils/Utils';
const util = new Util();
class BookController {
static async getAllBooks(req, res) {
try {
const allBooks = await BookService.getAllBooks();
if (allBooks.length > 0) {
@victorsteven
victorsteven / Utils.js
Created April 20, 2019 18:36
Utils.js file
export default class Util {
constructor() {
this.statusCode = null;
this.type = null;
this.data = null;
this.message = null;
}
setSuccess(statusCode, message, data) {
this.statusCode = statusCode;
@victorsteven
victorsteven / BookRoutes.js
Created April 20, 2019 18:41
BookRoutes file
import { Router } from 'express';
import BookController from '../controllers/BookController';
const router = Router();
router.get('/', BookController.getAllBooks);
router.post('/', BookController.addBook);
router.get('/:id', BookController.getABook);
router.put('/:id', BookController.updatedBook);
router.delete('/:id', BookController.deleteBook);
@victorsteven
victorsteven / index.js
Created April 20, 2019 18:45
Root index.js file
import config from 'dotenv';
import express from 'express';
import bodyParser from 'body-parser';
import bookRoutes from './server/routes/BookRoutes';
config.config();
const app = express();
app.use(bodyParser.json());