fix: add race condition guard and null check in group queries

- createOrFindPackageGroup: catch unique constraint violation from
  concurrent creates and fall back to findFirst
- createManualGroup: guard against empty package results before
  accessing first element

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-25 22:45:29 +01:00
parent d50c68f67c
commit a4156b2ac6
2 changed files with 24 additions and 10 deletions

View File

@@ -609,6 +609,9 @@ export async function createManualGroup(name: string, packageIds: string[]) {
where: { id: { in: packageIds } },
select: { sourceChannelId: true },
});
if (pkgs.length === 0) {
throw new Error("No matching packages found");
}
const channelIds = new Set(pkgs.map((p) => p.sourceChannelId));
if (channelIds.size > 1) {
throw new Error("Cannot group packages from different channels");