From 60cb7325f52ff39dae1f42dfdfd424faa7252876 Mon Sep 17 00:00:00 2001 From: MohammadHMazarei Date: Thu, 17 Apr 2025 10:59:07 +0330 Subject: [PATCH] ADD: transaction model --- components/transaction/transactionModel.js | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 components/transaction/transactionModel.js 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