forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarbonCreditModel.js
More file actions
20 lines (20 loc) 路 1.22 KB
/
Copy pathcarbonCreditModel.js
File metadata and controls
20 lines (20 loc) 路 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const mongoose = require('mongoose');
const carbonCreditSchema = new mongoose.Schema({
creditId: {type: String, required: true, unique: true, index: true},
userId: {type: String, required: true},
organization: {type: String, default: null},
creditType: {type: String, enum: ['recycling','renewable_energy','carbon_offset','green_infrastructure','waste_reduction'], required: true},
amount: {type: Number, required: true},
unit: {type: String, default: 'kgCO2e'},
verificationStatus: {type: String, enum: ['pending','verified','rejected'], default: 'pending'},
verifiedBy: {type: String, default: null},
evidence: {type: String, default: null},
esgReport: {type: String, default: null},
status: {type: String, enum: ['active','traded','retired'], default: 'active'},
tradedTo: {type: String, default: null},
retiredAt: {type: Date, default: null},
createdAt: {type: Date, default: Date.now},
verifiedAt: {type: Date, default: null}
});
carbonCreditSchema.statics.getTotalCredits = function(userId) { return this.aggregate([{$match: {userId, status: 'active', verificationStatus: 'verified'}}, {$group: {_id: null, total: {$sum: '$amount'}}}]); };
module.exports = mongoose.model('CarbonCredit', carbonCreditSchema);