Skip to content

Commit

Permalink
Set minBuyout to numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
sandervspl committed Jul 19, 2024
1 parent 9cbcab4 commit a4f38e1
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 30 deletions.
2 changes: 1 addition & 1 deletion apps/server/src/api/item/auction-house.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function updateAuctionHouseData(
numAuctions: item.numAuctions,
marketValue: item.marketValue,
historical: item.historical,
minBuyout: item.minBuyout,
minBuyout: item.minBuyout.toString(),
quantity: item.quantity,
})),
);
Expand Down
9 changes: 7 additions & 2 deletions apps/server/src/api/item/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ async function queryItem(id: number, auctionHouseId: number, version: i.GameVers
.fullJoin(itemsMetadata, eq(items.itemId, itemsMetadata.id))
.orderBy(desc(items.timestamp))
.limit(1);
const itemFromDb = queryResult?.[0]?.items;
const itemFromDb = queryResult?.[0]?.items
? {
...queryResult[0].items,
minBuyout: Number(queryResult[0].items.minBuyout),
}
: null;

const someTimeAgo = dayjs().subtract(3, 'hours');
const isTooOld = dayjs(itemFromDb?.timestamp) < someTimeAgo;
Expand Down Expand Up @@ -162,7 +167,7 @@ async function queryItem(id: number, auctionHouseId: number, version: i.GameVers
numAuctions: item.numAuctions,
marketValue: item.marketValue,
historicalValue: item.historical,
minBuyout: item.minBuyout,
minBuyout: Number(item.minBuyout),
quantity: item.quantity,
},
previous: null,
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/db/drizzle/0002_funny_scorpion.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "items" ALTER COLUMN "min_buyout" SET DATA TYPE numeric;
26 changes: 13 additions & 13 deletions apps/server/src/db/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"id": "fc3ac108-d576-44a9-a1bb-95c61c4cb449",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "5",
"dialect": "pg",
"version": "6",
"dialect": "postgresql",
"tables": {
"items": {
"public.items": {
"name": "items",
"schema": "",
"columns": {
Expand Down Expand Up @@ -85,15 +83,15 @@
"uniqueConstraints": {
"items_item_id_auction_house_id_unq": {
"name": "items_item_id_auction_house_id_unq",
"nullsNotDistinct": false,
"columns": [
"item_id",
"auction_house_id"
]
],
"nullsNotDistinct": false
}
}
},
"items_metadata": {
"public.items_metadata": {
"name": "items_metadata",
"schema": "",
"columns": {
Expand Down Expand Up @@ -175,19 +173,21 @@
"uniqueConstraints": {
"items_metadata_id_unq": {
"name": "items_metadata_id_unq",
"nullsNotDistinct": false,
"columns": [
"id"
]
],
"nullsNotDistinct": false
}
}
}
},
"enums": {},
"schemas": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
"tables": {},
"columns": {}
},
"id": "fc3ac108-d576-44a9-a1bb-95c61c4cb449",
"prevId": "00000000-0000-0000-0000-000000000000"
}
22 changes: 11 additions & 11 deletions apps/server/src/db/drizzle/meta/0001_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"id": "03ab9ad6-742c-452d-94b6-9857493b1baf",
"prevId": "fc3ac108-d576-44a9-a1bb-95c61c4cb449",
"version": "5",
"dialect": "pg",
"version": "6",
"dialect": "postgresql",
"tables": {
"items": {
"public.items": {
"name": "items",
"schema": "",
"columns": {
Expand Down Expand Up @@ -85,7 +83,7 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"items_metadata": {
"public.items_metadata": {
"name": "items_metadata",
"schema": "",
"columns": {
Expand Down Expand Up @@ -167,19 +165,21 @@
"uniqueConstraints": {
"items_metadata_id_unq": {
"name": "items_metadata_id_unq",
"nullsNotDistinct": false,
"columns": [
"id"
]
],
"nullsNotDistinct": false
}
}
}
},
"enums": {},
"schemas": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
"tables": {},
"columns": {}
},
"id": "03ab9ad6-742c-452d-94b6-9857493b1baf",
"prevId": "fc3ac108-d576-44a9-a1bb-95c61c4cb449"
}
185 changes: 185 additions & 0 deletions apps/server/src/db/drizzle/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"id": "38fd37ab-0d40-4750-a8b9-25d4a2fbee0b",
"prevId": "03ab9ad6-742c-452d-94b6-9857493b1baf",
"version": "6",
"dialect": "postgresql",
"tables": {
"public.items": {
"name": "items",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "bigserial",
"primaryKey": true,
"notNull": true
},
"auction_house_id": {
"name": "auction_house_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"item_id": {
"name": "item_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"pet_species_id": {
"name": "pet_species_id",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"min_buyout": {
"name": "min_buyout",
"type": "numeric",
"primaryKey": false,
"notNull": true
},
"quantity": {
"name": "quantity",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"market_value": {
"name": "market_value",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"historical": {
"name": "historical",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"num_auctions": {
"name": "num_auctions",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"timestamp": {
"name": "timestamp",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {
"items_item_id_auction_house_id_ts_idx": {
"name": "items_item_id_auction_house_id_ts_idx",
"columns": [
"item_id",
"auction_house_id",
"timestamp"
],
"isUnique": false
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.items_metadata": {
"name": "items_metadata",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "bigserial",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"slug": {
"name": "slug",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"locale": {
"name": "locale",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'en_US'"
},
"quality": {
"name": "quality",
"type": "integer",
"primaryKey": false,
"notNull": false,
"default": 1
},
"tags": {
"name": "tags",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"item_level": {
"name": "item_level",
"type": "integer",
"primaryKey": false,
"notNull": false,
"default": 0
},
"required_level": {
"name": "required_level",
"type": "integer",
"primaryKey": false,
"notNull": false,
"default": 0
}
},
"indexes": {
"items_metadata_id_idx": {
"name": "items_metadata_id_idx",
"columns": [
"id"
],
"isUnique": false
},
"items_metadata_id_locale_idx": {
"name": "items_metadata_id_locale_idx",
"columns": [
"id",
"locale"
],
"isUnique": false
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"items_metadata_id_unq": {
"name": "items_metadata_id_unq",
"nullsNotDistinct": false,
"columns": [
"id"
]
}
}
}
},
"enums": {},
"schemas": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
7 changes: 7 additions & 0 deletions apps/server/src/db/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"when": 1709673329815,
"tag": "0001_numerous_mysterio",
"breakpoints": true
},
{
"idx": 2,
"version": "6",
"when": 1721419759043,
"tag": "0002_funny_scorpion",
"breakpoints": true
}
]
}
13 changes: 11 additions & 2 deletions apps/server/src/db/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { text, integer, pgTable, unique, index, bigserial, timestamp } from 'drizzle-orm/pg-core';
import {
text,
integer,
pgTable,
unique,
index,
bigserial,
timestamp,
numeric,
} from 'drizzle-orm/pg-core';
import { createInsertSchema } from 'drizzle-zod';

export const items = pgTable(
Expand All @@ -8,7 +17,7 @@ export const items = pgTable(
auctionHouseId: integer('auction_house_id').notNull(),
itemId: integer('item_id').notNull(),
petSpeciesId: integer('pet_species_id'),
minBuyout: integer('min_buyout').notNull(),
minBuyout: numeric('min_buyout').notNull(),
quantity: integer('quantity').notNull(),
marketValue: integer('market_value').notNull(),
historical: integer('historical').notNull(),
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/utils/tsm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export async function getItem(itemId: number, auctionHouseId: number, tsmApiKey:
numAuctions: item.numAuctions,
marketValue: item.marketValue,
historical: item.historical,
minBuyout: item.minBuyout,
minBuyout: item.minBuyout.toString(),
quantity: item.quantity,
})
.onConflictDoNothing();
Expand Down

0 comments on commit a4f38e1

Please sign in to comment.