-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ac2be40
Showing
6 changed files
with
2,018 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
// Define Schemes | ||
const operationSchema = new mongoose.Schema({ | ||
keys: { type: String, required: true }, | ||
line: { type: Number, required: true }, | ||
column: { type: Number, required: true } | ||
}); | ||
const snapshotSchema = new mongoose.Schema({ | ||
index: { type: Number, required: true }, | ||
timestamp: { type: Date, required: true }, | ||
user_id: { type: Number, required: true }, | ||
history_id: { type: Number, required: true }, | ||
operation: operationSchema | ||
}); | ||
const historySchema = new mongoose.Schema({ | ||
children: [snapshotSchema] | ||
}); | ||
|
||
/* | ||
this == model | ||
return Promise | ||
*/ | ||
|
||
// Create new history document | ||
historySchema.statics.create = function(data) { | ||
const history = new this(data); | ||
return history.save(); | ||
}; | ||
|
||
// Find one history by history id | ||
historySchema.statics.findOneById = function(id) { | ||
return this.findOne({id}); | ||
} | ||
|
||
// Update history by id | ||
historySchema.statics.updateById = function(id, data) { | ||
const history = this.findOneAndUpdate({id}, data, { new: true }); | ||
return history; | ||
} | ||
|
||
// Delete history by id | ||
historySchema.statics.deleteById = function(id) { | ||
return this.remove({id}); | ||
} | ||
|
||
// Create Model & Export | ||
module.exports = mongoose.model('History', historySchema); |
Oops, something went wrong.