Skip to content

Commit

Permalink
add timestamps on event creation (#13)
Browse files Browse the repository at this point in the history
* add timestamps on event creation

* fix tests

* fix 2
  • Loading branch information
devksingh4 authored Sep 3, 2024
1 parent 658edd1 commit 63b9d0c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppRoles, RunEnvironment } from "./roles.js";
import { allAppRoles, AppRoles, RunEnvironment } from "./roles.js";
import { OriginFunction } from "@fastify/cors";

// From @fastify/cors
Expand Down Expand Up @@ -37,11 +37,11 @@ const genericConfig: GenericConfigType = {
const environmentConfig: EnvironmentConfigType = {
dev: {
GroupRoleMapping: {
"48591dbc-cdcb-4544-9f63-e6b92b067e33": [AppRoles.EVENTS_MANAGER], // Infra Chairs
"940e4f9e-6891-4e28-9e29-148798495cdb": [AppRoles.EVENTS_MANAGER], // ACM Infra Team
"f8dfc4cf-456b-4da3-9053-f7fdeda5d5d6": [AppRoles.EVENTS_MANAGER], // Infra Leads
"0": [AppRoles.EVENTS_MANAGER], // Dummy Group for development only
"1": [AppRoles.PUBLIC], // Dummy Group for development only
"48591dbc-cdcb-4544-9f63-e6b92b067e33": allAppRoles, // Infra Chairs
"940e4f9e-6891-4e28-9e29-148798495cdb": allAppRoles, // ACM Infra Team
"f8dfc4cf-456b-4da3-9053-f7fdeda5d5d6": allAppRoles, // Infra Leads
"0": allAppRoles, // Dummy Group for development only
"1": [], // Dummy Group for development only
},
AzureRoleMapping: { AutonomousWriters: [AppRoles.EVENTS_MANAGER] },
ValidCorsOrigins: [
Expand All @@ -56,8 +56,8 @@ const environmentConfig: EnvironmentConfigType = {
},
prod: {
GroupRoleMapping: {
"48591dbc-cdcb-4544-9f63-e6b92b067e33": [AppRoles.EVENTS_MANAGER], // Infra Chairs
"ff49e948-4587-416b-8224-65147540d5fc": [AppRoles.EVENTS_MANAGER], // Officers
"48591dbc-cdcb-4544-9f63-e6b92b067e33": allAppRoles, // Infra Chairs
"ff49e948-4587-416b-8224-65147540d5fc": allAppRoles, // Officers
"ad81254b-4eeb-4c96-8191-3acdce9194b1": [AppRoles.EVENTS_MANAGER], // Exec
},
AzureRoleMapping: { AutonomousWriters: [AppRoles.EVENTS_MANAGER] },
Expand Down
4 changes: 3 additions & 1 deletion src/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ export const runEnvironments = ["dev", "prod"] as const;
export type RunEnvironment = (typeof runEnvironments)[number];
export enum AppRoles {
EVENTS_MANAGER = "manage:events",
PUBLIC = "public",
}
export const allAppRoles = Object.values(AppRoles).filter(
(value) => typeof value === "string",
);
14 changes: 9 additions & 5 deletions src/routes/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DynamoDBClient,
GetItemCommand,
PutItemCommand,
QueryCommand,
ScanCommand,
} from "@aws-sdk/client-dynamodb";
import { genericConfig } from "../config.js";
Expand Down Expand Up @@ -111,18 +112,21 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
Key: { id: { S: userProvidedId } },
}),
);
if (!response.Item) {
originalEvent = response.Item;
if (!originalEvent) {
throw new ValidationError({
message: `${userProvidedId} is not a valid event ID.`,
});
} else {
originalEvent = response.Item;
}
}
const entry = {
...request.body,
id: entryUUID,
createdBy: request.username,
createdAt: originalEvent
? originalEvent.createdAt || new Date().toISOString()
: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};
await dynamoClient.send(
new PutItemCommand({
Expand Down Expand Up @@ -189,9 +193,9 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
const id = request.params.id;
try {
const response = await dynamoClient.send(
new ScanCommand({
new QueryCommand({
TableName: genericConfig.DynamoTableName,
FilterExpression: "#id = :id",
KeyConditionExpression: "#id = :id",
ExpressionAttributeNames: {
"#id": "id",
},
Expand Down

0 comments on commit 63b9d0c

Please sign in to comment.