Skip to content

Commit e663459

Browse files
committed
Update group creation ID
1 parent 254f2ed commit e663459

File tree

1 file changed

+49
-31
lines changed

1 file changed

+49
-31
lines changed

src/api/routes/organizations.ts

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import {
6161
assignIdpGroupsToTeam,
6262
createGithubTeam,
6363
} from "api/functions/github.js";
64-
import { requestFormReset } from "react-dom";
6564

6665
export const CLIENT_HTTP_CACHE_POLICY = `public, max-age=${ORG_DATA_CACHED_DURATION}, stale-while-revalidate=${Math.floor(ORG_DATA_CACHED_DURATION * 1.1)}, stale-if-error=3600`;
6766

@@ -396,7 +395,7 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
396395
primaryKey: `DEFINE#${request.params.orgId}`,
397396
entryId: "0",
398397
}),
399-
AttributesToGet: ["leadsEntraGroupId"],
398+
AttributesToGet: ["leadsEntraGroupId", "leadsGithubTeamId"],
400399
ConsistentRead: true,
401400
});
402401

@@ -527,33 +526,36 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
527526
}
528527
}
529528

530-
const storeIdsOperation = async () => {
531-
const commandTransaction = new TransactWriteItemsCommand({
532-
TransactItems: [
533-
...logStatements,
534-
{
535-
Put: {
536-
TableName: genericConfig.SigInfoTableName,
537-
Item: marshall(
538-
{
539-
primaryKey: `DEFINE#${request.params.orgId}`,
540-
entryId: "0",
541-
...updates,
542-
},
543-
{ removeUndefinedValues: true },
544-
),
529+
// Store external group IDs if they were created
530+
if (Object.keys(updates).length > 0) {
531+
const storeIdsOperation = async () => {
532+
const commandTransaction = new TransactWriteItemsCommand({
533+
TransactItems: [
534+
...logStatements,
535+
{
536+
Put: {
537+
TableName: genericConfig.SigInfoTableName,
538+
Item: marshall(
539+
{
540+
primaryKey: `DEFINE#${request.params.orgId}`,
541+
entryId: "0",
542+
...updates,
543+
},
544+
{ removeUndefinedValues: true },
545+
),
546+
},
545547
},
546-
},
547-
],
548-
});
549-
return await clients.dynamoClient.send(commandTransaction);
550-
};
548+
],
549+
});
550+
return await clients.dynamoClient.send(commandTransaction);
551+
};
551552

552-
await retryDynamoTransactionWithBackoff(
553-
storeIdsOperation,
554-
request.log,
555-
`Store group IDs for ${request.params.orgId}`,
556-
);
553+
await retryDynamoTransactionWithBackoff(
554+
storeIdsOperation,
555+
request.log,
556+
`Store group IDs for ${request.params.orgId}`,
557+
);
558+
}
557559
}
558560

559561
const commonArgs = {
@@ -572,10 +574,26 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
572574
removeLead({ ...commonArgs, username }),
573575
);
574576

575-
const results = await Promise.allSettled([
576-
...addPromises,
577-
...removePromises,
578-
]);
577+
// Execute all add/remove operations sequentially to avoid transaction conflicts
578+
const results: PromiseSettledResult<SQSMessage | null>[] = [];
579+
580+
// Process adds
581+
for (const promise of addPromises) {
582+
const result = await promise.then(
583+
(value) => ({ status: "fulfilled" as const, value }),
584+
(reason) => ({ status: "rejected" as const, reason }),
585+
);
586+
results.push(result);
587+
}
588+
589+
// Process removes
590+
for (const promise of removePromises) {
591+
const result = await promise.then(
592+
(value) => ({ status: "fulfilled" as const, value }),
593+
(reason) => ({ status: "rejected" as const, reason }),
594+
);
595+
results.push(result);
596+
}
579597

580598
const failures = results.filter((r) => r.status === "rejected");
581599
if (failures.length > 0) {

0 commit comments

Comments
 (0)