Skip to content

Commit

Permalink
primer commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AAIING committed Mar 22, 2020
1 parent 8d75a54 commit bb850d9
Show file tree
Hide file tree
Showing 23 changed files with 7,569 additions and 272 deletions.
11 changes: 1 addition & 10 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": true
}
}
]
]
"presets": ["@babel/preset-env"]
}
Empty file removed app/GraphQL/.gitkeep
Empty file.
52 changes: 52 additions & 0 deletions app/GraphQL/evento.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { gql } from 'apollo-server-express'
import * as db from '../database'

export const typeDefs = gql`
extend type Query {
getAllEventos: [Evento]
getEvento(id: ID!): Evento
getEventoByEmpresa(id_empresa: ID!): [Evento]
}
extend type Mutation{
changeStatusPedido(id_evento: ID!, estado_pedido: String): Evento!
}
type Evento {
id_evento: ID!
nombre_evento: String
fecha: String
hora_inicio: String
hora_termino: String
estado_pedido: String
precio_entrada: Int
direccion_evento: String
lat_evento: String
lng_evento: String
descripcion_evento: String
id_empresa: ID!
}
`

export const resolvers = {
Mutation:{
changeStatusPedido: async (obj, args, context, info) =>{
console.log(args.id_empresa);
return Promise.all([
db.evento.update({ estado_pedido: args.estado_pedido},
{ where:{ id_evento: args.id_evento }})
]);

}
},

Query: {
getAllEventos: async () => db.evento.findAll(),
getEvento: async (obj, args, context, info) =>
db.evento.findByPk(args.id),
getEventoByEmpresa: async (obj, args, context, info) =>
db.evento.findAll({
where:{ id_empresa: args.id_empresa }
}),
},
}
35 changes: 35 additions & 0 deletions app/GraphQL/evento_usuario.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { gql } from 'apollo-server-express'
import * as db from '../database'

export const typeDefs = gql`
extend type Query {
getAllEventoUsuarios: [EventoUsuario]
getEventoUsuarioById(id: ID!): EventoUsuario
getEventoUsuarioByUserId(id_usuario: ID!): [EventoUsuario]
}
type EventoUsuario {
id: ID!
id_evento: Int
id_empresa: Int
id_usuario: ID!
evento: Evento
}
`
//getEventoUsuarioByEvento(id_evento: ID!): [EventoUsuario]

export const resolvers = {
Query: {
getAllEventoUsuarios: async () => db.evento_usuario.findAll(),
getEventoUsuarioById: async (obj, args, context, info) =>
db.evento_usuario.findByPk(args.id),
getEventoUsuarioByUserId: async (obj, args, context, info) =>
db.evento_usuario.findAll({
where:{id_usuario: args.id_usuario }
}),
},
EventoUsuario:{
evento: async (obj, args, context, info) =>
db.evento.findByPk(obj.id_evento),
},
}

40 changes: 40 additions & 0 deletions app/GraphQL/pedido.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { gql } from 'apollo-server-express'
import * as db from '../database'

export const typeDefs = gql`
extend type Query {
getAllPedidos: [Pedido]
getPedido(id: ID!): Pedido
getPedidoByUser(id_usuario: ID!): [Pedido]
getPedidoByEvento(id_evento: ID!): [Pedido]
}
type Pedido {
id_pedido: ID!
fecha_pedido: String
hora_pedido: String
turno_retiro: String
estado: String
id_usuario: ID!
total_pedido: String
id_evento: ID!
}
`

export const resolvers = {
Query: {
getAllPedidos: async () => db.pedido.findAll(),
getPedido: async (obj, args, context, info) =>
db.pedido.findByPk(args.id),
getPedidoByUser: async (obj, args, context, info) =>
db.pedido.findAll({
where:{id_usuario: args.id_usuario
}
}),
getPedidoByEvento: async (obj, args, context, info) =>
db.pedido.findAll({
where:{id_evento: args.id_evento
}
}),
},
}
23 changes: 0 additions & 23 deletions app/GraphQL/priorities.js

This file was deleted.

22 changes: 0 additions & 22 deletions app/GraphQL/status.js

This file was deleted.

40 changes: 0 additions & 40 deletions app/GraphQL/tickets.js

This file was deleted.

13 changes: 9 additions & 4 deletions app/GraphQL/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ export const typeDefs = gql`
}
type User {
id: ID!
id_usuario: ID!
nombre: String
apellido: String
telefono: String
email: String
name: String
rol_usuario: String
}
`

export const resolvers = {
Query: {
users: async () => db.users.findAll(),
user: async (obj, args, context, info) => db.users.findByPk(args.id),
users: async () => db.usuario.findAll(),
user: async (obj, args, context, info) => db.usuario.findByPk(args.id),
},
}


13 changes: 8 additions & 5 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@ const bodyParser = require('body-parser')
const { ApolloServer } = require('apollo-server-express')
const cors = require('cors')
const app = express()

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cors())


const server = new ApolloServer({
modules: [
require('./GraphQL/tickets'),
require('./GraphQL/status'),
require('./GraphQL/evento_usuario'),
require('./GraphQL/pedido'),
require('./GraphQL/users'),
require('./GraphQL/priorities'),
require('./GraphQL/evento'),
],
})


server.applyMiddleware({ app })

app.get('/', (req, res) => res.send('Hello World!'))

app.listen({ port: 5000 }, () =>
console.log(`🚀 Server ready at http://localhost:5000`),
app.listen({ port: 4000 }, () =>
console.log(`🚀 Server ready at http://localhost:4000`),
)
10 changes: 5 additions & 5 deletions app/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const Sequelize = require('sequelize')

var db = {}

const sequelize = new Sequelize('graphql-mysql-tutorial', 'graphql', '123456', {
const sequelize = new Sequelize('compras_db', 'user_dev', 'azsxdc', {
host: 'localhost',
port: '8006',
port: '3306',
dialect: 'mysql',
define: {
freezeTableName: true,
Expand All @@ -20,9 +20,9 @@ const sequelize = new Sequelize('graphql-mysql-tutorial', 'graphql', '123456', {
})

let models = [
require('./models/priorities.js'),
require('./models/status.js'),
require('./models/tickets.js'),
require('./models/evento_usuario.js'),
require('./models/pedido.js'),
require('./models/evento.js'),
require('./models/users.js'),
]

Expand Down
Empty file removed app/models/.gitkeep
Empty file.
62 changes: 62 additions & 0 deletions app/models/evento.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

module.exports = function(sequelize, DataTypes) {
return sequelize.define('evento', {
id_evento: {
type: DataTypes.INTEGER(10).UNSIGNED,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
nombre_evento: {
type: DataTypes.STRING(256),
allowNull: false
},
fecha: {
type: DataTypes.STRING(256),
allowNull: false
},
hora_inicio: {
type: DataTypes.STRING(256),
allowNull: false
},
hora_termino: {
type: DataTypes.STRING(256),
allowNull: false
},
estado_pedido: {
type: DataTypes.STRING(256),
allowNull: false
},
precio_entrada: {
type: DataTypes.INTEGER(11),
allowNull: false
},
direccion_evento: {
type: DataTypes.STRING(256),
allowNull: false
},
lat_evento: {
type: DataTypes.STRING(256),
allowNull: false
},
lng_evento: {
type: DataTypes.STRING(256),
allowNull: false
},
descripcion_evento: {
type: DataTypes.STRING,
allowNull: false
},
id_empresa: {
type: DataTypes.INTEGER(11),
allowNull: false,
references: {
model: 'empresa',
key: 'id_empresa'
}
}
}, {
tableName: 'evento',
timestamps: false
});
};
Loading

0 comments on commit bb850d9

Please sign in to comment.