reformat with prettier,add react frontend submodule

This commit is contained in:
2018-06-03 12:47:23 +03:00
parent 38688491f9
commit bbee6b2b95
16 changed files with 255 additions and 58 deletions

View File

@@ -15,7 +15,7 @@ const TodoSchema = Schema({
completed: { type: Boolean, default: false },
});
TodoSchema.pre('save', async function () {
TodoSchema.pre('save', async function() {
if (this.isNew) {
const user = await this.model('User').findById(this.user);
user.todos.push(this._id);
@@ -27,7 +27,7 @@ TodoSchema.pre('save', async function () {
}
});
TodoSchema.pre('remove', async function () {
TodoSchema.pre('remove', async function() {
const user = await this.model('User').findById(this.user);
user.todos.splice(user.todos.indexOf(this._id), 1);
await user.save();
@@ -37,7 +37,7 @@ TodoSchema.pre('remove', async function () {
await list.save();
});
TodoSchema.methods.toJson = function () {
TodoSchema.methods.toJson = function() {
return {
id: this._id.toString(),
text: this.text,

View File

@@ -14,7 +14,7 @@ const TodoListSchema = Schema({
user: { type: Schema.Types.ObjectId, ref: 'User', required: true },
});
TodoListSchema.pre('save', async function () {
TodoListSchema.pre('save', async function() {
if (this.isNew) {
const user = await this.model('User').findById(this.user);
user.lists.push(this._id);
@@ -22,7 +22,7 @@ TodoListSchema.pre('save', async function () {
}
});
TodoListSchema.pre('remove', async function () {
TodoListSchema.pre('remove', async function() {
const user = await this.model('User').findById(this.user);
user.lists.splice(user.lists.indexOf(this._id), 1);
@@ -41,8 +41,10 @@ TodoListSchema.pre('remove', async function () {
.exec();
});
TodoListSchema.methods.toJson = function () {
const todos = this.populated('todos') ? this.todos.map(todo => todo.toJson()) : this.todos;
TodoListSchema.methods.toJson = function() {
const todos = this.populated('todos')
? this.todos.map(todo => todo.toJson())
: this.todos;
return {
id: this._id.toString(),
user: this.user.toString(),

View File

@@ -24,7 +24,7 @@ const UserSchema = Schema({
UserSchema.plugin(passportLocalMongoose);
UserSchema.plugin(uniqueValidator);
UserSchema.pre('remove', async function () {
UserSchema.pre('remove', async function() {
await this.model('TodoList')
.find({ user: this._id })
.remove()
@@ -35,18 +35,20 @@ UserSchema.pre('remove', async function () {
.exec();
});
UserSchema.methods.generateJwt = function () {
return jwt.sign({ id: this._id, username: this.username }, secret, { expiresIn: '120d' });
UserSchema.methods.generateJwt = function() {
return jwt.sign({ id: this._id, username: this.username }, secret, {
expiresIn: '120d',
});
};
UserSchema.methods.toJson = function () {
UserSchema.methods.toJson = function() {
return {
id: this._id,
username: this.username,
};
};
UserSchema.methods.toAuthJson = function () {
UserSchema.methods.toAuthJson = function() {
return {
id: this._id,
username: this.username,