Skip to content

Commit

Permalink
Refactor order and order model.
Browse files Browse the repository at this point in the history
  • Loading branch information
HranikBs23 committed Feb 20, 2022
1 parent 205230f commit 2bcd290
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
3 changes: 0 additions & 3 deletions src/modules/order/order-product.model.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const path = require('path');
const sequelize = require(path.join(process.cwd(), 'src/config/lib/sequelize'));
const Product = require(path.join(process.cwd(), "src/modules/product/product.model"));
const { DataTypes } = require('sequelize');

const OrderProduct = sequelize.define('order_products', {
Expand Down Expand Up @@ -29,6 +28,4 @@ const OrderProduct = sequelize.define('order_products', {
updatedAt: 'updated_at'
});

OrderProduct.belongsTo(Product, { as: "product", foreignKey: "product_id" });

module.exports = OrderProduct;
9 changes: 2 additions & 7 deletions src/modules/order/order.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Order = sequelize.define('orders', {
},
total_price: {
allowNull: false,
type: DataTypes.INTEGER
type: DataTypes.DECIMAL(10, 2)
},
staus: {
type: DataTypes.ENUM,
Expand All @@ -30,12 +30,6 @@ const Order = sequelize.define('orders', {
values: ['process-pending', 'processing', 'success', 'failed'],
defaultValue: 'process-pending'
},
created_by: {
type: DataTypes.INTEGER
},
updated_by: {
type: DataTypes.INTEGER
}
}, {
tableName: 'orders',
timestamps: true,
Expand All @@ -46,6 +40,7 @@ const Order = sequelize.define('orders', {
Customer.hasMany(Order, { as: 'orders', foreignKey: 'customer_id' });
Order.belongsTo(Customer, { as: 'customer', foreignKey: 'customer_id' });
Order.hasMany(OrderProduct, { as: 'order_products', foreignKey: 'order-product_id' });
OrderProduct.belongsTo(Product, { as: "product", foreignKey: "product_id" });

const OrderModel = new Order;
module.exports = OrderModel;

0 comments on commit 2bcd290

Please sign in to comment.