Skip to content

Commit

Permalink
Create Transaction.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Nov 25, 2024
1 parent 7548fb5 commit e1964c8
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/models/Transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const mongoose = require('mongoose');

const transactionSchema = new mongoose.Schema({
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User ', // Reference to User model
required: true,
},
destinationId: {
type: String, // Could be a Stellar account ID or similar
required: true,
},
amount: {
type: Number,
required: true,
},
status: {
type: String,
enum: ['pending', 'completed', 'failed', 'canceled'],
default: 'pending',
},
createdAt: {
type: Date,
default: Date.now,
},
transactionHash: {
type: String, // Store transaction hash from blockchain
},
});

// Method to cancel a transaction
transactionSchema.methods.cancel = async function() {
this.status = 'canceled';
await this.save();
};

const Transaction = mongoose.model('Transaction', transactionSchema);

module.exports = Transaction;

0 comments on commit e1964c8

Please sign in to comment.