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_send": "Gifted to",
|
||||||
"transaction_gift_receive": "Received from",
|
"transaction_gift_receive": "Received from",
|
||||||
"transaction_create_challenge": "Created challenge",
|
"transaction_create_challenge": "Created challenge",
|
||||||
|
"transaction_create_bank_challenge": "Created bank challenge",
|
||||||
"transaction_create_guild": "Created guild",
|
"transaction_create_guild": "Created guild",
|
||||||
"transaction_change_class": "Changed class",
|
"transaction_change_class": "Changed class",
|
||||||
"transaction_rebirth": "Used Orb of Rebirth",
|
"transaction_rebirth": "Used Orb of Rebirth",
|
||||||
"transaction_release_pets": "Released pets",
|
"transaction_release_pets": "Released pets",
|
||||||
"transaction_release_mounts": "Released mounts",
|
"transaction_release_mounts": "Released mounts",
|
||||||
"transaction_reroll": "Used Fortify Potion",
|
"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();
|
const hero = await User.findById(heroId).exec();
|
||||||
if (!hero) throw new NotFound(res.t('userWithIDNotFound', { userId: heroId }));
|
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
|
// give them gems if they got an higher level
|
||||||
// tier = level in this context
|
// 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 savedHero = await hero.save();
|
||||||
const heroJSON = savedHero.toJSON();
|
const heroJSON = savedHero.toJSON();
|
||||||
|
|||||||
@@ -714,8 +714,8 @@ api.transferGems = {
|
|||||||
throw new NotAuthorized(res.t('badAmountOfGemsToSend'));
|
throw new NotAuthorized(res.t('badAmountOfGemsToSend'));
|
||||||
}
|
}
|
||||||
|
|
||||||
await receiver.updateBalance(amount, 'gift_receive', sender._id, sender.profile.name);
|
await receiver.updateBalance(amount, 'gift_receive', sender._id, sender.auth.local.username);
|
||||||
await sender.updateBalance(-amount, 'gift_send', sender._id, receiver.profile.name);
|
await sender.updateBalance(-amount, 'gift_send', sender._id, receiver.auth.local.username);
|
||||||
// @TODO necessary? Also saved when sending the inbox message
|
// @TODO necessary? Also saved when sending the inbox message
|
||||||
const promises = [receiver.save(), sender.save()];
|
const promises = [receiver.save(), sender.save()];
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|||||||
@@ -64,9 +64,15 @@ api.purchaseHistory = {
|
|||||||
req.checkParams('memberId', res.t('memberIdRequired')).notEmpty().isUUID();
|
req.checkParams('memberId', res.t('memberIdRequired')).notEmpty().isUUID();
|
||||||
const validationErrors = req.validationErrors();
|
const validationErrors = req.validationErrors();
|
||||||
if (validationErrors) throw validationErrors;
|
if (validationErrors) throw validationErrors;
|
||||||
const transactions = await Transaction
|
let transactions = await Transaction
|
||||||
.find({ userId: req.params.memberId })
|
.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);
|
res.respond(200, transactions);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -74,14 +74,16 @@ export async function createChallenge (user, req, res) {
|
|||||||
if (groupBalance >= prizeCost) {
|
if (groupBalance >= prizeCost) {
|
||||||
// Group pays for all of prize
|
// Group pays for all of prize
|
||||||
group.balance -= prizeCost;
|
group.balance -= prizeCost;
|
||||||
|
|
||||||
|
await user.updateBalance(0, 'create_bank_challenge', challenge._id, challenge.name);
|
||||||
} else if (groupBalance > 0) {
|
} else if (groupBalance > 0) {
|
||||||
// User pays remainder of prize cost after group
|
// User pays remainder of prize cost after group
|
||||||
const remainder = prizeCost - group.balance;
|
const remainder = prizeCost - group.balance;
|
||||||
group.balance = 0;
|
group.balance = 0;
|
||||||
await user.updateBalance(-remainder, 'create_challenge', challenge._id, challenge.text);
|
await user.updateBalance(-remainder, 'create_challenge', challenge._id, challenge.name);
|
||||||
} else {
|
} else {
|
||||||
// User pays for all of prize
|
// 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,
|
amount,
|
||||||
reference,
|
reference,
|
||||||
referenceText,
|
referenceText,
|
||||||
|
|
||||||
|
currentAmount: this.consecutive.trinkets,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import baseModel from '../libs/baseModel';
|
|||||||
const { Schema } = mongoose;
|
const { Schema } = mongoose;
|
||||||
|
|
||||||
export const currencies = ['gems', 'hourglasses'];
|
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({
|
export const schema = new Schema({
|
||||||
currency: { $type: String, enum: currencies, required: true },
|
currency: { $type: String, enum: currencies, required: true },
|
||||||
@@ -13,6 +13,7 @@ export const schema = new Schema({
|
|||||||
reference: { $type: String },
|
reference: { $type: String },
|
||||||
referenceText: { $type: String },
|
referenceText: { $type: String },
|
||||||
amount: { $type: Number, required: true },
|
amount: { $type: Number, required: true },
|
||||||
|
currentAmount: { $type: Number },
|
||||||
userId: {
|
userId: {
|
||||||
$type: String, ref: 'User', required: true, validate: [v => validator.isUUID(v), 'Invalid uuid for Transaction.'],
|
$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, {
|
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,
|
timestamps: true,
|
||||||
_id: false, // using custom _id
|
_id: false, // using custom _id
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -559,5 +559,6 @@ schema.methods.updateBalance = async function updateBalance (amount,
|
|||||||
amount,
|
amount,
|
||||||
reference,
|
reference,
|
||||||
referenceText,
|
referenceText,
|
||||||
|
currentAmount: this.balance,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user