Skip to content

Commit 70140f6

Browse files
committed
test button for azure api
1 parent bced8dc commit 70140f6

File tree

6 files changed

+60
-14
lines changed

6 files changed

+60
-14
lines changed

src/api/functions/entraId.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
2929
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
3030
import { checkPaidMembershipFromTable } from "./membership.js";
3131

32-
function validateGroupId(groupId: string): boolean {
32+
export function validateGroupId(groupId: string): boolean {
3333
const groupIdPattern = /^[a-zA-Z0-9-]+$/; // Adjust the pattern as needed
3434
return groupIdPattern.test(groupId);
3535
}

src/api/functions/siglead.ts

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import {
22
AttributeValue,
33
DynamoDBClient,
4+
GetItemCommand,
45
PutItemCommand,
56
PutItemCommandInput,
67
QueryCommand,
78
ScanCommand,
89
} from "@aws-sdk/client-dynamodb";
910
import { unmarshall } from "@aws-sdk/util-dynamodb";
11+
import { DatabaseInsertError } from "common/errors/index.js";
1012
import { OrganizationList, orgIds2Name } from "common/orgs.js";
1113
import {
1214
DynamoDBItem,
@@ -113,7 +115,7 @@ export async function fetchSigCounts(
113115
return countsArray;
114116
}
115117

116-
export async function addMemberToSig(
118+
export async function addMemberToSigDynamo(
117119
sigMemberTableName: string,
118120
sigMemberUpdateRequest: SigMemberUpdateRecord,
119121
dynamoClient: DynamoDBClient,
@@ -122,12 +124,50 @@ export async function addMemberToSig(
122124
Object.entries(sigMemberUpdateRequest).forEach(([k, v]) => {
123125
item[k] = { S: v };
124126
});
125-
const input: PutItemCommandInput = {
127+
128+
// put into table
129+
const put = new PutItemCommand({
126130
Item: item,
127131
ReturnConsumedCapacity: "TOTAL",
128132
TableName: sigMemberTableName,
129-
};
130-
// console.log(input);
131-
const put = new PutItemCommand(input);
132-
const response = await dynamoClient.send(put);
133+
});
134+
try {
135+
const response = await dynamoClient.send(put);
136+
console.log(response);
137+
} catch (e) {
138+
console.error("Put to dynamo db went wrong.");
139+
throw e;
140+
}
141+
142+
// fetch from db and check if fetched item update time = input item update time
143+
const validatePutQuery = new GetItemCommand({
144+
TableName: sigMemberTableName,
145+
Key: {
146+
sigGroupId: { S: sigMemberUpdateRequest.sigGroupId },
147+
email: { S: sigMemberUpdateRequest.email },
148+
},
149+
ProjectionExpression: "updatedAt",
150+
});
151+
152+
try {
153+
const response = await dynamoClient.send(validatePutQuery);
154+
const item = response.Item;
155+
156+
if (!item || !item.updatedAt?.S) {
157+
throw new Error("Item not found or missing 'updatedAt'");
158+
}
159+
160+
if (item.updatedAt.S !== sigMemberUpdateRequest.updatedAt) {
161+
throw new DatabaseInsertError({
162+
message: "The member exists, but was updated by someone else!",
163+
});
164+
}
165+
} catch (e) {
166+
console.error("Validate DynamoDB get went wrong.", e);
167+
throw e;
168+
}
169+
}
170+
171+
export async function addMemberToSigEntra() {
172+
// uuid validation not implemented yet
133173
}

src/api/routes/siglead.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
SigMemberUpdateRecord,
1212
} from "common/types/siglead.js";
1313
import {
14-
addMemberToSig,
14+
addMemberToSigDynamo,
1515
fetchMemberRecords,
1616
fetchSigCounts,
1717
fetchSigDetail,
@@ -127,7 +127,7 @@ const sigleadRoutes: FastifyPluginAsync = async (fastify, _options) => {
127127
"/addMember",
128128
async (request, reply) => {
129129
try {
130-
await addMemberToSig(
130+
await addMemberToSigDynamo(
131131
genericConfig.SigleadDynamoSigMemberTableName,
132132
request.body,
133133
fastify.dynamoClient,

src/common/types/siglead.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ export type SigMemberUpdateRecord = {
3333
updatedAt: string;
3434
}
3535

36-
export type SigMemberUpdateRequest = {
37-
38-
}
39-
4036
export type DynamoDBItem = {
4137
Item: {
4238
[key: string]: {

src/common/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const reservedCharsRegex = /[:\/?#\[\]@!$&'()*+,;=]/g;
2929
* @returns {string} - The transformed organization name, ready for use as a URL.
3030
*/
3131
export function transformSigLeadToURI(org: string) {
32-
console.log(`org\t${org}`)
32+
// console.log(`org\t${org}`)
3333
org = org
3434
// change not reserved chars to spaces
3535
.trim()

src/ui/pages/siglead/ViewSigLead.page.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ export const AddMemberToSigPage: FC = () => {
219219
await api.post(`/api/v1/siglead/addMember`, data);
220220
}
221221

222+
async function testAddGroup() {
223+
await api.patch(
224+
`/api/v1/iam/groups/:e37a2420-1030-48da-9d17-f7e201b446e1`,
225+
{ add: ["d115c8cb-2520-4ba4-bc36-dd55af69c590"], remove: [] },
226+
);
227+
}
228+
222229
return (
223230
<AuthGuard
224231
resourceDef={{ service: "core", validRoles: [AppRoles.SIGLEAD_MANAGER] }}
@@ -252,6 +259,9 @@ export const AddMemberToSigPage: FC = () => {
252259
{/* <button type="submit" onSubmit={handleSubmit}>Submit</button> */}
253260
<button type="submit">Submit</button>
254261
</form>
262+
<button type="button" onClick={testAddGroup}>
263+
Test
264+
</button>
255265
</AuthGuard>
256266
);
257267
};

0 commit comments

Comments
 (0)