'use strict';
module.exports = {
async up (queryInterface, Sequelize) {
await queryInterface.createTable('Smetas', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
patientName: {
allowNull: true,
type: Sequelize.STRING
},
patientBirthDate: {
type: Sequelize.STRING,
allowNull: true,
},
patientPromoter: {
type: Sequelize.STRING,
allowNull: true,
},
createdAt: {
allowNull: true,
type: Sequelize.DATE
},
updatedAt: {
allowNull: true,
type: Sequelize.DATE
}
});
},
async down (queryInterface, Sequelize) {
await queryInterface.dropTable('Smetas');
}
};
'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('SmetaCheckupPlans', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
kind: {
type: Sequelize.TEXT
},
supplier: {
type: Sequelize.TEXT
},
address: {
type: Sequelize.TEXT
},
phone: {
type: Sequelize.TEXT
},
price: {
type: Sequelize.TEXT
},
smetaId: {
type: Sequelize.INTEGER,
onDelete: 'CASCADE',
references: {
model: 'Smetas',
key: 'id',
as: 'smetaId',
}
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('SmetaCheckupPlans');
}
};
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Smeta 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
console.log('Associating Smeta with SmetaCheckupPlan');
Smeta.hasMany(models.SmetaCheckupPlan, {
foreignKey: 'smetaId',
onDelete: 'cascade'
})
Smeta.hasMany(models.AdditionalCost, {
foreignKey: 'smetaId',
onDelete: 'cascade'
})
}
}
Smeta.init({
patientPromoter: DataTypes.STRING,
patientName: DataTypes.STRING,
patientBirthDate: DataTypes.STRING,
applId:DataTypes.STRING, // это я сделал доп миграцией addColumn и тоже строку вручную добавил
execDate: DataTypes.STRING
}, {
sequelize,
modelName: 'Smeta',
tableName:'Smetas'
});
return Smeta;
};
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class SmetaCheckupPlan extends Model {
static associate(models) {
console.log('Associating SmetaCheckupPlan with Smeta');
// define association here
SmetaCheckupPlan.belongsTo(models.Smeta, {
foreignKey: 'smetaId',
onDelete: 'CASCADE'
})
}
}
SmetaCheckupPlan.init({
kind: DataTypes.TEXT,
supplier: DataTypes.TEXT,
address: DataTypes.TEXT,
phone:DataTypes.TEXT,
price: DataTypes.TEXT,
}, {
sequelize,
modelName: 'SmetaCheckupPlan',
});
return SmetaCheckupPlan;
};
result = await SmetaCheckupPlan.create({...plan});
await result.setSmeta(smetaData);
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
//session expires after 3 hours
cookie: { maxAge: 60 * 1000 * 60 * 3 },
})
);
app.use("/api", routes);
//routes
router.use("/cart", cart);
// cart
router.route("/add").post( async (req, res) => {
const cart_id = req.user?.cart_id;
console.log(' req.user', req.user);
console.log('session',req.session);
if ( req.session.cart) {
console.log('req.session.cart YES');
req.session.cart.items+=1
}
else {
console.log('req.session.cart NO');
req.session.cart={items:1}
}
console.log('session',req.session);
// const cart = await cartService.addItem({ ...req.body, cart_id });
res.status(200).json({ data: 'cart' });
};); //те каждый раз я увеличиваю item на 1
//получение кол-ва
router.route("/qty").get(async (req, res) => {
const cart = req.session.cart
console.log('sess',cart);
if (cart) {
res.json(cart.items);
}
else {
res.json({qty:10});
}
};);
await fetch(...)
} не обьявлять внутри компонента а создавать где нить в другом файле скажем /api/someservice.js ?