Skip to content

Commit

Permalink
ignition 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilenka committed Mar 25, 2020
0 parents commit ae3d5e1
Show file tree
Hide file tree
Showing 30 changed files with 7,490 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"presets": [
[
"@babel/env",
{
"targets": {
"node": "current"
}
}
]
],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread"
]
}
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DEVELOPMENT_JWT_SECRET=learneverything
DEVELOPMENT_MONGO_URL=mongodb://localhost:27017/covid-api-dev?retryWrites=true&w=majority

PRODUCTION_JWT_SECRET=
PRODUCTION_MONGO_URL=

TESTING_JWT_SECRET=
TESTING_MONGO_URL=
26 changes: 26 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
parserOptions: {
sourceType: "module"
},
parser: "babel-eslint",
env: {
node: true
},
extends: [
"standard",
"prettier",
"prettier/standard",
"plugin:jest/recommended"
],
plugins: ["prettier", "jest"],
rules: {
"promise/catch-or-return": "error",
"prettier/prettier": [
"error",
{
singleQuote: true,
semi: false
}
]
}
};
121 changes: 121 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Project
.env

# Mac
.DS_Store

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*
4 changes: 4 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
semi: false,
singleQuote: true
}
23 changes: 23 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"restartable": "rs",
"ignore": [
".git",
"node_modules/**/node_modules",
"dist"
],
"verbose": true,
"execMap": {
"js": "node"
},

"runOnChangeOnly": false,
"watch": [
"src/**/*.js",
"src/**/*.graphql",
"src/**/*.gql"
],
"env": {
"NODE_ENV": "development"
},
"ext": "js,json,graphql"
}
72 changes: 72 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "wilayah-administrasi-indonesia",
"version": "1.0.0",
"main": "index.js",
"author": "Ongki Herlambang <[email protected]>",
"license": "MIT",
"scripts": {
"build": "babel src --out-dir dist",
"test": "NODE_ENV=testing jest --forceExit --detectOpenHandles --silent",
"test-routes": "yarn test -t router",
"test-models": "yarn test -t model",
"test-controllers": "yarn test -t controllers",
"test-auth": "yarn test -t Authentication:",
"dev": "NODE_ENV=development nodemon --exec yarn restart",
"restart": "rimraf dist && yarn build && node dist/index.js",
"start": "rimraf dist && yarn build && NODE_ENV=production node dist/index.js"
},
"dependencies": {
"bcrypt": "^3.0.2",
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"cuid": "^2.1.4",
"dotenv": "^6.1.0",
"express": "^4.16.4",
"jsonwebtoken": "^8.4.0",
"lodash": "^4.17.11",
"mariadb": "^2.2.0",
"mongoose": "^5.3.13",
"morgan": "^1.9.1",
"validator": "^10.9.0",
"nodemon": "^1.18.3",
"rimraf": "^2.6.2",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "^8.2.1",
"babel-jest": "^23.4.2"
},
"devDependencies": {
"eslint": "^4.15.0",
"eslint-config-prettier": "^2.9.0",
"eslint-config-standard": "^11.0.0",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jest": "^21.15.1",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-prettier": "^2.6.2",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"jest": "^23.6.0",
"mock-req-res": "^1.0.2",
"prettier": "^1.15.2",
"supertest": "^3.3.0"
},
"jest": {
"verbose": true,
"testURL": "http://localhost/",
"testEnvironment": "node",
"setupTestFrameworkScriptFile": "<rootDir>/test-db-setup.js",
"testPathIgnorePatterns": [
"dist/"
],
"restoreMocks": true
},
"engines": {
"node": "13.11.0"
}
}
8 changes: 8 additions & 0 deletions src/config/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// require('dotenv').config()

export const devConfig = {
secrets: {
jwt: process.env.DEVELOPMENT_JWT_SECRET
},
dbUrl: process.env.DEVELOPMENT_MONGO_URL
}
41 changes: 41 additions & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { merge } from 'lodash'
const env = process.env.NODE_ENV || 'development'

import { devConfig } from './dev'
import { prodConfig } from './prod'
import { testConfig } from './testing'

const baseConfig = {
env,
isDev: env === 'development',
isTest: env === 'testing',
port: process.env.PORT || 3000,
secrets: {
jwt: process.env.DEVELOPMENT_JWT_SECRET,
jwtExp: '100d'
}
}

let envConfig = {}

switch (env) {
case 'dev':
case 'development':
envConfig = devConfig
break

case 'test':
case 'testing':
envConfig = testConfig
break

case 'prod':
case 'production':
envConfig = prodConfig
break

default:
envConfig = devConfig
}

export default merge(baseConfig, envConfig)
6 changes: 6 additions & 0 deletions src/config/prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const prodConfig = {
secrets: {
jwt: process.env.PRODUCTION_JWT_SECRET
},
dbUrl: process.env.PRODUCTION_MONGO_URL
}
6 changes: 6 additions & 0 deletions src/config/testing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const testConfig = {
secrets: {
jwt: process.env.TESTING_JWT_SECRET
},
dbUrl: process.env.TESTING_MONGO_URL
}
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { start } from './server'
start()
4 changes: 4 additions & 0 deletions src/resources/district/district.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { District } from './district.model'
import { crudControllers } from '../../utils/crud'

export default crudControllers(District)
21 changes: 21 additions & 0 deletions src/resources/district/district.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Schema, model } from 'mongoose'

const districtSchema = new Schema({
id: {
type: String,
required: true,
unique: true,
trim: true
},
regency_id: {
type: String,
required: true,
trim: true
},
name: {
type: String,
required: true
}
})

export const District = model('districts', districtSchema)
10 changes: 10 additions & 0 deletions src/resources/district/district.router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Router } from 'express'
import districtController from './district.controller'

const router = Router()

router.get('/', districtController.getAll)
router.get('/:id', districtController.getById)
router.get('/:id/all', districtController.getComplete)

module.exports = router
4 changes: 4 additions & 0 deletions src/resources/province/province.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Province } from './province.model'
import { crudControllers } from '../../utils/crud'

export default crudControllers(Province)
Loading

0 comments on commit ae3d5e1

Please sign in to comment.