Commit project

This commit is contained in:
Rodrigo Pedroso 2019-06-19 10:46:14 -04:00
commit 3ac017a5ad
1030 changed files with 94062 additions and 0 deletions

21
models/branch.js Normal file
View file

@ -0,0 +1,21 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var BranchSchema = new Schema({
branch_name: String,
number: Number,
street: String,
street_2: String,
city: String,
province: String,
postal_code: String,
country: String,
telephone: String,
cellular: String,
telephone_other: String,
merchant_id: { type: Schema.Types.ObjectId, ref: 'Merchant' }
}, {timestamps: true});
module.exports = mongoose.model('Branch', BranchSchema);

24
models/client.js Normal file
View file

@ -0,0 +1,24 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ClientSchema = new Schema({
client_name: String,
number: Number,
street: String,
street_2: String,
city: String,
province: String,
postal_code: String,
country: String,
client_email: String,
telephone: String,
cellular: String,
telephone_other: String,
birthday: String,
merchant_id: { type: Schema.Types.ObjectId, ref: 'Merchant' },
branch_id: { type: Schema.Types.ObjectId, ref: 'Branch' }
}, {timestamps: true});
module.exports = mongoose.model('Client', ClientSchema);

13
models/employee.js Normal file
View file

@ -0,0 +1,13 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var EmployeeSchema = new Schema({
merchant_id: { type: Schema.Types.ObjectId, ref: 'Merchant' },
branch_id: { type: Schema.Types.ObjectId, ref: 'Branch' },
employee_number: Number,
employee_name: String
}, {timestamps: true});
module.exports = mongoose.model('Employee', EmployeeSchema);

16
models/gift-card.js Normal file
View file

@ -0,0 +1,16 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var GiftCardSchema = new Schema({
gift_card_number: String,
merchant_id: { type: Schema.Types.ObjectId, ref: 'Merchant' },
client_id: { type: Schema.Types.ObjectId, ref: 'Client' },
branch_id: { type: Schema.Types.ObjectId, ref: 'Branch' },
number: Number,
balance: Number,
points: Number
}, {timestamps: true});
module.exports = mongoose.model('GiftCard', GiftCardSchema);

18
models/index.js Normal file
View file

@ -0,0 +1,18 @@
const mongoose = require('mongoose');
module.exports.connect = (uri) => {
mongoose.connect(uri, {
useMongoClient: true,
});
// plug in the promise library:
mongoose.Promise = require('bluebird');
mongoose.connection.on('error', (err) => {
console.error(`Mongoose connection error: ${err}`);
process.exit(1);
});
// load models
require('./merchant');
};

55
models/merchant.js Normal file
View file

@ -0,0 +1,55 @@
'use strict';
var mongoose = require('mongoose');
var bcrypt = require('bcrypt');
var Schema = mongoose.Schema;
var MerchantSchema = new Schema({
name: String,
password: String,
merchant_email: {
type: String,
index: { unique: true }
},
merchant_name: String,
language: String,
street: String,
street_2: String,
city: String,
province: String,
postal_code: String,
country: String,
telephone: String,
cellular: String,
telephone_other: String,
number: Number
}, {timestamps: true});
MerchantSchema.methods.comparePassword = function comparePassword(password, callback) {
bcrypt.compare(password, this.password, callback);
};
MerchantSchema.pre('save', function saveHook(next) {
let user = this;
// proceed only if password is modified or the user is new
if (!user.isModified('password')) {
return next();
}
return bcrypt.genSalt((saltError, salt) => {
if (saltError) {
return next(saltError);
}
return bcrypt.hash(user.password, salt, (hashError, hash) => {
if (hashError) {
return next(hashError);
}
// Replace password string with hash value
user.password = hash;
return next();
});
});
});
module.exports = mongoose.model('Merchant', MerchantSchema);

26
models/transaction.js Normal file
View file

@ -0,0 +1,26 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var TransactionSchema = new Schema({
merchant_id: { type: Schema.Types.ObjectId, ref: 'Merchant' },
client_id: { type: Schema.Types.ObjectId, ref: 'Client' },
branch_id: { type: Schema.Types.ObjectId, ref: 'Branch' },
employee_id: { type: Schema.Types.ObjectId, ref: 'Employee' },
workstation_id: { type: Schema.Types.ObjectId, ref: 'Workstation' },
serial_number: String,
invoice: String,
type: String,
gift_card_id: { type: Schema.Types.ObjectId, ref: 'GiftCard' },
gift_card_number: String,
loyalty_card_id: { type: Schema.Types.ObjectId, ref: 'LoyaltyCard' },
money_amount: Number,
points_amount: Number,
cancelled_transaction_id: { type: Schema.Types.ObjectId, ref: 'Transaction'},
cancelled: Boolean,
remainder: Number,
message: String
}, {timestamps: true});
module.exports = mongoose.model('Transaction', TransactionSchema);

14
models/workstation.js Normal file
View file

@ -0,0 +1,14 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var WorkstationSchema = new Schema({
serial_number: String,
number: Number,
merchant_id: { type: Schema.Types.ObjectId, ref: 'Merchant' },
branch_id: { type: Schema.Types.ObjectId, ref: 'Branch' },
workstation_name: String
}, {timestamps: true});
module.exports = mongoose.model('Workstation', WorkstationSchema);