feat(api): Update section creation routes to support Tiers
Some checks failed
Deploy to Production / deploy (push) Failing after 0s
Test / backend-test (push) Failing after 0s
Test / frontend-test (push) Failing after 0s

This commit is contained in:
fullsizemalt 2025-12-11 13:23:32 -08:00
parent 3a11590795
commit ed36645cc8

View file

@ -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
}
}
});