diff --git a/client/play/geoword/admin/invoice.html b/client/play/geoword/admin/invoice.html index 9eeb84812..afe0512ed 100644 --- a/client/play/geoword/admin/invoice.html +++ b/client/play/geoword/admin/invoice.html @@ -25,6 +25,7 @@
Packet id (or set id):
Username:
User id:
+Manually recorded by:
Amount: $
diff --git a/client/play/geoword/admin/invoice.js b/client/play/geoword/admin/invoice.js index 5a75d1206..03e2d3b6b 100644 --- a/client/play/geoword/admin/invoice.js +++ b/client/play/geoword/admin/invoice.js @@ -6,11 +6,15 @@ fetch('/api/geoword/admin/invoice?' + new URLSearchParams({ _id, packetName })) .then(response => response.json()) .then(data => { const { amount, payment } = data; - const { packet, set, user_id: userId, username, createdAt } = payment; + const { packet, set, user_id: userId, username, createdAt, recordedBy, recordedByUsername } = payment; document.getElementById('date').textContent = new Date(createdAt).toLocaleString(); document.getElementById('packet-name').textContent = packet?.name ?? `All packets in ${set.name}`; document.getElementById('packet-id').textContent = packet?._id ?? set._id; document.getElementById('user-id').textContent = userId; document.getElementById('username').textContent = username; + if (recordedBy) { + document.getElementById('recorded-by').textContent = `${recordedByUsername} (${recordedBy})`; + document.getElementById('recorded-by-row').classList.remove('d-none'); + } document.getElementById('amount').textContent = (amount / 100).toFixed(2); }); diff --git a/database/geoword/admin/get-invoice.js b/database/geoword/admin/get-invoice.js index 55ea2170c..0d5398426 100644 --- a/database/geoword/admin/get-invoice.js +++ b/database/geoword/admin/get-invoice.js @@ -6,6 +6,9 @@ export default async function getInvoice ({ _id }) { if (payment) { payment.username = await getUsername(payment.user_id); + if (payment.recordedBy) { + payment.recordedByUsername = await getUsername(payment.recordedBy); + } } return payment; diff --git a/database/geoword/record-payment.js b/database/geoword/record-payment.js index 3d4922bd0..88c768310 100644 --- a/database/geoword/record-payment.js +++ b/database/geoword/record-payment.js @@ -5,14 +5,14 @@ import getSetPayment from './get-set-payment.js'; /** * @param {String} packetName * @param {ObjectId} userId - * @param {{ manual?: boolean, amountInCents?: number }} [options] + * @param {{ manual?: boolean, amountInCents?: number, recordedBy?: ObjectId }} [options] */ -async function recordPayment (packetName, userId, { manual = false, amountInCents = null } = {}) { +async function recordPayment (packetName, userId, { manual = false, amountInCents = null, recordedBy = null } = {}) { const setPayment = await getSetPayment(packetName); if (setPayment) { return await payments.replaceOne( { user_id: userId, 'set._id': setPayment.set._id, packet: { $exists: false } }, - { user_id: userId, set: setPayment.set, createdAt: new Date(), manual, amountInCents }, + { user_id: userId, set: setPayment.set, createdAt: new Date(), manual, amountInCents, recordedBy }, { upsert: true } ); } @@ -20,7 +20,7 @@ async function recordPayment (packetName, userId, { manual = false, amountInCent const packet = await packets.findOne({ name: packetName }); return await payments.replaceOne( { user_id: userId, 'packet.name': packetName }, - { user_id: userId, packet: { _id: packet._id, name: packetName }, set: packet.set, createdAt: new Date(), manual, amountInCents }, + { user_id: userId, packet: { _id: packet._id, name: packetName }, set: packet.set, createdAt: new Date(), manual, amountInCents, recordedBy }, { upsert: true } ); } diff --git a/routes/api/geoword/admin/record-payment.js b/routes/api/geoword/admin/record-payment.js index 206479c8e..ada74dd61 100644 --- a/routes/api/geoword/admin/record-payment.js +++ b/routes/api/geoword/admin/record-payment.js @@ -13,7 +13,7 @@ router.put('/', async (req, res) => { if (!userId) { return res.status(400).send('User not found'); } const amountInCents = await getCost(packetName); - const result = await recordPayment(packetName, userId, { manual: true, amountInCents }); + const result = await recordPayment(packetName, userId, { manual: true, amountInCents, recordedBy: res.locals.userId }); console.log(userId, result);