This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
-- The terminals used to own the tabs and report them as snapshots; the server holds them in "Tab" now
|
||||||
|
DROP TABLE "OpenTabSnapshot";
|
||||||
|
|
||||||
|
DROP TABLE "TabOwnership";
|
||||||
@@ -15,7 +15,6 @@ model Venue {
|
|||||||
|
|
||||||
devices Device[]
|
devices Device[]
|
||||||
clientUsers ClientUser[]
|
clientUsers ClientUser[]
|
||||||
tabOwnerships TabOwnership[]
|
|
||||||
remoteCommands RemoteCommand[]
|
remoteCommands RemoteCommand[]
|
||||||
auditLogs AuditLog[]
|
auditLogs AuditLog[]
|
||||||
regCodes RegistrationCode[]
|
regCodes RegistrationCode[]
|
||||||
@@ -44,8 +43,6 @@ model Device {
|
|||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
||||||
venue Venue @relation(fields: [venueId], references: [id])
|
venue Venue @relation(fields: [venueId], references: [id])
|
||||||
tabSnapshots OpenTabSnapshot[]
|
|
||||||
tabOwnerships TabOwnership[]
|
|
||||||
remoteCommands RemoteCommand[]
|
remoteCommands RemoteCommand[]
|
||||||
tabEvents TabEvent[]
|
tabEvents TabEvent[]
|
||||||
settlements Settlement[]
|
settlements Settlement[]
|
||||||
@@ -81,38 +78,6 @@ model RegistrationCode {
|
|||||||
@@index([venueId])
|
@@index([venueId])
|
||||||
}
|
}
|
||||||
|
|
||||||
model OpenTabSnapshot {
|
|
||||||
id String @id @default(uuid())
|
|
||||||
deviceId String
|
|
||||||
tabId String
|
|
||||||
customerName String
|
|
||||||
version Int
|
|
||||||
totalInCents Int
|
|
||||||
itemCount Int
|
|
||||||
// The tab's lines as reported by the terminal: [{ productName, quantity, unitPriceInCents }].
|
|
||||||
// Null for terminals running an app version that doesn't report them.
|
|
||||||
items Json?
|
|
||||||
reportedAt DateTime
|
|
||||||
|
|
||||||
device Device @relation(fields: [deviceId], references: [id])
|
|
||||||
|
|
||||||
@@unique([deviceId, tabId])
|
|
||||||
@@index([deviceId])
|
|
||||||
@@index([tabId, reportedAt])
|
|
||||||
}
|
|
||||||
|
|
||||||
model TabOwnership {
|
|
||||||
tabId String
|
|
||||||
venueId String
|
|
||||||
deviceId String
|
|
||||||
lastReportedAt DateTime
|
|
||||||
|
|
||||||
venue Venue @relation(fields: [venueId], references: [id])
|
|
||||||
device Device @relation(fields: [deviceId], references: [id])
|
|
||||||
|
|
||||||
@@id([venueId, tabId])
|
|
||||||
}
|
|
||||||
|
|
||||||
// A request from the dashboard. close_tab used to be executed by the owning terminal; the server now settles
|
// A request from the dashboard. close_tab used to be executed by the owning terminal; the server now settles
|
||||||
// the tab itself and records the command as completed right away, for the history.
|
// the tab itself and records the command as completed right away, for the history.
|
||||||
model RemoteCommand {
|
model RemoteCommand {
|
||||||
|
|||||||
+33
-15
@@ -5,13 +5,41 @@ const crypto = require('crypto');
|
|||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
// One line with itemCount units, priced so the tab adds up to about totalInCents
|
||||||
|
async function createTab(venueId, tab) {
|
||||||
|
const lineId = uuidv4();
|
||||||
|
const addedAt = tab.reportedAt.toISOString();
|
||||||
|
await prisma.tab.create({
|
||||||
|
data: {
|
||||||
|
venueId,
|
||||||
|
id: tab.tabId,
|
||||||
|
customerName: tab.customerName,
|
||||||
|
openedAt: tab.reportedAt,
|
||||||
|
version: tab.version,
|
||||||
|
lines: [{
|
||||||
|
id: lineId,
|
||||||
|
productId: null,
|
||||||
|
productName: 'Pils',
|
||||||
|
unitPriceInCents: Math.round(tab.totalInCents / tab.itemCount),
|
||||||
|
units: Array.from({ length: tab.itemCount }, (_, i) => ({ id: `${lineId}:${i}`, addedAt, removedAt: null })),
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log('Seeding database...');
|
console.log('Seeding database...');
|
||||||
|
|
||||||
await prisma.auditLog.deleteMany();
|
await prisma.auditLog.deleteMany();
|
||||||
|
await prisma.tabEvent.deleteMany();
|
||||||
|
await prisma.tabReminder.deleteMany();
|
||||||
|
await prisma.plannedTab.deleteMany();
|
||||||
await prisma.remoteCommand.deleteMany();
|
await prisma.remoteCommand.deleteMany();
|
||||||
await prisma.openTabSnapshot.deleteMany();
|
await prisma.settlement.deleteMany();
|
||||||
await prisma.tabOwnership.deleteMany();
|
await prisma.tab.deleteMany();
|
||||||
|
await prisma.stockAdjustment.deleteMany();
|
||||||
|
await prisma.product.deleteMany();
|
||||||
|
await prisma.productImage.deleteMany();
|
||||||
await prisma.refreshToken.deleteMany();
|
await prisma.refreshToken.deleteMany();
|
||||||
await prisma.registrationCode.deleteMany();
|
await prisma.registrationCode.deleteMany();
|
||||||
await prisma.device.deleteMany();
|
await prisma.device.deleteMany();
|
||||||
@@ -92,12 +120,7 @@ async function main() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (const tab of tabsData) {
|
for (const tab of tabsData) {
|
||||||
await prisma.tabOwnership.create({
|
await createTab(venueId, tab);
|
||||||
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 },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const staleTabs = [
|
const staleTabs = [
|
||||||
@@ -106,15 +129,10 @@ async function main() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (const tab of staleTabs) {
|
for (const tab of staleTabs) {
|
||||||
await prisma.tabOwnership.create({
|
await createTab(venueId, tab);
|
||||||
data: { tabId: tab.tabId, venueId, deviceId: device2Id, 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 },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Created 6 open tabs across 2 devices');
|
console.log('Created 6 open tabs');
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
|
|||||||
+26
-7
@@ -10,9 +10,15 @@ async function main() {
|
|||||||
|
|
||||||
// Clean existing data so seed is idempotent
|
// Clean existing data so seed is idempotent
|
||||||
await prisma.auditLog.deleteMany();
|
await prisma.auditLog.deleteMany();
|
||||||
|
await prisma.tabEvent.deleteMany();
|
||||||
|
await prisma.tabReminder.deleteMany();
|
||||||
|
await prisma.plannedTab.deleteMany();
|
||||||
await prisma.remoteCommand.deleteMany();
|
await prisma.remoteCommand.deleteMany();
|
||||||
await prisma.openTabSnapshot.deleteMany();
|
await prisma.settlement.deleteMany();
|
||||||
await prisma.tabOwnership.deleteMany();
|
await prisma.tab.deleteMany();
|
||||||
|
await prisma.stockAdjustment.deleteMany();
|
||||||
|
await prisma.product.deleteMany();
|
||||||
|
await prisma.productImage.deleteMany();
|
||||||
await prisma.refreshToken.deleteMany();
|
await prisma.refreshToken.deleteMany();
|
||||||
await prisma.registrationCode.deleteMany();
|
await prisma.registrationCode.deleteMany();
|
||||||
await prisma.device.deleteMany();
|
await prisma.device.deleteMany();
|
||||||
@@ -83,11 +89,24 @@ async function main() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (const tab of tabsData) {
|
for (const tab of tabsData) {
|
||||||
await prisma.tabOwnership.create({
|
// One line with itemCount units, priced so the tab adds up to about totalInCents
|
||||||
data: { tabId: tab.tabId, venueId, deviceId, lastReportedAt: tab.reportedAt },
|
const lineId = uuidv4();
|
||||||
});
|
const addedAt = tab.reportedAt.toISOString();
|
||||||
await prisma.openTabSnapshot.create({
|
await prisma.tab.create({
|
||||||
data: { deviceId, tabId: tab.tabId, customerName: tab.customerName, version: tab.version, totalInCents: tab.totalInCents, itemCount: tab.itemCount, reportedAt: tab.reportedAt },
|
data: {
|
||||||
|
venueId,
|
||||||
|
id: tab.tabId,
|
||||||
|
customerName: tab.customerName,
|
||||||
|
openedAt: tab.reportedAt,
|
||||||
|
version: tab.version,
|
||||||
|
lines: [{
|
||||||
|
id: lineId,
|
||||||
|
productId: null,
|
||||||
|
productName: 'Pils',
|
||||||
|
unitPriceInCents: Math.round(tab.totalInCents / tab.itemCount),
|
||||||
|
units: Array.from({ length: tab.itemCount }, (_, i) => ({ id: `${lineId}:${i}`, addedAt, removedAt: null })),
|
||||||
|
}],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,11 @@ async function main() {
|
|||||||
await tx.tabReminder.deleteMany();
|
await tx.tabReminder.deleteMany();
|
||||||
await tx.plannedTab.deleteMany();
|
await tx.plannedTab.deleteMany();
|
||||||
await tx.remoteCommand.deleteMany();
|
await tx.remoteCommand.deleteMany();
|
||||||
await tx.openTabSnapshot.deleteMany();
|
await tx.settlement.deleteMany();
|
||||||
await tx.tabOwnership.deleteMany();
|
await tx.tab.deleteMany();
|
||||||
|
await tx.stockAdjustment.deleteMany();
|
||||||
|
await tx.product.deleteMany();
|
||||||
|
await tx.productImage.deleteMany();
|
||||||
await tx.refreshToken.deleteMany();
|
await tx.refreshToken.deleteMany();
|
||||||
await tx.registrationCode.deleteMany();
|
await tx.registrationCode.deleteMany();
|
||||||
await tx.device.deleteMany();
|
await tx.device.deleteMany();
|
||||||
|
|||||||
Reference in New Issue
Block a user