diff --git a/components/transaction/transactionModel.js b/components/transaction/transactionModel.js new file mode 100644 index 0000000..6e4e6b0 --- /dev/null +++ b/components/transaction/transactionModel.js @@ -0,0 +1,46 @@ +const mongoose = require('mongoose') +const ObjectID = mongoose.Schema.Types.ObjectId + +const transactionSchema = new mongoose.Schema( + { + type: { + type: String, + enum: ['withdraw', 'deposit'], + required: true, + }, + status: { + type: String, + enum: ['failed', 'pending', 'finished'], + required: true, + }, + source: { + type: String, + enum: ['normal'], + }, + value: { + type: Number, + required: true, + }, + date: { + type: Date, + default: Date.now(), + }, + description: String, + userId: { + type: ObjectID, + ref: 'User', + }, + belongingId: { + type: ObjectID, + ref: 'Belonging', + }, + }, + { + toJSON: { virtuals: true }, + toObject: { virtuals: true }, + timestamps: true, + } +) + +const Transaction = mongoose.model('Transaction', transactionSchema) +module.exports = Transaction