Skip to content

Commit

Permalink
upgrade all node modules and apply prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
marcgreenstock committed Jul 30, 2021
1 parent 1237201 commit 269c83c
Show file tree
Hide file tree
Showing 48 changed files with 18,048 additions and 21,194 deletions.
17 changes: 10 additions & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
"project": [
"**/tsconfig.json"
]
},
"plugins": [
"@typescript-eslint/eslint-plugin",
"@typescript-eslint",
"prettier",
"jest"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-namespace": "off"
"@typescript-eslint/no-namespace": "off",
"prettier/prettier": 2
}
}
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 80
}
78 changes: 45 additions & 33 deletions example/todos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ import * as yup from 'yup'
class UUIDValue implements AuroraDataAPI.CustomValue {
private value: string

constructor (value: string) {
constructor(value: string) {
this.value = value
}

toSqlParameter (): AuroraDataAPI.SqlParameter {
toSqlParameter(): AuroraDataAPI.SqlParameter {
return {
typeHint: 'uuid',
value: {
stringValue: this.value
}
stringValue: this.value,
},
}
}
}

interface Todo {
id: string;
name: string;
completedAt: Date;
createdAt: Date;
updatedAt: Date;
id: string
name: string
completedAt: Date
createdAt: Date
updatedAt: Date
}

const dataAPI = new AuroraDataAPI({
Expand All @@ -36,11 +36,13 @@ const dataAPI = new AuroraDataAPI({
database: process.env.DATA_API_DATABASE_NAME,
credentials: {
accessKeyId: 'example',
secretAccessKey: 'example'
}
secretAccessKey: 'example',
},
})

const parseEventBody = (event: AWSLambda.APIGatewayEvent): { [key: string]: unknown } => {
const parseEventBody = (
event: AWSLambda.APIGatewayEvent
): { [key: string]: unknown } => {
if (event.body === null) {
throw new createError.BadRequest('JSON body is required in request')
}
Expand All @@ -64,16 +66,17 @@ const handleError = (error: Error): AWSLambda.APIGatewayProxyResult => {
statusCode: 400,
body: JSON.stringify({
message: error.message,
errors: error.errors
})
errors: error.errors,
}),
}
}
const statusCode = error instanceof createError.HttpError ? error.statusCode : 500
const statusCode =
error instanceof createError.HttpError ? error.statusCode : 500
return {
statusCode,
body: JSON.stringify({
message: error.message
})
message: error.message,
}),
}
}

Expand All @@ -90,10 +93,12 @@ const getTodo = async (id: string): Promise<Todo> => {

export const list: AWSLambda.APIGatewayProxyHandler = async () => {
try {
const { rows } = await dataAPI.query<Todo>('SELECT * FROM "todos" ORDER BY "createdAt" ASC')
const { rows } = await dataAPI.query<Todo>(
'SELECT * FROM "todos" ORDER BY "createdAt" ASC'
)
return {
statusCode: 200,
body: JSON.stringify(rows)
body: JSON.stringify(rows),
}
} catch (error) {
return handleError(error)
Expand All @@ -105,7 +110,7 @@ export const get: AWSLambda.APIGatewayProxyHandler = async (event) => {
const todo = await getTodo(parseEventId(event))
return {
statusCode: 200,
body: JSON.stringify(todo)
body: JSON.stringify(todo),
}
} catch (error) {
return handleError(error)
Expand All @@ -114,10 +119,12 @@ export const get: AWSLambda.APIGatewayProxyHandler = async (event) => {

export const create: AWSLambda.APIGatewayProxyHandler = async (event) => {
try {
const { name, completedAt } = yup.object({
name: yup.string().required(),
completedAt: yup.date().nullable()
}).validateSync(parseEventBody(event))
const { name, completedAt } = yup
.object({
name: yup.string().required(),
completedAt: yup.date().nullable(),
})
.validateSync(parseEventBody(event))
const { rows } = await dataAPI.query<Todo>(
'INSERT INTO "todos" ("name", "completedAt") VALUES (:name, :completedAt) RETURNING *',
{ name, completedAt }
Expand All @@ -127,7 +134,7 @@ export const create: AWSLambda.APIGatewayProxyHandler = async (event) => {
}
return {
statusCode: 201,
body: JSON.stringify(rows[0])
body: JSON.stringify(rows[0]),
}
} catch (error) {
return handleError(error)
Expand All @@ -137,11 +144,14 @@ export const create: AWSLambda.APIGatewayProxyHandler = async (event) => {
export const update: AWSLambda.APIGatewayProxyHandler = async (event) => {
try {
const todo = await getTodo(parseEventId(event))
const { name, completedAt } = yup.object({
name: yup.string().default(todo.name),
completedAt: yup.date().nullable().default(todo.completedAt)
}).validateSync(parseEventBody(event))
const { rows } = await dataAPI.query<Todo>(`
const { name, completedAt } = yup
.object({
name: yup.string().default(todo.name),
completedAt: yup.date().nullable().default(todo.completedAt),
})
.validateSync(parseEventBody(event))
const { rows } = await dataAPI.query<Todo>(
`
UPDATE "todos"
SET
"name" = :name,
Expand All @@ -157,7 +167,7 @@ export const update: AWSLambda.APIGatewayProxyHandler = async (event) => {
}
return {
statusCode: 200,
body: JSON.stringify(rows[0])
body: JSON.stringify(rows[0]),
}
} catch (error) {
return handleError(error)
Expand All @@ -167,10 +177,12 @@ export const update: AWSLambda.APIGatewayProxyHandler = async (event) => {
export const remove: AWSLambda.APIGatewayProxyHandler = async (event) => {
try {
const todo = await getTodo(parseEventId(event))
await dataAPI.query('DELETE FROM todos WHERE id = :id', { id: new UUIDValue(todo.id) })
await dataAPI.query('DELETE FROM todos WHERE id = :id', {
id: new UUIDValue(todo.id),
})
return {
statusCode: 204,
body: ''
body: '',
}
} catch (error) {
return handleError(error)
Expand Down
Loading

0 comments on commit 269c83c

Please sign in to comment.