Merged PetitTetonApps with the website now that the deployment server always uses SSL. Used the Apps more recent implementation of NodeJS/Express.

This commit is contained in:
Wynne Crisman
2016-05-31 14:37:42 -07:00
parent a98d7d3a5f
commit 78be012a14
192 changed files with 58459 additions and 19 deletions

31
app/models/category.js Normal file
View File

@@ -0,0 +1,31 @@
"use strict";
module.exports = function(sequelize, DataTypes) {
//The id field is auto added and made primary key.
var Category = sequelize.define('Category', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true
},
name: {
type: DataTypes.STRING,
allowNull: false
},
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
}
}, {
freezeTableName: true, // Model tableName will be the same as the model name
classMethods: {
associate: function(models) {
Category.hasMany(models.Subcategory, {as: 'subcategories', foreignKey: {name: 'categoryId', field: 'categoryId'}});
}
}
});
return Category;
};

32
app/models/index.js Normal file
View File

@@ -0,0 +1,32 @@
"use strict";
var fs = require("fs");
var path = require("path");
var Sequelize = require("sequelize");
var env = process.env.NODE_ENV || "development";
//var config = require(__dirname + '/../config/config.json')[env];
var configDB = require('./../../config/database.js');
//var sequelize = new Sequelize(config.database, config.username, config.password, config);
var sequelize = new Sequelize(configDB.url);
var db = {};
fs
.readdirSync(__dirname)
.filter(function(file) {
return (file.indexOf(".") !== 0) && (file !== "index.js");
})
.forEach(function(file) {
var model = sequelize.import(path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(function(modelName) {
if ("associate" in db[modelName]) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;

35
app/models/item.js Normal file
View File

@@ -0,0 +1,35 @@
"use strict";
module.exports = function(sequelize, DataTypes) {
//The id field is auto added and made primary key.
var Item = sequelize.define('Item', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true
},
name: {
type: DataTypes.STRING,
allowNull: false
},
counts: {
type: DataTypes.JSON,
allowNull: false
},
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
}
}, {
freezeTableName: true, // Model tableName will be the same as the model name
classMethods: {
associate: function(models) {
Item.belongsTo(models.Subcategory, {as: 'subcategory', foreignKey: {name: 'subcategoryId', field: 'subcategoryId'}});
}
}
});
return Item;
};

32
app/models/measure.js Normal file
View File

@@ -0,0 +1,32 @@
"use strict";
module.exports = function(sequelize, DataTypes) {
//The id field is auto added and made primary key.
return sequelize.define('Measure', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true
},
name: {
type: DataTypes.STRING,
allowNull: false
},
image: {
type: DataTypes.STRING,
allowNull: true
},
postfix: {
type: DataTypes.STRING,
allowNull: false
},
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
}
}, {
freezeTableName: true // Model tableName will be the same as the model name
});
};

33
app/models/sale.js Normal file
View File

@@ -0,0 +1,33 @@
"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.DATE,
allowNull: false
},
measure: {
type: DataTypes.JSONB,
allowNull: false
}
}, {
freezeTableName: true, // Model tableName will be the same as the model name
classMethods: {
associate: function(models) {
//Sale.hasOne(models.Category, {as: 'category'});
//Sale.hasOne(models.Subcategory, {as: 'subcategory'});
Sale.belongsTo(models.Item, {as: 'item', foreignKey: {name: 'itemId', field: 'itemId'}});
Sale.belongsTo(models.Venue, {as: 'venue', foreignKey: {name: 'venueId', field: 'venueId'}});
}
}
});
return Sale;
};

34
app/models/subcategory.js Normal file
View File

@@ -0,0 +1,34 @@
"use strict";
module.exports = function(sequelize, DataTypes) {
//The id field is auto added and made primary key.
var Subcategory = sequelize.define('Subcategory', {
id: {
type: DataTypes.INTEGER,
field: 'id',
primaryKey: true,
allowNull: false,
autoIncrement: true
},
name: {
type: DataTypes.STRING,
field: 'name',
allowNull: false
},
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
}
}, {
freezeTableName: true, // Model tableName will be the same as the model name
classMethods: {
associate: function(models) {
Subcategory.belongsTo(models.Category, {as: 'category', foreignKey: {name: 'categoryId', field: 'categoryId'}});
Subcategory.hasMany(models.Item, {as: 'items', foreignKey: {name: 'subcategoryId', field: 'subcategoryId'}});
}
}
});
return Subcategory;
};

25
app/models/user.js Normal file
View File

@@ -0,0 +1,25 @@
"use strict";
var bcrypt = require('bcrypt-nodejs');
module.exports = function(sequelize, DataTypes) {
//The id field is auto added and made primary key.
return sequelize.define('User', {
login: {
type: DataTypes.STRING
},
password: {
type: DataTypes.STRING
}
}, {
freezeTableName: true, // Model tableName will be the same as the model name
instanceMethods: {
generateHash: function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
},
validPassword: function(password) {
return bcrypt.compareSync(password, this.password);
}
}
});
};

24
app/models/venue.js Normal file
View File

@@ -0,0 +1,24 @@
"use strict";
module.exports = function(sequelize, DataTypes) {
//The id field is auto added and made primary key.
return sequelize.define('Venue', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true
},
name: {
type: DataTypes.STRING,
allowNull: false
},
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
}
}, {
freezeTableName: true // Model tableName will be the same as the model name
});
};