update
This commit is contained in:
		
							parent
							
								
									161f5ff914
								
							
						
					
					
						commit
						e6784eb666
					
				@ -1,14 +1,14 @@
 | 
			
		||||
{
 | 
			
		||||
  "development": {
 | 
			
		||||
    ""
 | 
			
		||||
    "dialect": "mysql"
 | 
			
		||||
    "storage": "./database/development.sqlite",
 | 
			
		||||
    "dialect": "sqlite"
 | 
			
		||||
  },
 | 
			
		||||
  "test": {
 | 
			
		||||
    
 | 
			
		||||
    "dialect": "mysql"
 | 
			
		||||
    "storage": "./database/test.sqlite",
 | 
			
		||||
    "dialect": "sqlite"
 | 
			
		||||
  },
 | 
			
		||||
  "production": {
 | 
			
		||||
    
 | 
			
		||||
    "dialect": "mysql"
 | 
			
		||||
    "storage": "./database/production.sqlite",
 | 
			
		||||
    "dialect": "sqlite"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,6 @@
 | 
			
		||||
const Produto = require('../models/produto');
 | 
			
		||||
const produtos = new Produto();
 | 
			
		||||
//const Produto = require('../models/produto');
 | 
			
		||||
//const produtos = new Produto();
 | 
			
		||||
const { produto } = require('../models');
 | 
			
		||||
 | 
			
		||||
const listar = function(req, res){ 
 | 
			
		||||
  res.render('produtos/listar', {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								database/development.sqlite
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								database/development.sqlite
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										36
									
								
								migrations/20241129012306-create-produto.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								migrations/20241129012306-create-produto.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
			
		||||
'use strict';
 | 
			
		||||
/** @type {import('sequelize-cli').Migration} */
 | 
			
		||||
module.exports = {
 | 
			
		||||
  async up(queryInterface, Sequelize) {
 | 
			
		||||
    await queryInterface.createTable('produtos', {
 | 
			
		||||
      id: {
 | 
			
		||||
        allowNull: false,
 | 
			
		||||
        autoIncrement: true,
 | 
			
		||||
        primaryKey: true,
 | 
			
		||||
        type: Sequelize.INTEGER
 | 
			
		||||
      },
 | 
			
		||||
      nome: {
 | 
			
		||||
        type: Sequelize.STRING
 | 
			
		||||
      },
 | 
			
		||||
      preco: {
 | 
			
		||||
        type: Sequelize.FLOAT
 | 
			
		||||
      },
 | 
			
		||||
      imagem: {
 | 
			
		||||
        type: Sequelize.STRING
 | 
			
		||||
      },
 | 
			
		||||
      createdAt: {
 | 
			
		||||
        allowNull: false,
 | 
			
		||||
        type: Sequelize.DATE,
 | 
			
		||||
        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
 | 
			
		||||
      },
 | 
			
		||||
      updatedAt: {
 | 
			
		||||
        allowNull: false,
 | 
			
		||||
        type: Sequelize.DATE,
 | 
			
		||||
        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  },
 | 
			
		||||
  async down(queryInterface, Sequelize) {
 | 
			
		||||
    await queryInterface.dropTable('produtos');
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
@ -1,15 +1,25 @@
 | 
			
		||||
class Produto {
 | 
			
		||||
  listar(){
 | 
			
		||||
    return [
 | 
			
		||||
      {id: 1, nome: 'Produto 1', preco: '20.00', imagem: 'https://picsum.photos/200/300'},
 | 
			
		||||
      {id: 2, nome: 'Produto 2', preco: '30.00', imagem: 'https://picsum.photos/200/300'},
 | 
			
		||||
      {id: 3, nome: 'Produto 3', preco: '40.00', imagem: 'https://picsum.photos/200/300'},
 | 
			
		||||
    ]
 | 
			
		||||
'use strict';
 | 
			
		||||
const {
 | 
			
		||||
  Model
 | 
			
		||||
} = require('sequelize');
 | 
			
		||||
module.exports = (sequelize, DataTypes) => {
 | 
			
		||||
  class produto extends Model {
 | 
			
		||||
    /**
 | 
			
		||||
     * Helper method for defining associations.
 | 
			
		||||
     * This method is not a part of Sequelize lifecycle.
 | 
			
		||||
     * The `models/index` file will call this method automatically.
 | 
			
		||||
     */
 | 
			
		||||
    static associate(models) {
 | 
			
		||||
      // define association here
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  buscarPorID(id){
 | 
			
		||||
    return this.listar().find(produto => produto.id == id)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = Produto
 | 
			
		||||
  produto.init({
 | 
			
		||||
    nome: DataTypes.STRING,
 | 
			
		||||
    preco: DataTypes.FLOAT,
 | 
			
		||||
    imagem: DataTypes.STRING
 | 
			
		||||
  }, {
 | 
			
		||||
    sequelize,
 | 
			
		||||
    modelName: 'produto',
 | 
			
		||||
  });
 | 
			
		||||
  return produto;
 | 
			
		||||
};
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user