feat: add plannedTabs

This commit is contained in:
2026-09-20 12:20:55 +02:00
parent 4eb9bf7643
commit db3d8f30f0
28 changed files with 1172 additions and 782 deletions
+18 -80
View File
@@ -55,103 +55,43 @@ async function main() {
});
console.log('Created viewer user: viewer@example.com / Viewer123!');
// Create devices
const device1Id = uuidv4();
const device2Id = uuidv4();
const token1 = 'dev_' + crypto.randomBytes(48).toString('base64url');
const token2 = 'dev_' + crypto.randomBytes(48).toString('base64url');
// Create one device
const deviceId = uuidv4();
const token = 'dev_' + crypto.randomBytes(48).toString('base64url');
await prisma.device.create({
data: {
id: device1Id,
id: deviceId,
venueId,
name: 'Bar terminal 1',
tokenHash: crypto.createHash('sha256').update(token1).digest('hex'),
tokenPrefix: token1.substring(0, 8),
tokenHash: crypto.createHash('sha256').update(token).digest('hex'),
tokenPrefix: token.substring(0, 8),
tokenExpiresAt: new Date(Date.now() + 90 * 24 * 60 * 60 * 1000),
lastSeenAt: new Date(Date.now() - 1 * 60 * 1000), // seen 1 minute ago (online)
lastSeenAt: new Date(Date.now() - 1 * 60 * 1000),
},
});
await prisma.device.create({
data: {
id: device2Id,
venueId,
name: 'Bar terminal 2',
tokenHash: crypto.createHash('sha256').update(token2).digest('hex'),
tokenPrefix: token2.substring(0, 8),
tokenExpiresAt: new Date(Date.now() + 90 * 24 * 60 * 60 * 1000),
lastSeenAt: new Date(Date.now() - 15 * 60 * 1000), // seen 15 minutes ago (stale)
},
});
console.log(`Created device: Bar terminal 1 (${deviceId})`);
console.log(`Created device: Bar terminal 1 (${device1Id})`);
console.log(`Created device: Bar terminal 2 (${device2Id})`);
console.log(`Device 1 token: ${token1}`);
console.log(`Device 2 token: ${token2}`);
// Create tab ownership and snapshots for device 1
const tabsData = [
{ tabId: uuidv4(), customerName: 'Jan', version: 5, totalInCents: 2450, itemCount: 3, reportedAt: new Date(Date.now() - 2 * 60 * 1000) },
{ tabId: uuidv4(), customerName: 'Marie', version: 3, totalInCents: 1800, itemCount: 2, reportedAt: new Date(Date.now() - 5 * 60 * 1000) },
{ tabId: uuidv4(), customerName: 'Thomas', version: 7, totalInCents: 4200, itemCount: 5, reportedAt: new Date(Date.now() - 3 * 60 * 1000) },
{ tabId: uuidv4(), customerName: 'Lisa', version: 2, totalInCents: 900, itemCount: 1, reportedAt: new Date(Date.now() - 4 * 60 * 1000) },
];
for (const tab of tabsData) {
await prisma.tabOwnership.create({
data: {
tabId: tab.tabId,
venueId,
deviceId: device1Id,
lastReportedAt: tab.reportedAt,
},
});
await prisma.openTabSnapshot.create({
data: {
deviceId: device1Id,
tabId: tab.tabId,
customerName: tab.customerName,
version: tab.version,
totalInCents: tab.totalInCents,
itemCount: tab.itemCount,
reportedAt: tab.reportedAt,
},
});
}
// Create tab ownership and snapshots for device 2 (stale)
const staleTabs = [
{ tabId: uuidv4(), customerName: 'Emma', version: 4, totalInCents: 3200, itemCount: 4, reportedAt: new Date(Date.now() - 16 * 60 * 1000) },
{ tabId: uuidv4(), customerName: 'David', version: 1, totalInCents: 1500, itemCount: 2, reportedAt: new Date(Date.now() - 20 * 60 * 1000) },
];
for (const tab of staleTabs) {
for (const tab of tabsData) {
await prisma.tabOwnership.create({
data: {
tabId: tab.tabId,
venueId,
deviceId: device2Id,
lastReportedAt: tab.reportedAt,
},
data: { tabId: tab.tabId, venueId, deviceId, lastReportedAt: tab.reportedAt },
});
await prisma.openTabSnapshot.create({
data: {
deviceId: device2Id,
tabId: tab.tabId,
customerName: tab.customerName,
version: tab.version,
totalInCents: tab.totalInCents,
itemCount: tab.itemCount,
reportedAt: tab.reportedAt,
},
data: { deviceId, tabId: tab.tabId, customerName: tab.customerName, version: tab.version, totalInCents: tab.totalInCents, itemCount: tab.itemCount, reportedAt: tab.reportedAt },
});
}
console.log('Created 6 open tabs across 2 devices');
console.log('Created 6 open tabs');
// Create sample commands
const now = new Date();
@@ -161,7 +101,7 @@ async function main() {
data: {
id: uuidv4(),
venueId,
deviceId: device1Id,
deviceId,
targetTabId: tabsData[1].tabId,
type: 'close_tab',
expectedVersion: 3,
@@ -180,7 +120,7 @@ async function main() {
data: {
id: uuidv4(),
venueId,
deviceId: device1Id,
deviceId,
targetTabId: tabsData[0].tabId,
type: 'close_tab',
expectedVersion: 5,
@@ -197,8 +137,8 @@ async function main() {
data: {
id: uuidv4(),
venueId,
deviceId: device2Id,
targetTabId: staleTabs[0].tabId,
deviceId,
targetTabId: tabsData[4].tabId,
type: 'close_tab',
expectedVersion: 4,
paymentMethod: 'payment_pending',
@@ -216,7 +156,7 @@ async function main() {
data: {
id: uuidv4(),
venueId,
deviceId: device1Id,
deviceId,
targetTabId: tabsData[2].tabId,
type: 'close_tab',
expectedVersion: 7,
@@ -249,9 +189,7 @@ async function main() {
console.log('Demo credentials:');
console.log(' Admin: admin@example.com / Admin123!');
console.log(' Viewer: viewer@example.com / Viewer123!');
console.log(`\nDevice tokens (for simulator):`);
console.log(` Bar terminal 1: ${token1}`);
console.log(` Bar terminal 2: ${token2}`);
console.log(`\nDevice token (for simulator): ${token}`);
}
main()