diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..e69de29 diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 0000000..4a58bdc --- /dev/null +++ b/.flowconfig @@ -0,0 +1,7 @@ +[ignore] + +[include] + +[libs] + +[options] diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 1c8c958..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "packages/mongoose-polymorphic"] - path = packages/mongoose-polymorphic - url = https://github.com/ForsakenHarmony/mongoose-polymorphic.git diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000..c17ea7c --- /dev/null +++ b/src/config.js @@ -0,0 +1,3 @@ +/** + * Created by ForsakenHarmony on 19/03/17. + */ diff --git a/src/db/index.js b/src/db/index.js new file mode 100644 index 0000000..f77bd98 --- /dev/null +++ b/src/db/index.js @@ -0,0 +1,17 @@ +const mongoose = require('mongoose'); +mongoose.Promise = global.Promise; +const config = require.main.require('./config'); + +const models = require('./models'); + +mongoose.connect(config.mongoHost, 'chime'); + +module.exports = { + mongoose, + User : models.User, + Token : models.Token, + Comment : models.Comment, + Like : models.Like, + Notification: models.Notification, + Post : models.Post, +}; diff --git a/src/db/model.js b/src/db/model.js deleted file mode 100644 index 78da938..0000000 --- a/src/db/model.js +++ /dev/null @@ -1,19 +0,0 @@ -// TODO: entities maybe as an object - -exports.init = (mongoose, app) => { - const user = require('./models/user').init(mongoose); - const token = require('./models/token').init(mongoose, app.context.secret);// TODO - const post = require('./models/post').init(mongoose); - const comment = require('./models/comment').init(mongoose); - const follow = require('./models/follow').init(mongoose); - const like = require('./models/like').init(mongoose); - - return { - user, - token, - post, - comment, - follow, - like, - }; -}; diff --git a/src/db/models/index.js b/src/db/models/index.js new file mode 100644 index 0000000..c17ea7c --- /dev/null +++ b/src/db/models/index.js @@ -0,0 +1,3 @@ +/** + * Created by ForsakenHarmony on 19/03/17. + */ diff --git a/src/db/models/notification.js b/src/db/models/notification.js new file mode 100644 index 0000000..ef472e4 --- /dev/null +++ b/src/db/models/notification.js @@ -0,0 +1,26 @@ +const polymorphic = require('mongoose-polymorphic'); + +exports.init = (mongoose) => { + const Schema = mongoose.Schema; + + const schema = new Schema({ + user : { type: Schema.Types.ObjectId, ref: 'User', required: true }, + notifier : { type: Schema.Types.ObjectId, ref: 'User', required: true }, + type : { type: String, maxlength: 32, required: true }, + created_at: { type: Date, default: Date.now }, + updated_at: { type: Date, default: Date.now }, + }); + + schema.plugin(polymorphic, { + associationKey: 'object', + promise : global.Promise, + required : true + }); + + schema.pre('save', function (next) { + this.updated_at = Date.now(); + next(); + }); + + return mongoose.model('Notifications', schema); +}; \ No newline at end of file diff --git a/src/db/mongo.js b/src/db/mongo.js deleted file mode 100644 index 20c3bf4..0000000 --- a/src/db/mongo.js +++ /dev/null @@ -1,13 +0,0 @@ -const mongoose = require('mongoose'); -mongoose.Promise = global.Promise; - -const model = require('./model'); - -exports.init = (app) => { - const models = model.init(mongoose); - - mongoose.connect('localhost', 'chime'); - - // app.context.db = mongoose; - app.context.db = models; -}; diff --git a/src/lib/authorize.js b/src/lib/authorize.js new file mode 100644 index 0000000..325f045 --- /dev/null +++ b/src/lib/authorize.js @@ -0,0 +1,3 @@ +/** + * Created by ForsakenHarmony on 18/02/17. + */ diff --git a/src/lib/error.js b/src/lib/error.js new file mode 100644 index 0000000..48f742c --- /dev/null +++ b/src/lib/error.js @@ -0,0 +1,3 @@ +/** + * Created by ForsakenHarmony on 20/02/17. + */