Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*MODELS*/
- const Sequelize = require('sequelize'),
- sequelize = new Sequelize('directory','direc','9696Gory!',{
- dialect: 'mysql',
- host: '45.84.255.226'
- }),
- left = sequelize.define('left',{
- id:{
- type: Sequelize.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- allowNull: false
- },
- name:{
- type: Sequelize.STRING,
- allowNull: false
- }
- },{
- timestamps: false,
- freezeTableName: true
- }),
- main = sequelize.define('main',{
- id:{
- type: Sequelize.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- allowNull: false
- },
- name:{
- type: Sequelize.STRING,
- allowNull: false
- }
- },{
- timestamps: false,
- freezeTableName: true
- }),
- data = sequelize.define('data',{
- id:{
- type: Sequelize.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- allowNull: false
- },
- function:{
- type: Sequelize.STRING,
- allowNull: false
- },
- name:{
- type: Sequelize.STRING,
- allowNull: false
- },
- cabinet:{
- type: Sequelize.STRING,
- allowNull: false
- },
- phone:{
- type: Sequelize.STRING,
- allowNull: false
- }
- },{
- timestamps: false,
- freezeTableName: true
- }),
- m_l = sequelize.define('m_l',{
- id:{
- type: Sequelize.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- allowNull: false
- }
- },{
- timestamps: false,
- freezeTableName: true
- }),
- l_d = sequelize.define('m_d',{
- id:{
- type: Sequelize.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- allowNull: false
- }
- },{
- timestamps: false,
- freezeTableName: true
- });
- main.belongsToMany(left,{through: m_l});
- left.belongsToMany(main,{through: m_l});
- data.belongsToMany(left,{through: l_d});
- left.belongsToMany(data,{through: l_d});
- module.exports = {
- left,
- main,
- data,
- m_l,
- l_d
- }
- /* ROUTES */
- const express = require('express'),
- router = express.Router(),
- models = require('../models');
- router.post('/view-content',(request,response)=>{
- models.db.data.findAll({
- include:[{
- model: models.db.left,
- where: {
- id: request.body.left
- },
- include:[{
- model: models.db.main,
- where: {
- id: request.body.main
- }
- }]
- }]
- })
- .then(all=>{
- })
- .catch(err=>console.log(err));
- });
- module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement