fix: rename shop_items to shop_equipment
authorxangelo <me@xangelo.ca>
Wed, 2 Aug 2023 17:47:49 +0000 (13:47 -0400)
committerxangelo <me@xangelo.ca>
Wed, 2 Aug 2023 17:47:49 +0000 (13:47 -0400)
shop_equipment is more explanatory as the items listed are only
equipment types (weapon/armour/spells).

migrations/20230802173517_shop_equipment.ts [new file with mode: 0644]
seeds/shop_items.ts
src/client/index.ts
src/events/stores/server.ts
src/server/api.ts
src/server/inventory.ts
src/server/items.ts
src/server/shopEquipment.ts [new file with mode: 0644]
src/server/shopItem.ts [deleted file]
src/shared/inventory.ts

diff --git a/migrations/20230802173517_shop_equipment.ts b/migrations/20230802173517_shop_equipment.ts
new file mode 100644 (file)
index 0000000..61db94b
--- /dev/null
@@ -0,0 +1,12 @@
+import { Knex } from "knex";
+
+
+export async function up(knex: Knex): Promise<void> {
+  return knex.schema.renameTable('shop_items', 'shop_equipment');
+}
+
+
+export async function down(knex: Knex): Promise<void> {
+  return knex.schema.renameTable('shop_equipment', 'shop_items');
+}
+
index e61773d612e7b659ce9d94561de93ebd336fd1bd..3a3833ffc9d4818001aa4fef8a944b39802a63e1 100644 (file)
@@ -12,8 +12,8 @@ const base = Airtable.base('appDfPLPajPNog5Iw');
 
 export async function createShopEquipment(): Promise<void> {
   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<void> {
   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,
index 3abf73d7f8cfb2f39b2d2517eab649f86df36782..92bfb138c1ee60ed394d1a7645770fae356e8121 100644 (file)
@@ -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
     </div>`;
 }
 
-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 `<div class="store-list">
     <div>
@@ -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<string, string> = {};
   const listingTypes = new Set<string>();
   data.forEach(item => {
index 076cab4e93b6f74b47e3b3c8e03fdf34ada30873..ef7c6e6c537071e30e0b2a4d9d070446452e0a76 100644 (file)
@@ -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 = {
index 606581a964f3df080e755a4eb3825f5b313773ac..729f45a90e2663a7b189b24c09b82d1a4903a068 100644 (file)
@@ -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';
index 9a62bdfed3fe533b247f00c5e42cd3b47437d942..c5c2b6717e4cbec2471512b6ca3262979559e891 100644 (file)
@@ -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(),
index 295b5394e9506aab88ff9824ee9c2d5f72d3014d..8a9aee5a671dcaea3270b3747bd77eee57d46fb6 100644 (file)
@@ -2,13 +2,13 @@ import { db } from './lib/db';
 import {PlayerItem} from '../shared/items';
 
 export async function getPlayersItems(player_id: string): Promise<PlayerItem[]> {
-  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<PlayerItem | undefined> {
-  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 (file)
index 0000000..5a215c1
--- /dev/null
@@ -0,0 +1,16 @@
+import { db } from './lib/db';
+import {ShopEquipment} from '../shared/inventory';
+
+export function listShopItems(where: Partial<ShopEquipment>): Promise<ShopEquipment[]> {
+  return db.select('*').from<ShopEquipment>('shop_equipment')
+        .where(where)
+        .orderBy('type')
+        .orderBy('equipment_slot')
+        .orderByRaw(`requirements->>'level' asc`);
+}
+
+export function getShopItem(id: number): Promise<ShopEquipment> {
+  return db.select('*').from<ShopEquipment>('shop_equipment').where({
+    id
+  }).first();
+}
diff --git a/src/server/shopItem.ts b/src/server/shopItem.ts
deleted file mode 100644 (file)
index 69c55e6..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-import { db } from './lib/db';
-import {ShopItem} from '../shared/inventory';
-
-export function listShopItems(where: Partial<ShopItem>): Promise<ShopItem[]> {
-  return db.select('*').from<ShopItem>('shop_items')
-        .where(where)
-        .orderBy('type')
-        .orderBy('equipment_slot')
-        .orderByRaw(`requirements->>'level' asc`);
-}
-
-export function getShopItem(id: number): Promise<ShopItem> {
-  return db.select('*').from<ShopItem>('shop_items').where({
-    id
-  }).first();
-}
index c3b58b6faba4fc9c783d74804ba03c9d82a4a774..6c18807635b2bc26100d18b548d5358caa7bf2f9 100644 (file)
@@ -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<InventoryItem, 'id' | 'player_id'> & {
+export type ShopEquipment = Omit<InventoryItem, 'id' | 'player_id'> & {
   id: number;
   location_id: number;
 };