This commit is contained in:
+33
-15
@@ -5,13 +5,41 @@ const crypto = require('crypto');
|
||||
|
||||
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() {
|
||||
console.log('Seeding database...');
|
||||
|
||||
await prisma.auditLog.deleteMany();
|
||||
await prisma.tabEvent.deleteMany();
|
||||
await prisma.tabReminder.deleteMany();
|
||||
await prisma.plannedTab.deleteMany();
|
||||
await prisma.remoteCommand.deleteMany();
|
||||
await prisma.openTabSnapshot.deleteMany();
|
||||
await prisma.tabOwnership.deleteMany();
|
||||
await prisma.settlement.deleteMany();
|
||||
await prisma.tab.deleteMany();
|
||||
await prisma.stockAdjustment.deleteMany();
|
||||
await prisma.product.deleteMany();
|
||||
await prisma.productImage.deleteMany();
|
||||
await prisma.refreshToken.deleteMany();
|
||||
await prisma.registrationCode.deleteMany();
|
||||
await prisma.device.deleteMany();
|
||||
@@ -92,12 +120,7 @@ async function main() {
|
||||
];
|
||||
|
||||
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 },
|
||||
});
|
||||
await createTab(venueId, tab);
|
||||
}
|
||||
|
||||
const staleTabs = [
|
||||
@@ -106,15 +129,10 @@ async function main() {
|
||||
];
|
||||
|
||||
for (const tab of staleTabs) {
|
||||
await prisma.tabOwnership.create({
|
||||
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 },
|
||||
});
|
||||
await createTab(venueId, tab);
|
||||
}
|
||||
|
||||
console.log('Created 6 open tabs across 2 devices');
|
||||
console.log('Created 6 open tabs');
|
||||
|
||||
const now = new Date();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user