From 68d481ad18c4740a04ecc2637512b1e2a8ed6943 Mon Sep 17 00:00:00 2001 From: xangelo Date: Wed, 2 Aug 2023 13:47:49 -0400 Subject: [PATCH] fix: rename shop_items to shop_equipment shop_equipment is more explanatory as the items listed are only equipment types (weapon/armour/spells). --- migrations/20230802173517_shop_equipment.ts | 12 ++++++++++++ seeds/shop_items.ts | 5 ++--- src/client/index.ts | 6 +++--- src/events/stores/server.ts | 2 +- src/server/api.ts | 2 +- src/server/inventory.ts | 4 ++-- src/server/items.ts | 4 ++-- src/server/shopEquipment.ts | 16 ++++++++++++++++ src/server/shopItem.ts | 16 ---------------- src/shared/inventory.ts | 2 +- 10 files changed, 40 insertions(+), 29 deletions(-) create mode 100644 migrations/20230802173517_shop_equipment.ts create mode 100644 src/server/shopEquipment.ts delete mode 100644 src/server/shopItem.ts diff --git a/migrations/20230802173517_shop_equipment.ts b/migrations/20230802173517_shop_equipment.ts new file mode 100644 index 0000000..61db94b --- /dev/null +++ b/migrations/20230802173517_shop_equipment.ts @@ -0,0 +1,12 @@ +import { Knex } from "knex"; + + +export async function up(knex: Knex): Promise { + return knex.schema.renameTable('shop_items', 'shop_equipment'); +} + + +export async function down(knex: Knex): Promise { + return knex.schema.renameTable('shop_equipment', 'shop_items'); +} + diff --git a/seeds/shop_items.ts b/seeds/shop_items.ts index e61773d..3a3833f 100644 --- a/seeds/shop_items.ts +++ b/seeds/shop_items.ts @@ -12,8 +12,8 @@ const base = Airtable.base('appDfPLPajPNog5Iw'); export async function createShopEquipment(): Promise { return new Promise(async (resolve) => { - base('Shop Items').select().eachPage(async (records, next) => { - await db('shop_items').insert(records.map(r => { + base('Shop Equipment').select().eachPage(async (records, next) => { + await db('shop_equipment').insert(records.map(r => { return { id: r.fields.id, name: r.fields.Name, @@ -52,7 +52,6 @@ export async function createShopItems(): Promise { return new Promise(async (resolve) => { base('Items').select().eachPage(async (records, next) => { await db('items').insert(records.map(r => { - console.log(`Creating [${r.fields['Name']}]`); return { id: r.fields['Id'], name: r.fields.Name, diff --git a/src/client/index.ts b/src/client/index.ts index 3abf73d..92bfb13 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -7,7 +7,7 @@ import {Fight, FightTrigger, MonsterForFight, MonsterForList} from '../shared/mo import {FightRound} from '../shared/fight'; import { City, Location, LocationType, Path } from '../shared/map' import { v4 as uuid } from 'uuid'; -import {EquipmentSlot, ShopItem} from '../shared/inventory'; +import {EquipmentSlot, ShopEquipment} from '../shared/inventory'; import { capitalize, each } from 'lodash'; import {EquippedItemDetails} from '../shared/equipped'; import { Skill, Skills } from '../shared/skills'; @@ -597,7 +597,7 @@ function renderInventoryItem(item: EquippedItemDetails , action: (item: Equipped `; } -function renderShopItem(item: ShopItem, action: (item: ShopItem) => string): string { +function renderShopItem(item: ShopEquipment, action: (item: ShopEquipment) => string): string { const player: Player = cache.get('player'); return `
@@ -631,7 +631,7 @@ function renderShopItem(item: ShopItem, action: (item: ShopItem) => string): str } -socket.on('city:stores', (data: ShopItem[]) => { +socket.on('city:stores', (data: ShopEquipment[]) => { const listing: Record = {}; const listingTypes = new Set(); data.forEach(item => { diff --git a/src/events/stores/server.ts b/src/events/stores/server.ts index 076cab4..ef7c6e6 100644 --- a/src/events/stores/server.ts +++ b/src/events/stores/server.ts @@ -1,5 +1,5 @@ import {SocketEvent} from "../../server/socket-event.server"; -import {listShopItems} from '../../server/shopItem'; +import {listShopItems} from '../../server/shopEquipment'; import { logger } from '../../server/lib/logger'; export const stores: SocketEvent = { diff --git a/src/server/api.ts b/src/server/api.ts index 606581a..729f45a 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -15,7 +15,7 @@ import {FightRound} from '../shared/fight'; import {addInventoryItem, deleteInventoryItem, getEquippedItems, getInventory, updateAp} from './inventory'; import { getItemFromPlayer, getPlayersItems } from './items'; import {FightTrigger, MonsterForFight} from '../shared/monsters'; -import {getShopItem } from './shopItem'; +import {getShopItem } from './shopEquipment'; import {EquippedItemDetails} from '../shared/equipped'; import {ArmourEquipmentSlot, EquipmentSlot} from '../shared/inventory'; import { clearTravelPlan, getAllPaths, getAllServices, getCityDetails, getTravelPlan, travel } from './map'; diff --git a/src/server/inventory.ts b/src/server/inventory.ts index 9a62bdf..c5c2b67 100644 --- a/src/server/inventory.ts +++ b/src/server/inventory.ts @@ -1,10 +1,10 @@ -import {InventoryItem, ShopItem} from "../shared/inventory"; +import {InventoryItem, ShopEquipment} from "../shared/inventory"; import { v4 as uuid } from 'uuid'; import { db} from './lib/db'; import {EquippedItemDetails} from "../shared/equipped"; -export async function addInventoryItem(playerId: string, item: ShopItem) { +export async function addInventoryItem(playerId: string, item: ShopEquipment) { const inventoryItem: InventoryItem = { player_id: playerId, item_id: uuid(), diff --git a/src/server/items.ts b/src/server/items.ts index 295b539..8a9aee5 100644 --- a/src/server/items.ts +++ b/src/server/items.ts @@ -2,13 +2,13 @@ import { db } from './lib/db'; import {PlayerItem} from '../shared/items'; export async function getPlayersItems(player_id: string): Promise { - const res = await db.raw(`select pi.*, i.name, i.effect_name, i.icon_name, i.description from player_items pi + const res = await db.raw(`select pi.*, i.* from player_items pi join items i on pi.item_id = i.id where pi.player_id = ? and amount > 0`, [player_id]); return res.rows as PlayerItem[]; } export async function getItemFromPlayer(player_id: string, item_id: number): Promise { - const res = await db.raw(`select pi.*, i.name, i.effect_name, i.icon_name, i.description from player_items pi + const res = await db.raw(`select pi.*, i.* from player_items pi join items i on pi.item_id = i.id where pi.player_id = ? and pi.item_id = ?`, [player_id, item_id]); if(res.rows.length === 1) { return res.rows[0] as PlayerItem; diff --git a/src/server/shopEquipment.ts b/src/server/shopEquipment.ts new file mode 100644 index 0000000..5a215c1 --- /dev/null +++ b/src/server/shopEquipment.ts @@ -0,0 +1,16 @@ +import { db } from './lib/db'; +import {ShopEquipment} from '../shared/inventory'; + +export function listShopItems(where: Partial): Promise { + return db.select('*').from('shop_equipment') + .where(where) + .orderBy('type') + .orderBy('equipment_slot') + .orderByRaw(`requirements->>'level' asc`); +} + +export function getShopItem(id: number): Promise { + return db.select('*').from('shop_equipment').where({ + id + }).first(); +} diff --git a/src/server/shopItem.ts b/src/server/shopItem.ts deleted file mode 100644 index 69c55e6..0000000 --- a/src/server/shopItem.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { db } from './lib/db'; -import {ShopItem} from '../shared/inventory'; - -export function listShopItems(where: Partial): Promise { - return db.select('*').from('shop_items') - .where(where) - .orderBy('type') - .orderBy('equipment_slot') - .orderByRaw(`requirements->>'level' asc`); -} - -export function getShopItem(id: number): Promise { - return db.select('*').from('shop_items').where({ - id - }).first(); -} diff --git a/src/shared/inventory.ts b/src/shared/inventory.ts index c3b58b6..6c18807 100644 --- a/src/shared/inventory.ts +++ b/src/shared/inventory.ts @@ -40,7 +40,7 @@ export type InventoryItem = { // shop items have a numeric id since they're tracked in a separate spreadsheet // and they are also tied to a specific location -export type ShopItem = Omit & { +export type ShopEquipment = Omit & { id: number; location_id: number; }; -- 2.25.1