mirror of
https://github.com/wassname/talk.git
synced 2026-08-13 12:40:11 +08:00
* Adds identifier and hide _id.
* Gets only the user for subdocuments and not the whole document.
This commit is contained in:
+11
-2
@@ -1,14 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
const mongoose = require('../mongoose');
|
||||
const uuid = require('uuid');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const assetSchema = new Schema({
|
||||
const AssetSchema = new Schema({
|
||||
id: {
|
||||
type: String,
|
||||
default: uuid.v4,
|
||||
unique: true
|
||||
},
|
||||
title: String,
|
||||
created_at: { type: Date, default: Date.now },
|
||||
updated_at: { type: Date, default: Date.now }
|
||||
},{
|
||||
_id: false
|
||||
});
|
||||
|
||||
const Asset = mongoose.model('Asset', assetSchema);
|
||||
const Asset = mongoose.model('Asset', AssetSchema);
|
||||
|
||||
module.exports = Asset;
|
||||
module.exports.Schema = AssetSchema;
|
||||
|
||||
+35
-8
@@ -1,21 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
const mongoose = require('../mongoose');
|
||||
const uuid = require('uuid');
|
||||
const Schema = mongoose.Schema;
|
||||
const User = require('user');
|
||||
const Asset = require('asset');
|
||||
const UserSchema = require('./user').Schema;
|
||||
const AssetSchema = require('./asset').Schema;
|
||||
|
||||
const commentSchema = new Schema({
|
||||
const CommentSchema = new Schema({
|
||||
id: {
|
||||
type: String,
|
||||
default: uuid.v4,
|
||||
unique: true
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
required: [true, 'The content is required.'],
|
||||
minlenght: 50
|
||||
},
|
||||
asset: Asset,
|
||||
author: User,
|
||||
asset: AssetSchema,
|
||||
author: UserSchema,
|
||||
actions: {
|
||||
flags: [User],
|
||||
likes: [User]
|
||||
flags: [UserSchema],
|
||||
likes: [UserSchema]
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
@@ -25,8 +31,29 @@ const commentSchema = new Schema({
|
||||
parent: Comment,
|
||||
created_at: { type: Date, default: Date.now },
|
||||
updated_at: { type: Date, default: Date.now }
|
||||
},{
|
||||
_id: false
|
||||
});
|
||||
|
||||
const Comment = mongoose.model('Comment', commentSchema);
|
||||
/**
|
||||
* Finds a user by the id.
|
||||
* @param {String} id identifier of the user (uuid)
|
||||
*/
|
||||
CommentSchema.methods.findById = function(id, done) {
|
||||
Comment.findOne({
|
||||
id : id
|
||||
}, (err, comment) => {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
if (!comment) {
|
||||
return done(null, false);
|
||||
}
|
||||
return done(null, comment);
|
||||
});
|
||||
};
|
||||
|
||||
const Comment = mongoose.model('Comment', CommentSchema);
|
||||
|
||||
module.exports = Comment;
|
||||
|
||||
+11
-2
@@ -1,14 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
const mongoose = require('../mongoose');
|
||||
const uuid = require('uuid');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const userSchema = new Schema({
|
||||
const UserSchema = new Schema({
|
||||
id: {
|
||||
type: String,
|
||||
default: uuid.v4,
|
||||
unique: true
|
||||
},
|
||||
name: String,
|
||||
created_at: { type: Date, default: Date.now },
|
||||
updated_at: { type: Date, default: Date.now }
|
||||
},{
|
||||
_id: false
|
||||
});
|
||||
|
||||
const User = mongoose.model('User', userSchema);
|
||||
const User = mongoose.model('User', UserSchema);
|
||||
|
||||
module.exports = User;
|
||||
module.exports.Schema = UserSchema;
|
||||
|
||||
Reference in New Issue
Block a user