-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
1 parent
6b3fad1
commit 683b33f
Showing
8 changed files
with
118 additions
and
7 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
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
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
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,39 @@ | ||
/** | ||
* Module dependencies | ||
*/ | ||
const mongoose = require('mongoose'); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
/** | ||
* Data Model Mongoose | ||
*/ | ||
|
||
const HistoryMongoose = new Schema({ | ||
apiId: String, | ||
result: {}, | ||
status: Boolean, | ||
time: Number, | ||
}, { | ||
timestamps: true, | ||
}); | ||
|
||
/** | ||
* @desc Function to add id (+ _id) to all objects | ||
* @param {Object} scrap | ||
* @return {Object} Scrap | ||
*/ | ||
function addID() { | ||
return this._id.toHexString(); | ||
} | ||
|
||
/** | ||
* Model configuration | ||
*/ | ||
HistoryMongoose.virtual('id').get(addID); | ||
// Ensure virtual fields are serialised. | ||
HistoryMongoose.set('toJSON', { | ||
virtuals: true, | ||
}); | ||
|
||
mongoose.model('History', HistoryMongoose); |
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,18 @@ | ||
/** | ||
* Module dependencies | ||
*/ | ||
const Joi = require('joi'); | ||
|
||
/** | ||
* Data Schema | ||
*/ | ||
const historySchema = Joi.object().keys({ | ||
apiId: Joi.string().trim().required(), | ||
result: Joi.object({}).unknown().optional(), | ||
time: Joi.number().default(0).required(), | ||
status: Joi.boolean().default(false).required(), | ||
}); | ||
|
||
module.exports = { | ||
Scrap: historySchema, | ||
}; |
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
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,13 @@ | ||
/** | ||
* Module dependencies | ||
*/ | ||
const mongoose = require('mongoose'); | ||
|
||
const History = mongoose.model('History'); | ||
|
||
/** | ||
* @desc Function to create a scrap in db | ||
* @param {Object} scrap | ||
* @return {Object} scrap | ||
*/ | ||
exports.create = (history) => new History(history).save(); |
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