51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
"use strict";
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
//The id field is auto added and made primary key.
|
|
var Sale = sequelize.define('Sale', {
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
primaryKey: true,
|
|
allowNull: false,
|
|
autoIncrement: true
|
|
},
|
|
date: {
|
|
type: DataTypes.DATEONLY,
|
|
allowNull: false
|
|
},
|
|
amount: {
|
|
type: DataTypes.DECIMAL(13,2),
|
|
allowNull: false
|
|
},
|
|
price: {
|
|
//GAAP standard is to use DECIMAL(13,4) for precision when dealing with money. 13 digits before the decimal, and 4 after it.
|
|
type: DataTypes.DECIMAL(13,4),
|
|
allowNull: false
|
|
},
|
|
createdAt: {
|
|
type: DataTypes.DATE,
|
|
allowNull: false
|
|
},
|
|
updatedAt: {
|
|
type: DataTypes.DATE,
|
|
allowNull: false
|
|
},
|
|
deletedAt: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true
|
|
}
|
|
}, {
|
|
freezeTableName: true, // Model tableName will be the same as the model name
|
|
paranoid: true,
|
|
classMethods: {
|
|
associate: function(models) {
|
|
Sale.belongsTo(models.Item, {as: 'item', foreignKey: {name: 'itemId', field: 'itemId'}});
|
|
Sale.belongsTo(models.Venue, {as: 'venue', foreignKey: {name: 'venueId', field: 'venueId'}});
|
|
Sale.belongsTo(models.Measure, {as: 'measure', foreignKey: {name: 'measureId', field: 'measureId'}});
|
|
}
|
|
}
|
|
});
|
|
|
|
return Sale;
|
|
};
|