Restructure project to root layout
This commit is contained in:
1 parent
e0e26a34ab
commit
3ffe9bbf99
51 files changed
+16
-12
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import Dexie, { Table } from 'dexie';
|
||||
import { Area } from '../models/Area';
|
||||
import { PickItem } from '../models/PickItem';
|
||||
import { PickList } from '../models/PickList';
|
||||
import { Product } from '../models/Product';
|
||||
import { applyMigrations } from './migrations';
|
||||
import { seedDatabase } from './seed';
|
||||
|
||||
export class StockFillDB extends Dexie {
|
||||
products!: Table<Product>;
|
||||
areas!: Table<Area>;
|
||||
pickLists!: Table<PickList>;
|
||||
pickItems!: Table<PickItem>;
|
||||
|
||||
constructor() {
|
||||
super('stockfill');
|
||||
this.version(1).stores({
|
||||
products:
|
||||
'id, name, category, barcode, archived, created_at, updated_at',
|
||||
areas: 'id, name, created_at, updated_at',
|
||||
pickLists: 'id, area_id, created_at, completed_at',
|
||||
pickItems: 'id, pick_list_id, product_id, status, created_at, updated_at',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const db = new StockFillDB();
|
||||
|
||||
export const initializeDatabase = async () => {
|
||||
await applyMigrations(db);
|
||||
await seedDatabase(db);
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
import { StockFillDB } from './index';
|
||||
|
||||
export const applyMigrations = async (db: StockFillDB) => {
|
||||
// Future migrations can be added here.
|
||||
await db.open();
|
||||
};
|
||||
@@ -0,0 +1,54 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { StockFillDB } from './index';
|
||||
|
||||
const now = () => Date.now();
|
||||
|
||||
export const seedDatabase = async (db: StockFillDB) => {
|
||||
const areaCount = await db.areas.count();
|
||||
if (areaCount === 0) {
|
||||
await db.areas.bulkAdd([
|
||||
{ id: uuidv4(), name: 'Drinks', created_at: now(), updated_at: now() },
|
||||
{ id: uuidv4(), name: 'Snacks', created_at: now(), updated_at: now() },
|
||||
{ id: uuidv4(), name: 'Dairy', created_at: now(), updated_at: now() },
|
||||
]);
|
||||
}
|
||||
|
||||
const productCount = await db.products.count();
|
||||
if (productCount === 0) {
|
||||
await db.products.bulkAdd([
|
||||
{
|
||||
id: uuidv4(),
|
||||
name: 'Sparkling Water 500ml',
|
||||
category: 'Drinks',
|
||||
unit_type: 'bottle',
|
||||
bulk_name: 'case',
|
||||
units_per_bulk: 12,
|
||||
archived: false,
|
||||
created_at: now(),
|
||||
updated_at: now(),
|
||||
},
|
||||
{
|
||||
id: uuidv4(),
|
||||
name: 'Salted Chips 50g',
|
||||
category: 'Snacks',
|
||||
unit_type: 'bag',
|
||||
bulk_name: 'box',
|
||||
units_per_bulk: 24,
|
||||
archived: false,
|
||||
created_at: now(),
|
||||
updated_at: now(),
|
||||
},
|
||||
{
|
||||
id: uuidv4(),
|
||||
name: 'Chocolate Bar',
|
||||
category: 'Confectionery',
|
||||
unit_type: 'bar',
|
||||
bulk_name: 'slab',
|
||||
units_per_bulk: 32,
|
||||
archived: false,
|
||||
created_at: now(),
|
||||
updated_at: now(),
|
||||
},
|
||||
]);
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user