add equipment update

This commit is contained in:
Devin Zuczek
2026-07-21 01:52:37 -04:00
parent 086441f6f5
commit cfde2cebf4
5 changed files with 187 additions and 29 deletions
+44 -3
View File
@@ -28,7 +28,7 @@ import {
getConsumables,
grantConsumable,
} from './consumables-db'
import { getEquipment, grantEquipment } from './equipment-db'
import { getEquipment, grantEquipment, setEquipmentFavorited } from './equipment-db'
import { getInventory, grantItem } from './inventory-db'
import {
AUTHED,
@@ -42,6 +42,7 @@ import {
ConsumeEnvelope,
ConsumeGiftRequest,
CustomAvatarItemsResponse,
EquipmentUpdateRequest,
ErrorResponse,
form,
json,
@@ -280,11 +281,13 @@ function toAvatarItem(giftDrop: StoreGiftDrop): AvatarItem {
/** Build the owned equipment DTO granted into the buyer's inventory from a gift-drop. */
function toEquipment(giftDrop: StoreGiftDrop): Equipment {
return {
EquipmentModificationGuid: giftDrop.EquipmentModificationGuid,
EquipmentPrefabName: giftDrop.EquipmentPrefabName,
ModificationGuid: giftDrop.EquipmentModificationGuid,
PrefabName: giftDrop.EquipmentPrefabName,
FriendlyName: giftDrop.FriendlyName,
Tooltip: giftDrop.Tooltip,
Rarity: giftDrop.Rarity,
PlatformMask: -1,
Favorited: false,
}
}
@@ -714,6 +717,44 @@ const app = new Hono<App>({ strict: false })
}
)
// Favourite/un-favourite owned equipment. [Authorize]. The client PUTs the entries
// it wants changed (one request can carry several) and reads nothing back. Only
// `Favorited` is written — the rest of each entry is the client echoing what it was
// served, and a guid the caller doesn't own matches no row and is dropped.
.put(
'/api/equipment/v1/update',
describeRoute({
tags: ['Equipment'],
summary: 'Update owned equipment',
description:
'Applies the posted `Favorited` flags to the callers owned equipment, matched by ' +
'`ModificationGuid`. Everything else in each entry is ignored, and a guid the caller ' +
'doesnt own is silently skipped. Empty body on success.',
security: AUTHED,
requestBody: jsonBody(EquipmentUpdateRequest, 'The entries to update'),
responses: {
200: { description: 'Applied (empty body)' },
400: { description: 'Body isnt a JSON array (empty body)' },
401: UNAUTHORIZED_RESPONSE,
},
}),
async (c) => {
const id = await authedId(c)
if (id === null) return unauthorized(c)
const body = (await c.req.json().catch(() => null)) as unknown
if (!Array.isArray(body)) return c.body(null, 400)
const updates = body
.filter((e): e is Record<string, unknown> => typeof e === 'object' && e !== null)
.filter((e) => typeof e.ModificationGuid === 'string' && e.ModificationGuid !== '')
.map((e) => ({
ModificationGuid: e.ModificationGuid as string,
Favorited: e.Favorited === true,
}))
await setEquipmentFavorited(c.env.DB, id, updates)
return c.body(null, 200)
}
)
// Room consumables/currencies for a given room. Stubbed as empty lists so the
// client doesn't 404.
.get(