mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Transaction Logs - Backend Changes (#14113)
* Transaction Logs - Backend Changes * filter out bank challenge if is not userSupport
This commit is contained in:
@@ -205,11 +205,13 @@
|
||||
"transaction_gift_send": "Gifted to",
|
||||
"transaction_gift_receive": "Received from",
|
||||
"transaction_create_challenge": "Created challenge",
|
||||
"transaction_create_bank_challenge": "Created bank challenge",
|
||||
"transaction_create_guild": "Created guild",
|
||||
"transaction_change_class": "Changed class",
|
||||
"transaction_rebirth": "Used Orb of Rebirth",
|
||||
"transaction_release_pets": "Released pets",
|
||||
"transaction_release_mounts": "Released mounts",
|
||||
"transaction_reroll": "Used Fortify Potion",
|
||||
"transaction_subscription_perks": "From subscription perk"
|
||||
"transaction_subscription_perks": "From subscription perk",
|
||||
"transaction_admin_update_balance": "Admin given"
|
||||
}
|
||||
|
||||
@@ -267,7 +267,11 @@ api.updateHero = {
|
||||
const hero = await User.findById(heroId).exec();
|
||||
if (!hero) throw new NotFound(res.t('userWithIDNotFound', { userId: heroId }));
|
||||
|
||||
if (updateData.balance) hero.balance = updateData.balance;
|
||||
if (updateData.balance) {
|
||||
await hero.updateBalance(updateData.balance - hero.balance, 'admin_update_balance', '', 'Given by Habitica staff');
|
||||
|
||||
hero.balance = updateData.balance;
|
||||
}
|
||||
|
||||
// give them gems if they got an higher level
|
||||
// tier = level in this context
|
||||
@@ -323,7 +327,9 @@ api.updateHero = {
|
||||
}
|
||||
}
|
||||
|
||||
if (updateData.changeApiToken) hero.apiToken = common.uuid();
|
||||
if (updateData.changeApiToken) {
|
||||
hero.apiToken = common.uuid();
|
||||
}
|
||||
|
||||
const savedHero = await hero.save();
|
||||
const heroJSON = savedHero.toJSON();
|
||||
|
||||
@@ -714,8 +714,8 @@ api.transferGems = {
|
||||
throw new NotAuthorized(res.t('badAmountOfGemsToSend'));
|
||||
}
|
||||
|
||||
await receiver.updateBalance(amount, 'gift_receive', sender._id, sender.profile.name);
|
||||
await sender.updateBalance(-amount, 'gift_send', sender._id, receiver.profile.name);
|
||||
await receiver.updateBalance(amount, 'gift_receive', sender._id, sender.auth.local.username);
|
||||
await sender.updateBalance(-amount, 'gift_send', sender._id, receiver.auth.local.username);
|
||||
// @TODO necessary? Also saved when sending the inbox message
|
||||
const promises = [receiver.save(), sender.save()];
|
||||
await Promise.all(promises);
|
||||
|
||||
@@ -64,9 +64,15 @@ api.purchaseHistory = {
|
||||
req.checkParams('memberId', res.t('memberIdRequired')).notEmpty().isUUID();
|
||||
const validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
const transactions = await Transaction
|
||||
let transactions = await Transaction
|
||||
.find({ userId: req.params.memberId })
|
||||
.sort({ createdAt: -1 });
|
||||
.sort({ createdAt: -1 })
|
||||
.exec();
|
||||
|
||||
if (!res.locals.user.hasPermission('userSupport')) {
|
||||
transactions = transactions.filter(t => t.transactionType !== 'create_bank_challenge');
|
||||
}
|
||||
|
||||
res.respond(200, transactions);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -74,14 +74,16 @@ export async function createChallenge (user, req, res) {
|
||||
if (groupBalance >= prizeCost) {
|
||||
// Group pays for all of prize
|
||||
group.balance -= prizeCost;
|
||||
|
||||
await user.updateBalance(0, 'create_bank_challenge', challenge._id, challenge.name);
|
||||
} else if (groupBalance > 0) {
|
||||
// User pays remainder of prize cost after group
|
||||
const remainder = prizeCost - group.balance;
|
||||
group.balance = 0;
|
||||
await user.updateBalance(-remainder, 'create_challenge', challenge._id, challenge.text);
|
||||
await user.updateBalance(-remainder, 'create_challenge', challenge._id, challenge.name);
|
||||
} else {
|
||||
// User pays for all of prize
|
||||
await user.updateBalance(-prizeCost, 'create_challenge', challenge._id, challenge.text);
|
||||
await user.updateBalance(-prizeCost, 'create_challenge', challenge._id, challenge.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ schema.methods.updateHourglasses = async function updateHourglasses (userId,
|
||||
amount,
|
||||
reference,
|
||||
referenceText,
|
||||
|
||||
currentAmount: this.consecutive.trinkets,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ 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 transactionTypes = ['buy_money', 'buy_gold', 'spend', 'gift_send', 'gift_receive', 'debug', 'create_challenge', 'create_bank_challenge', 'create_guild', 'change_class', 'rebirth', 'release_pets', 'release_mounts', 'reroll', 'contribution', 'subscription_perks', 'admin_update_balance'];
|
||||
|
||||
export const schema = new Schema({
|
||||
currency: { $type: String, enum: currencies, required: true },
|
||||
@@ -13,6 +13,7 @@ export const schema = new Schema({
|
||||
reference: { $type: String },
|
||||
referenceText: { $type: String },
|
||||
amount: { $type: Number, required: true },
|
||||
currentAmount: { $type: Number },
|
||||
userId: {
|
||||
$type: String, ref: 'User', required: true, validate: [v => validator.isUUID(v), 'Invalid uuid for Transaction.'],
|
||||
},
|
||||
@@ -23,7 +24,17 @@ export const schema = new Schema({
|
||||
});
|
||||
|
||||
schema.plugin(baseModel, {
|
||||
noSet: ['id', '_id', 'userId', 'currency', 'transactionType', 'reference', 'referenceText', 'amount'], // Nothing can be set from the client
|
||||
noSet: [
|
||||
'id',
|
||||
'_id',
|
||||
'userId',
|
||||
'currency',
|
||||
'transactionType',
|
||||
'reference',
|
||||
'referenceText',
|
||||
'amount',
|
||||
'currentAmount',
|
||||
], // Nothing can be set from the client
|
||||
timestamps: true,
|
||||
_id: false, // using custom _id
|
||||
});
|
||||
|
||||
@@ -559,5 +559,6 @@ schema.methods.updateBalance = async function updateBalance (amount,
|
||||
amount,
|
||||
reference,
|
||||
referenceText,
|
||||
currentAmount: this.balance,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user