diff --git a/backend/src/routes/layout.routes.ts b/backend/src/routes/layout.routes.ts index 3e27ac8..5e769c1 100644 --- a/backend/src/routes/layout.routes.ts +++ b/backend/src/routes/layout.routes.ts @@ -476,7 +476,24 @@ export async function layoutRoutes(fastify: FastifyInstance, options: FastifyPlu fastify.post('/sections', { handler: async (request, reply) => { try { - const { roomId, name, code, type, posX, posY, width, height, rows, columns, spacing } = request.body as any; + const { roomId, name, code, type, posX, posY, width, height, rows, columns, spacing, tiers } = request.body as any; + const numTiers = tiers || 1; + + // Generate positions for all rows, columns, and tiers + const positionsToCreate = []; + for (let r = 1; r <= rows; r++) { + for (let c = 1; c <= columns; c++) { + for (let t = 1; t <= numTiers; t++) { + positionsToCreate.push({ + row: r, + column: c, + tier: t, + slot: 1, + status: 'EMPTY' + }); + } + } + } const section = await prisma.facilitySection.create({ data: { @@ -490,14 +507,10 @@ export async function layoutRoutes(fastify: FastifyInstance, options: FastifyPlu height, rows, columns, + tiers: numTiers, spacing: spacing || 12, positions: { - create: Array.from({ length: rows * columns }, (_, i) => ({ - row: Math.floor(i / columns) + 1, - column: (i % columns) + 1, - slot: 1, - status: 'EMPTY' - })) + create: positionsToCreate } }, include: { positions: true } @@ -611,6 +624,7 @@ export async function layoutRoutes(fastify: FastifyInstance, options: FastifyPlu height: sec.height, rows: sec.rows, columns: sec.columns, + tiers: sec.tiers || 1, spacing: sec.spacing || 12 }; @@ -622,17 +636,28 @@ export async function layoutRoutes(fastify: FastifyInstance, options: FastifyPlu }); } else { // Create new section with positions + const numTiers = sec.tiers || 1; + const positionsToCreate = []; + for (let r = 1; r <= sec.rows; r++) { + for (let c = 1; c <= sec.columns; c++) { + for (let t = 1; t <= numTiers; t++) { + positionsToCreate.push({ + row: r, + column: c, + tier: t, + slot: 1, + status: 'EMPTY' + }); + } + } + } + await tx.facilitySection.create({ data: { id: sec.id, ...secData, positions: { - create: Array.from({ length: sec.rows * sec.columns }, (_, i) => ({ - row: Math.floor(i / sec.columns) + 1, - column: (i % sec.columns) + 1, - slot: 1, - status: 'EMPTY' - })) + create: positionsToCreate } } });