Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[oauth] #3

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions backend-oauth2/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ DB_USER=
DB_PASS=
DB_HOST=
DB_PORT=


MYSQL_URL=mysql://root:[email protected]:5768/railway
MYSQLDATABASE=railway
MYSQLHOST=containers-us-west-197.railway.app
MYSQLPASSWORD=e7VHpwcC13qoUJ7IKLJ1
MYSQLPORT=MYSQLPORT
MYSQLUSER=root
2 changes: 1 addition & 1 deletion backend-oauth2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:16.14-alpine

WORKDIR /server
WORKDIR /backend-oauth2

COPY package* ./

Expand Down
37 changes: 37 additions & 0 deletions backend-oauth2/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as express from 'express';
import tasksRouter from './routers/tasksRouter';


class App {
public app: express.Express;

constructor() {
this.app = express();

this.config();
this.app.get('/', (req, res) => res.json({ ok: true }));
// Não remover essa rota
this.app.use('/', tasksRouter);
}

private config():void {
const accessControl: express.RequestHandler = (_req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,POST,DELETE,OPTIONS,PUT,PATCH');
res.header('Access-Control-Allow-Headers', '*');
next();
};

this.app.use(express.json());
this.app.use(accessControl);
}

public start(PORT: string | number):void {
this.app.listen(PORT, () => console.log(`Running on port ${PORT}`));
}
}

export { App };

// A execução dos testes de cobertura depende dessa exportação
export const { app } = new App();
17 changes: 17 additions & 0 deletions backend-oauth2/database/config/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'dotenv/config';
import { Options } from 'sequelize';

const config: Options = {
username: process.env.DB_USER || 'root',
password: process.env.DB_PASS || '123456',
database: 'W3lcome',
host: process.env.DB_HOST || 'localhost',
port: Number(process.env.DB_PORT) || 3002,
dialect: 'mysql',
dialectOptions: {
timezone: 'Z',
},
logging: false,
}

module.exports = config;
26 changes: 26 additions & 0 deletions backend-oauth2/database/migrations/1-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

module.exports = {
async up (queryInterface, Sequelize) {
await queryInterface.createTable('tasks', {
id: {
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
titulo: {
type: Sequelize.STRING,
allowNull: false
},
concluida: {
type: Sequelize.BOOLEAN,
allowNull: false
},
})
},

async down (queryInterface, Sequelize) {
await queryInterface.dropTable('tasks');
}
};
32 changes: 32 additions & 0 deletions backend-oauth2/database/models/TaskModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { DataTypes, Model } from 'sequelize';
import db from '.';

class Task extends Model {
id!: number;
titulo!: string;
concluida!: boolean;
}

Task.init({
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
titulo: {
type: DataTypes.STRING,
allowNull: false,
},
concluida: {
type: DataTypes.BOOLEAN,
allowNull: false,
unique: true,
},
}, {
sequelize: db,
modelName: 'tasks',
underscored: true,
timestamps: false,
});

export default Task;
4 changes: 4 additions & 0 deletions backend-oauth2/database/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Sequelize } from 'sequelize';
import * as config from '../config/database';

export default new Sequelize(config);
22 changes: 22 additions & 0 deletions backend-oauth2/database/seeders/20211205212238-tasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
up: async (queryInterface) => {
await queryInterface.bulkInsert('tasks', [
{
titulo: 'Aprender React',
concluida: true,
},
{
titulo: 'Estudar NodeJS',
concluida: false,
},
{
titulo: 'Praticar TypeScript',
concluida: false,
},
], {});
},

down: async (queryInterface) => {
await queryInterface.bulkDelete('tasks', null, {});
},
};
Loading