feat(api): Update section creation routes to support Tiers
This commit is contained in:
parent
3a11590795
commit
ed36645cc8
1 changed files with 38 additions and 13 deletions
|
|
@ -476,7 +476,24 @@ export async function layoutRoutes(fastify: FastifyInstance, options: FastifyPlu
|
||||||
fastify.post('/sections', {
|
fastify.post('/sections', {
|
||||||
handler: async (request, reply) => {
|
handler: async (request, reply) => {
|
||||||
try {
|
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({
|
const section = await prisma.facilitySection.create({
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -490,14 +507,10 @@ export async function layoutRoutes(fastify: FastifyInstance, options: FastifyPlu
|
||||||
height,
|
height,
|
||||||
rows,
|
rows,
|
||||||
columns,
|
columns,
|
||||||
|
tiers: numTiers,
|
||||||
spacing: spacing || 12,
|
spacing: spacing || 12,
|
||||||
positions: {
|
positions: {
|
||||||
create: Array.from({ length: rows * columns }, (_, i) => ({
|
create: positionsToCreate
|
||||||
row: Math.floor(i / columns) + 1,
|
|
||||||
column: (i % columns) + 1,
|
|
||||||
slot: 1,
|
|
||||||
status: 'EMPTY'
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
include: { positions: true }
|
include: { positions: true }
|
||||||
|
|
@ -611,6 +624,7 @@ export async function layoutRoutes(fastify: FastifyInstance, options: FastifyPlu
|
||||||
height: sec.height,
|
height: sec.height,
|
||||||
rows: sec.rows,
|
rows: sec.rows,
|
||||||
columns: sec.columns,
|
columns: sec.columns,
|
||||||
|
tiers: sec.tiers || 1,
|
||||||
spacing: sec.spacing || 12
|
spacing: sec.spacing || 12
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -622,17 +636,28 @@ export async function layoutRoutes(fastify: FastifyInstance, options: FastifyPlu
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Create new section with positions
|
// 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({
|
await tx.facilitySection.create({
|
||||||
data: {
|
data: {
|
||||||
id: sec.id,
|
id: sec.id,
|
||||||
...secData,
|
...secData,
|
||||||
positions: {
|
positions: {
|
||||||
create: Array.from({ length: sec.rows * sec.columns }, (_, i) => ({
|
create: positionsToCreate
|
||||||
row: Math.floor(i / sec.columns) + 1,
|
|
||||||
column: (i % sec.columns) + 1,
|
|
||||||
slot: 1,
|
|
||||||
status: 'EMPTY'
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue