Advertisement
Guest User

Untitled

a guest
Apr 20th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*MODELS*/
  2. const Sequelize = require('sequelize'),
  3.     sequelize = new Sequelize('directory','direc','9696Gory!',{
  4.         dialect: 'mysql',
  5.         host: '45.84.255.226'
  6.     }),
  7.     left = sequelize.define('left',{
  8.         id:{
  9.             type: Sequelize.INTEGER,
  10.             autoIncrement: true,
  11.             primaryKey: true,
  12.             allowNull: false
  13.         },
  14.         name:{
  15.             type: Sequelize.STRING,
  16.             allowNull: false
  17.         }
  18.     },{
  19.         timestamps: false,
  20.         freezeTableName: true
  21.     }),
  22.     main = sequelize.define('main',{
  23.         id:{
  24.             type: Sequelize.INTEGER,
  25.             autoIncrement: true,
  26.             primaryKey: true,
  27.             allowNull: false
  28.         },
  29.         name:{
  30.             type: Sequelize.STRING,
  31.             allowNull: false
  32.         }
  33.     },{
  34.         timestamps: false,
  35.         freezeTableName: true
  36.     }),
  37.     data = sequelize.define('data',{
  38.         id:{
  39.             type: Sequelize.INTEGER,
  40.             autoIncrement: true,
  41.             primaryKey: true,
  42.             allowNull: false
  43.         },
  44.         function:{
  45.             type: Sequelize.STRING,
  46.             allowNull: false
  47.         },
  48.         name:{
  49.             type: Sequelize.STRING,
  50.             allowNull: false
  51.         },
  52.         cabinet:{
  53.             type: Sequelize.STRING,
  54.             allowNull: false
  55.         },
  56.         phone:{
  57.             type: Sequelize.STRING,
  58.             allowNull: false
  59.         }
  60.     },{
  61.         timestamps: false,
  62.         freezeTableName: true
  63.     }),
  64.     m_l = sequelize.define('m_l',{
  65.         id:{
  66.             type: Sequelize.INTEGER,
  67.             autoIncrement: true,
  68.             primaryKey: true,
  69.             allowNull: false
  70.         }
  71.     },{
  72.         timestamps: false,
  73.         freezeTableName: true
  74.     }),
  75.     l_d = sequelize.define('m_d',{
  76.         id:{
  77.             type: Sequelize.INTEGER,
  78.             autoIncrement: true,
  79.             primaryKey: true,
  80.             allowNull: false
  81.         }
  82.     },{
  83.         timestamps: false,
  84.         freezeTableName: true
  85.     });
  86.  
  87. main.belongsToMany(left,{through: m_l});
  88. left.belongsToMany(main,{through: m_l});
  89.  
  90. data.belongsToMany(left,{through: l_d});
  91. left.belongsToMany(data,{through: l_d});
  92.  
  93. module.exports = {
  94.     left,
  95.     main,
  96.     data,
  97.     m_l,
  98.     l_d
  99. }
  100.  
  101.  
  102. /* ROUTES */
  103. const express = require('express'),
  104.     router = express.Router(),
  105.     models = require('../models');
  106.  
  107. router.post('/view-content',(request,response)=>{
  108.     models.db.data.findAll({
  109.         include:[{
  110.             model: models.db.left,
  111.             where: {
  112.                 id: request.body.left
  113.             },
  114.             include:[{
  115.                 model: models.db.main,
  116.                 where: {
  117.                     id: request.body.main
  118.                 }
  119.             }]
  120.         }]
  121.     })
  122.         .then(all=>{
  123.  
  124.         })
  125.         .catch(err=>console.log(err));
  126. });
  127.  
  128. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement