mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
* Log all gem transactions to database * Also store hourglass transactions * Fix tests * Display transaction history in hall of heroes for admins * add tests to new API call * hide transaction settings tab for non admins * fix(lint): remove console * fix(lint): various automatic corrections * fix(transactions): use enum expected pluralizations * fix api unit tests * fix lint * fix failing test * Fix minor inconsistencies * Log all gem transactions to database * Also store hourglass transactions * Fix tests * Display transaction history in hall of heroes for admins * add tests to new API call * hide transaction settings tab for non admins * fix(lint): remove console * fix(lint): various automatic corrections * fix(transactions): use enum expected pluralizations * fix api unit tests * fix lint * Fix minor inconsistencies Co-authored-by: Sabe Jones <sabrecat@gmail.com>
32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
import mongoose from 'mongoose';
|
|
import validator from 'validator';
|
|
import baseModel from '../libs/baseModel';
|
|
|
|
const { Schema } = mongoose;
|
|
|
|
export const currencies = ['gems', 'hourglasses'];
|
|
export const transactionTypes = ['buy_money', 'buy_gold', 'contribution', 'spend', 'gift_send', 'gift_receive', 'debug', 'create_challenge', 'create_guild', 'change_class', 'rebirth', 'release_pets', 'release_mounts', 'reroll', 'contribution', 'subscription_perks'];
|
|
|
|
export const schema = new Schema({
|
|
currency: { $type: String, enum: currencies, required: true },
|
|
transactionType: { $type: String, enum: transactionTypes, required: true },
|
|
reference: { $type: String },
|
|
referenceText: { $type: String },
|
|
amount: { $type: Number, required: true },
|
|
userId: {
|
|
$type: String, ref: 'User', required: true, validate: [v => validator.isUUID(v), 'Invalid uuid for Transaction.'],
|
|
},
|
|
}, {
|
|
strict: true,
|
|
minimize: false, // So empty objects are returned
|
|
typeKey: '$type', // So that we can use fields named `type`
|
|
});
|
|
|
|
schema.plugin(baseModel, {
|
|
noSet: ['id', '_id', 'userId', 'currency', 'transactionType', 'reference', 'referenceText', 'amount'], // Nothing can be set from the client
|
|
timestamps: true,
|
|
_id: false, // using custom _id
|
|
});
|
|
|
|
export const model = mongoose.model('Transaction', schema);
|