Skip to content

Commit 345c76b

Browse files
committed
deploying expo change
1 parent 6a5c52b commit 345c76b

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

services/expo/src/routes/project.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ projectRoutes.route("/").post(
184184
return;
185185
}
186186

187-
const projectExpo = Math.floor(Math.random() * config.numberOfExpo + 1);
187+
const projectExpo = Math.floor(Math.random() * config.numberOfExpo) + 1;
188188

189189
const tableGroups = await prisma.tableGroup.findMany({
190190
where: {
@@ -200,26 +200,19 @@ projectRoutes.route("/").post(
200200
});
201201

202202
let firstFreeTableGroup: undefined | TableGroup;
203-
let totalCapacity = 0;
204-
const tableNumberSet = new Set();
205203

206204
// select first non-empty tableGroup
207205
for (const tableGroup of tableGroups) {
208206
const projectsInCurrentExpoAndTableGroup = projectsInCurrentExpo.filter(
209207
project => project.tableGroupId === tableGroup.id
210208
);
211209

212-
for (const project of projectsInCurrentExpoAndTableGroup) {
213-
tableNumberSet.add(project.table);
214-
}
215-
216210
// check for first free table group to assign table number to
217-
const isFreeTableGroup = projectsInCurrentExpoAndTableGroup.length < tableGroup.tableCapacity;
218-
if (isFreeTableGroup && firstFreeTableGroup === undefined) {
211+
const isFreeTableGroup = projectsInCurrentExpoAndTableGroup.length < tableGroup.tableCapacity;
212+
if (isFreeTableGroup) {
219213
firstFreeTableGroup = tableGroup;
214+
break; // found free table group
220215
}
221-
222-
totalCapacity += tableGroup.tableCapacity;
223216
}
224217

225218
// no free table could be found; all table groups' capacities are full
@@ -229,9 +222,16 @@ projectRoutes.route("/").post(
229222
);
230223
}
231224

232-
// assigns table to first unused number
225+
const tableNumberSet = new Set<number>();
226+
for (const project of projectsInCurrentExpo) {
227+
if (project.tableGroupId === firstFreeTableGroup.id && project.table) {
228+
tableNumberSet.add(project.table);
229+
}
230+
}
231+
232+
// assigns table to first unused number
233233
let tableNumber;
234-
for (let i = 1; i <= totalCapacity; i++) {
234+
for (let i = 1; i <= firstFreeTableGroup.tableCapacity; i++) {
235235
if (!tableNumberSet.has(i)) {
236236
tableNumber = i;
237237
break;
@@ -376,7 +376,10 @@ projectRoutes.route("/:id").patch(
376376

377377
categories = dbCategories.map((category: any) => ({ id: category.id }));
378378

379-
if (tableGroup !== undefined) {
379+
if (tableGroup === undefined) {
380+
// see if the current table group (already assigned)
381+
// ADD CODE HERE
382+
} else {
380383
const dbTableGroup = await prisma.tableGroup.findUnique({
381384
where: { id: tableGroup },
382385
});

0 commit comments

Comments
 (0)