odoo-next-backend/seed_pos.js
2026-01-22 21:21:56 +05:30

54 lines
1.8 KiB
JavaScript

async function seed() {
const baseUrl = 'http://localhost:5000/api/pos';
// Floors
const floors = [
{ id: 1, name: 'First Floor' },
{ id: 2, name: 'Ground Floor' }
];
// Tables
const tables = [
{ id: 1, floorId: 1, name: 'Table 1', seats: 8, x: 200, y: 150, shape: 'circle' },
{ id: 2, floorId: 1, name: 'Table 2', seats: 6, x: 450, y: 150, shape: 'circle' },
{ id: 3, floorId: 1, name: 'Table 3', seats: 4, x: 700, y: 150, shape: 'square' },
{ id: 4, floorId: 1, name: 'Table 4', seats: 8, x: 300, y: 400, shape: 'circle' },
{ id: 5, floorId: 1, name: 'Table 5', seats: 2, x: 600, y: 400, shape: 'circle' },
{ id: 6, floorId: 2, name: 'Table G1', seats: 4, x: 200, y: 200, shape: 'circle' }
];
console.log('Seeding Floors...');
for (const floor of floors) {
try {
const res = await fetch(`${baseUrl}/floors`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(floor)
});
const text = await res.text();
console.log(`Floor ${floor.name}: ${res.status} - ${text}`);
} catch (e) {
console.error(`Error seeding floor ${floor.name}:`, e.message);
}
}
console.log('Seeding Tables...');
for (const table of tables) {
try {
const res = await fetch(`${baseUrl}/tables`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(table)
});
const text = await res.text();
console.log(`Table ${table.name}: ${res.status} - ${text}`);
} catch (e) {
console.error(`Error seeding table ${table.name}:`, e.message);
}
}
}
seed();