Skip to content

Commit

Permalink
Refactor; add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalushin committed Aug 20, 2021
1 parent 1ccd2c2 commit f5140a2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { APIGatewayProxyResult } from "aws-lambda";
import accessControlHeaders from "./accessControlHeaders.json";

/**
* An utility function that simplifies the instantiation of APIGatewayProxyResult.
* To be used in lambda functions triggered by API Gateway.
*/
export const formAPIGatewayProxyResult = (statusCode: number, body: any = ""): APIGatewayProxyResult => {
return {
statusCode,
Expand Down
6 changes: 2 additions & 4 deletions rolls/rolls-crud/src/storage/RollsStorage.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import MockDate from "mockdate";
import { createDescendantRollInput, RollsStorage } from "./RollsStorage";
import { createLocalTable, setEnvironmentVariablesForDynamoDBLocalTesting } from "../test-support/commonForLocalDynamoDBServiceTests";
import { RollReference } from "./RollReference";
import { createRollInputSample1, userSample1 } from "../test-support/objectSamples";
import MockDate from "mockdate";

let storage: RollsStorage;

Expand Down Expand Up @@ -212,7 +212,5 @@ describe("Create a descendant roll", () => {
expect(descendantRef.version).toBe(descendantRefReceived.version);
});

test("without Ref (e.g. generate new Ref) and read the new roll", async () => {
// console.log();
});
test.todo("without Ref (e.g. generate new Ref) and read the new roll");
});
5 changes: 5 additions & 0 deletions rolls/rolls-crud/src/storage/RollsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const conditionPkSkExists = [
{ exists: false, attr: "sk" },
];

/**
* A helper class that abstracts all operations with database.
* Saving / reading all roll data must be done using this class.
* Detailed explanation of terminology and roll operations is in rolls/README.md
*/
export class RollsStorage {
protected rollsTable: Table;
protected rollEntity: Entity<{}>;
Expand Down
8 changes: 7 additions & 1 deletion rolls/rolls-crud/src/storage/createRollEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const createRollEntity = (table: Table) => {
user: { required: true, type: "map" },
previousDepartmentInfo: { required: true, type: "map" },
registrationDate: { required: true, type: "string" },
physicalId: { partitionKey: "gs1", required: false, type: "string" }, // TODO required should be true
physicalId: { partitionKey: "gs1", required: false, type: "string" },
deletionMark: { required: true, type: "boolean" },
quality: { required: false, type: "map" },
totalLength: { required: true, type: "number" },
Expand All @@ -27,6 +27,12 @@ export const createRollEntity = (table: Table) => {
});
};

/**
* Returns a string containing first 10 characters of a string-encoded date,
* that correspond to a combination of year, month and day (ie. without time).
* Can be used for grouping items by date
* @param UTCDateString - ISO 8601 date
*/
export const truncateDate = (UTCDateString: string) => {
if (UTCDateString.length != 24) {
throw new Error("Incorrect date - expected UTC string");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CreateTableCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb";
import KSUID from "ksuid";

const LOCAL_REGION = process.env.DYNAMODB_TEST_REGION ?? "eu-west-1"; // doesn't matter for local DynamoDB, it just needs to be set
const LOCAL_REGION = process.env.DYNAMODB_TEST_REGION ?? "eu-west-1";
const LOCAL_ENDPOINT = process.env.DYNAMODB_TEST_URL ?? "http://localhost:8000";

export const createLocalTable = async () => {
Expand Down

0 comments on commit f5140a2

Please sign in to comment.