mirror of
https://github.com/djdevin/recflare.git
synced 2026-10-25 23:18:51 -07:00
[econ] fix currency name
This commit is contained in:
@@ -59,8 +59,10 @@ export interface RoomPurchasable {
|
||||
* so `ModifiedAt` is its `CreatedAt`.
|
||||
* - A consumable records only `ModifiedAt`, which stands as its `CreatedAt` too.
|
||||
* - A purchase offer is a pack of the room's currency sold for TOKENS, so its
|
||||
* `PurchaseCurrencyId` is null; it has no description or art of its own, and the one
|
||||
* timestamp it keeps serves as both.
|
||||
* `PurchaseCurrencyId` is null, and the one timestamp it keeps serves as both. Its `Name`
|
||||
* is `<amount> <currency name>` ("444 Gems"), NOT the stored `Name`: the client names an
|
||||
* offer by a GUID when it creates one, and that is what the shop showed. It takes the
|
||||
* currency's description and coin art, having none of its own.
|
||||
*/
|
||||
export async function getRoomPurchasables(
|
||||
db: D1Database,
|
||||
@@ -75,6 +77,7 @@ export async function getRoomPurchasables(
|
||||
db,
|
||||
currencies.map((currency) => currency.CurrencyId)
|
||||
)
|
||||
const currencyById = new Map(currencies.map((currency) => [currency.CurrencyId, currency]))
|
||||
|
||||
return [
|
||||
...keys.map((key): RoomPurchasable => ({
|
||||
@@ -101,19 +104,20 @@ export async function getRoomPurchasables(
|
||||
CreatedAt: consumable.ModifiedAt,
|
||||
ModifiedAt: consumable.ModifiedAt,
|
||||
})),
|
||||
...offers.flatMap((shop) =>
|
||||
shop.PurchaseOffers.map((offer): RoomPurchasable => ({
|
||||
...offers.flatMap((shop) => {
|
||||
const currency = currencyById.get(shop.CurrencyId)
|
||||
return shop.PurchaseOffers.map((offer): RoomPurchasable => ({
|
||||
ItemType: ROOM_PURCHASABLE_TYPE.roomCurrencyItem,
|
||||
ItemId: offer.CurrencyPurchaseOfferId,
|
||||
Name: offer.Name,
|
||||
Description: '',
|
||||
ImageName: null,
|
||||
Name: `${offer.CurrencyAmount} ${currency?.Name ?? ''}`.trim(),
|
||||
Description: currency?.Description ?? '',
|
||||
ImageName: currency?.ImageName ?? null,
|
||||
RoomId: roomId,
|
||||
Price: offer.Price,
|
||||
PurchaseCurrencyId: null,
|
||||
CreatedAt: offer.ModifiedAt,
|
||||
ModifiedAt: offer.ModifiedAt,
|
||||
}))
|
||||
),
|
||||
}),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -2940,13 +2940,14 @@ describe('econ endpoints', () => {
|
||||
const currency = await createRoomCurrency(env.DB, {
|
||||
RoomId: 93,
|
||||
Name: 'Gems',
|
||||
Description: '',
|
||||
Description: 'Shiny',
|
||||
Limit: 100,
|
||||
Shape: 0,
|
||||
Color: 0,
|
||||
})
|
||||
// The client names an offer by a GUID — not a label anyone should see.
|
||||
const offer = await createPurchaseOffer(env.DB, currency.CurrencyId, {
|
||||
Name: '100 gems',
|
||||
Name: '5a1c3e4f-0000-4000-8000-000000000093',
|
||||
CurrencyAmount: 100,
|
||||
Price: 400,
|
||||
Order: 0,
|
||||
@@ -2982,8 +2983,9 @@ describe('econ endpoints', () => {
|
||||
{
|
||||
ItemType: 3,
|
||||
ItemId: offer.CurrencyPurchaseOfferId,
|
||||
Name: '100 gems',
|
||||
Description: '',
|
||||
// So a pack is labelled by what it is, and wears the currency's description.
|
||||
Name: '100 Gems',
|
||||
Description: 'Shiny',
|
||||
ImageName: null,
|
||||
RoomId: 93,
|
||||
Price: 400,
|
||||
|
||||
Reference in New Issue
Block a user