[wip] bugs to work out, but backend should support inventory

This commit is contained in:
2026-04-02 19:24:51 -04:00
parent 38f041d86f
commit 3be17fe84c
8 changed files with 240 additions and 100 deletions

View File

@@ -88,6 +88,25 @@ export const createSkuCollection = async () => {
console.log(chalk.green('Collection "skus" created successfully.'));
}
// Delete and recreate the 'inventory' index
export const createInventoryCollection = async () => {
try {
await client.collections('inventories').delete();
} catch (error) {
// Ignore error, just means collection doesn't exist
}
await client.collections().create({
name: 'inventories',
fields: [
{ name: 'id', type: 'string' },
{ name: 'userId', type: 'string' },
{ name: 'catalogName', type: 'string' },
{ name: 'card_id', type: 'string', reference: 'cards.id' },
]
});
console.log(chalk.green('Collection "inventories" created successfully.'));
}
export const upsertCardCollection = async (db:DBInstance) => {
const pokemon = await db.query.cards.findMany({
@@ -131,6 +150,17 @@ export const upsertSkuCollection = async (db:DBInstance) => {
console.log(chalk.green('Collection "skus" indexed successfully.'));
}
export const upsertInventoryCollection = async (db:DBInstance) => {
const inv = await db.query.inventory.findMany();
await client.collections('inventories').documents().import(inv.map(i => ({
id: i.inventoryId,
userId: i.userId,
catalogName: i.catalogName,
card_id: i.cardId.toString(),
})), { action: 'upsert' });
console.log(chalk.green('Collection "inventories" indexed successfully.'));
}

View File

@@ -5,7 +5,10 @@ import * as Indexing from './pokemon-helper.ts';
//await Indexing.createCardCollection();
//await Indexing.createSkuCollection();
await Indexing.upsertCardCollection(db);
await Indexing.upsertSkuCollection(db);
await Indexing.createInventoryCollection();
//await Indexing.upsertCardCollection(db);
//await Indexing.upsertSkuCollection(db);
await Indexing.upsertInventoryCollection(db);
await ClosePool();
console.log(chalk.green('Pokémon reindex complete.'));