Skip to content

Commit

Permalink
converted es6 code works
Browse files Browse the repository at this point in the history
  • Loading branch information
Uncle Charlie committed Mar 12, 2017
1 parent 9ae572b commit bc35357
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 53 deletions.
7 changes: 7 additions & 0 deletions server/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": ["es2015", "stage-2", "react"],
"plugins": ["syntax-async-functions","transform-regenerator", "transform-object-assign",
"transform-object-rest-spread","transform-react-jsx-source"],
"sourceMaps": true,
"retainLines": true
}
20 changes: 11 additions & 9 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
*/

import 'babel-polyfill'
import express from 'express';
import mongoose from 'mongoose';
import hbs from 'express-hbs';
import express from 'express';
import mongoose from 'mongoose';
import hbs from 'express-hbs';

import SiteServer from './SiteServer';
import models from './models';
import api from './controllers/api';
import SiteServer from './SiteServer';
import models from './models';
import api from './controllers/api';
import middleware from './middleware';
import helpers from './helpers';
import errors from './errors';
import helpers from './helpers';
import errors from './errors';

function init() {
var apiApp = express(), // API
Expand All @@ -23,7 +23,9 @@ function init() {
// TODO: configure this connection string.
mongoose.connect('mongodb://localhost:27017/petshop');
}).then(() => {
models.init();
// no longer needed, no dynamic load for import key word
// models.init();
console.log('===>models init');
}).then(() => {
api.init();
}).then(() => {
Expand Down
2 changes: 2 additions & 0 deletions server/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ passport.use(new BasicStrategy(
// return done(err);
// });

console.log('===>controller/auth, 61', dataProvider);

dataProvider.User.findOne({ username: username }).exec().then((u) => {
if (!u) {
done(null, false);
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/pet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import * as _ from 'lodash'
import utils from '../utils'
import dataProvider from '../models/pet'
import dataProvider from '../models'
// import Accessory from '../models/accessory').model;

var postPets = function (req, res) {
Expand Down
11 changes: 4 additions & 7 deletions server/models/accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import mongoose from './base';

var Schema = mongoose.BaseSchema;

var AccessorySchema = new Schema({
name: {type: String, required: true},
price: {type: Number, required: true}
export var AccessorySchema = new Schema({
name: { type: String, required: true },
price: { type: Number, required: true }
});

export default {
schema: AccessorySchema,
model: mongoose.model('accessories', AccessorySchema)
};
export default mongoose.model('accessories', AccessorySchema);
4 changes: 1 addition & 3 deletions server/models/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ var clientSchema = new mongoose.BaseSchema({
userId: {type: String, required: true}
});

export default {
Client: mongoose.model('client', clientSchema)
};
export default mongoose.model('client', clientSchema);
14 changes: 6 additions & 8 deletions server/models/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
* Created by Uncle Charlie, 2017/03/01
*/

import mongoose from './base';
import mongoose from './base';
var Schema = mongoose.BaseSchema;

var codeSchema = new Schema({
value: {type: String, required: true},
redirectUri: {type: String, required: true},
userId: {type: String, required: true},
clientId: {type: String, required: true}
value: { type: String, required: true },
redirectUri: { type: String, required: true },
userId: { type: String, required: true },
clientId: { type: String, required: true }
});

module.exports = {
Code: mongoose.model('code', codeSchema)
};
export default mongoose.model('code', codeSchema);
51 changes: 35 additions & 16 deletions server/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,43 @@

import * as _ from 'lodash';

let exports = module.exports;
// let exports = module.exports;

let models = [
'accessory',
'client',
'code',
'pet',
'token',
'user'
];
// let models = [
// 'accessory',
// 'client',
// 'code',
// 'pet',
// 'token',
// 'user'
// ];

function init() {
exports.Base = require('./base');
// function init() {
// exports.Base = require('./base');

models.forEach(function (name) {
_.extend(exports, require('./' + name));
});
}
// models.forEach(function (name) {
// _.extend(exports, require('./' + name));
// });
// }

// // exports.init = init;
// exports.init = init;
exports.init = init;


import _user from './user';
import _accessory, { AccessorySchema } from './accessory';
import _client from './client';
import _code from './code';
import _pet from './pet';
import _token from './token';

export default {
User: _user,
Accessory: _accessory,
Client: _client,
Code: _code,
Pet: _pet,
Token: _token,
AccessorySchema,
init: () => { console.log('===> models init()') }
};
4 changes: 1 addition & 3 deletions server/models/pet.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,4 @@ petSchema.static('findFull', function (options, callback) {
// return this.find({}).populate('users').exec(callback);
});

export default {
Pet: mongoose.model('pet', petSchema)
};
export default mongoose.model('pet', petSchema);
4 changes: 1 addition & 3 deletions server/models/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ var tokenSchema = new Schema({
clientId: { type: String, required: true }
});

export default {
Token: mongoose.model('token', tokenSchema)
};
export default mongoose.model('token', tokenSchema);
4 changes: 1 addition & 3 deletions server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,4 @@ userSchema.methods.verifyPassword = function (password, callback) {
});
};

export default {
User: mongoose.model('User', userSchema)
};
export default mongoose.model('User', userSchema);

0 comments on commit bc35357

Please sign in to comment.