-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Wellerson
committed
Jul 26, 2019
0 parents
commit e8bbd4b
Showing
33 changed files
with
12,352 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Wellerson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<p align="center"> | ||
<img src="./backend.png" height="130"/> | ||
</p> | ||
<!-- <p align="center"> | ||
<img src="https://img.shields.io/github/package-json/v/wellers0n/4fun-fullstack.svg"/> | ||
<img src="https://img.shields.io/github/last-commit/wellers0n/4fun-fullstack.svg"/> | ||
<img src="https://img.shields.io/github/license/wellers0n/4fun-fullstack.svg"/> | ||
<a href="https://twitter.com/wellers0n_" target="_blank"> | ||
<img src="https://img.shields.io/twitter/url/https/wellers0n_.svg?style=social"/> | ||
</a> | ||
</p> --> | ||
|
||
<p> | ||
<h1 align="center">Backend-diff</h1> | ||
<p/> | ||
|
||
<br/> | ||
|
||
## Backend-diff JS and TS | ||
|
||
Backend-diff uses a stack full `JS/TS` on the backend, I'm making this project to improve | ||
my skills in the backend. | ||
|
||
## Initing in the your PC | ||
|
||
- For clone the project `git clone https://github.com/Wellers0n/Backend-diff.git` | ||
- Enter in the folder `cd Backend-diff/` | ||
- To install project dependency: `yarn install` | ||
- After the installation of the dependencies `yarn start` in the default directory | ||
|
||
## Stack used | ||
|
||
[NodeJS](https://nodejs.org/en/)<br/> | ||
[KoaJS](https://koajs.com/)<br/> | ||
[MongoDB](https://www.mongodb.com/)<br/> | ||
[GraphQL](https://graphql.org/)<br/> | ||
[Yarn](https://yarnpkg.com/en/)<br/> | ||
[WorkSpaces](https://yarnpkg.com/lang/en/docs/workspaces/)<br/> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "Main", | ||
"version": "0.0.1", | ||
"description": "Api graphql and rest", | ||
"main": "index.js", | ||
"author": "Wellerson", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"start": "yarn start:rest & yarn start:server", | ||
"start:rest": "yarn workspace @rest/server run start", | ||
"start:server": "yarn workspace @graphql/server run start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"workspaces": { | ||
"packages": [ | ||
"packages/*" | ||
], | ||
"nohoist": [ | ||
"**/react-native", | ||
"**/react-native-*" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
{ | ||
"presets": [ | ||
"@babel/env", | ||
"@babel/typescript" | ||
], | ||
"plugins": [ | ||
"@babel/proposal-class-properties", | ||
"@babel/proposal-object-rest-spread", | ||
"babel-plugin-idx" | ||
] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
.env | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"workbench.colorCustomizations": { | ||
"activityBar.background": "#5ece50", | ||
"activityBar.foreground": "#15202b", | ||
"activityBar.inactiveForeground": "#15202b99", | ||
"activityBarBadge.background": "#6a76d5", | ||
"activityBarBadge.foreground": "#e7e7e7", | ||
"statusBar.background": "#42b833", | ||
"statusBarItem.hoverBackground": "#349028", | ||
"statusBar.foreground": "#15202b" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"name": "@graphql/server", | ||
"version": "1.0.0", | ||
"description": "GraphQL test", | ||
"main": "index.js", | ||
"author": "Wellerson", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"start": "nodemon --exec ts-node ./src/index.ts", | ||
"tslint": "tslint --project .", | ||
"test": "jest", | ||
"test:watch": "jest --watchAll --coverage" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.4.3", | ||
"@babel/core": "^7.4.3", | ||
"@babel/plugin-proposal-class-properties": "^7.4.0", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.4.3", | ||
"@babel/preset-env": "^7.4.3", | ||
"@babel/preset-typescript": "^7.3.3", | ||
"@types/jest": "^24.0.11", | ||
"@types/kcors": "^2.2.3", | ||
"@types/koa": "^2.0.48", | ||
"@types/koa-bodyparser": "^4.2.2", | ||
"@types/koa-json": "^2.0.18", | ||
"@types/koa-logger": "^3.1.1", | ||
"@types/koa-router": "^7.0.40", | ||
"get-graphql-schema": "^2.1.2", | ||
"jest": "^24.7.0", | ||
"nodemon": "^1.18.10", | ||
"ts-jest": "^24.0.1", | ||
"ts-node": "^8.0.3", | ||
"tslint": "^5.15.0", | ||
"tslint-config-airbnb": "^5.11.1", | ||
"typescript": "^3.4.1" | ||
}, | ||
"dependencies": { | ||
"@types/dotenv-safe": "^5.0.3", | ||
"@types/form-data": "^2.2.1", | ||
"@types/graphql": "^14.2.0", | ||
"@types/graphql-relay": "^0.4.9", | ||
"@types/jsonwebtoken": "^8.3.2", | ||
"@types/koa-multer": "^1.0.0", | ||
"@types/mongoose": "^5.3.25", | ||
"@types/node-fetch": "^2.3.7", | ||
"babel-plugin-idx": "^2.4.0", | ||
"dataloader": "^1.4.0", | ||
"dotenv-safe": "^6.1.0", | ||
"form-data": "^2.4.0", | ||
"graphql": "^14.2.1", | ||
"graphql-relay": "^0.6.0", | ||
"idx": "^2.5.6", | ||
"jsonwebtoken": "^8.5.1", | ||
"kcors": "^2.2.2", | ||
"koa": "^2.7.0", | ||
"koa-bodyparser": "^4.2.1", | ||
"koa-graphql": "^0.8.0", | ||
"koa-json": "^2.0.2", | ||
"koa-logger": "^3.2.0", | ||
"koa-multer": "^1.0.2", | ||
"koa-router": "^7.4.0", | ||
"mongoose": "^5.5.6", | ||
"multer": "^1.4.1", | ||
"multer-gridfs-storage": "^3.2.3", | ||
"node-fetch": "^2.6.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {greeter} from '../server' | ||
|
||
describe('func test', () => { | ||
it('should return an string with name: Hello, wellerson', () => { | ||
expect(greeter('wellerson')).toBe('Hello, wellerson'); | ||
}); | ||
it('should return an string with name: Hello, moreira', () => { | ||
expect(greeter('moreira')).toBe('Hello, moreira'); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
import jwt from 'jsonwebtoken'; | ||
import User from './model/users'; | ||
import mongoose from 'mongoose' | ||
|
||
export async function getUser(token: string) { | ||
if (!token) return { user: null }; | ||
|
||
try { | ||
const decodedToken:any = jwt.verify(token, 'batman'); | ||
|
||
const user = await User.findOne({ _id: decodedToken.id }); | ||
|
||
return { | ||
user, | ||
}; | ||
} catch (err) { | ||
return { user: null }; | ||
} | ||
} | ||
|
||
type UserType = { | ||
_id: string, | ||
}; | ||
|
||
export function generateToken(user: UserType) { | ||
return jwt.sign({id: user._id}, 'batman'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import mongoose from "mongoose"; | ||
|
||
export default function connectDatabase() { | ||
return new Promise((resolve, reject) => { | ||
mongoose.Promise = global.Promise; | ||
mongoose.connection | ||
.on("error", error => reject(error)) | ||
.on("close", () => console.log("Database connection closed.")) | ||
.once("open", () => resolve(mongoose.connections[0])); | ||
|
||
mongoose.connect( | ||
"mongodb+srv://Wellerson:[email protected]/blog?retryWrites=true&w=majority", | ||
{ | ||
useNewUrlParser: true, | ||
useCreateIndex: true | ||
} | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import "@babel/polyfill"; | ||
import { createServer } from "http"; | ||
import app from "./server"; | ||
import connectDatabase from "./database"; | ||
|
||
(async () => { | ||
try { | ||
await connectDatabase(); | ||
} catch (error) { | ||
console.log("Could not connect to database", { error }); | ||
throw error; | ||
} | ||
|
||
const server = createServer(app.callback()); | ||
|
||
server.listen(5000, () => { | ||
return console.log( | ||
`SERVER ON: http://localhost:${process.env.PORT || 5000}/graphql` | ||
); | ||
}); | ||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import mongoose from "mongoose"; | ||
const Schema = mongoose.Schema; | ||
|
||
const article = new Schema({ | ||
idUser: { | ||
type: String, | ||
required: "idUser is requerid" | ||
}, | ||
title: { | ||
type: String, | ||
required: "title is requerid" | ||
}, | ||
subtitle: { | ||
type: String, | ||
required: "subtitle is requerid" | ||
}, | ||
description: { | ||
type: String, | ||
required: "author is requerid" | ||
}, | ||
author: { | ||
type: [String], | ||
required: "author is requerid" | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now, | ||
}, | ||
date_update: { | ||
type: Date | ||
} | ||
}); | ||
|
||
export default mongoose.model("articles", article); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import mongoose from 'mongoose'; | ||
const Schema = mongoose.Schema; | ||
|
||
const comment = new Schema({ | ||
name: { | ||
type: String, | ||
required: 'name is required', | ||
}, | ||
description: { | ||
type: String, | ||
required: 'description is required', | ||
}, | ||
idArticle: { | ||
type: String, | ||
required: 'idArticle required' | ||
} | ||
}); | ||
|
||
export default mongoose.model('comments', comment) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import mongoose from 'mongoose'; | ||
const Schema = mongoose.Schema; | ||
|
||
const users = new Schema({ | ||
name: { | ||
type: String, | ||
required: 'name is requerid', | ||
}, | ||
email:{ | ||
type: String, | ||
required: 'email is requerid', | ||
}, | ||
password:{ | ||
type: String, | ||
required: 'password is requerid', | ||
} | ||
|
||
}); | ||
|
||
export default mongoose.model('users', users) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { | ||
GraphQLObjectType, | ||
GraphQLString, | ||
GraphQLID, | ||
GraphQLList | ||
} from 'graphql' | ||
import {globalIdField} from 'graphql-relay' | ||
|
||
export default new GraphQLObjectType({ | ||
name: 'Articles', | ||
fields: () => ({ | ||
id: globalIdField('Articles'), | ||
_id:{ | ||
type: GraphQLID | ||
}, | ||
author:{ | ||
type: new GraphQLList(GraphQLString), | ||
}, | ||
date:{ | ||
type: GraphQLString | ||
}, | ||
date_update:{ | ||
type: GraphQLString | ||
}, | ||
title:{ | ||
type: GraphQLString | ||
}, | ||
subtitle:{ | ||
type: GraphQLString | ||
}, | ||
description:{ | ||
type: GraphQLString | ||
}, | ||
idUser: { | ||
type: GraphQLString | ||
} | ||
}) | ||
}) | ||
|
Oops, something went wrong.