Skip to content

Commit

Permalink
Initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
mixxeo committed Feb 21, 2022
0 parents commit ac2be40
Show file tree
Hide file tree
Showing 6 changed files with 2,018 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.env
48 changes: 48 additions & 0 deletions server/model.js
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);
Loading

0 comments on commit ac2be40

Please sign in to comment.