Skip to content

Commit

Permalink
refactor: 🏷️ Update package version and refactor lambda handler (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofeliponi authored Feb 29, 2024
1 parent 73e5f0d commit 830b5cd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adapcon-utils-js",
"version": "1.1.7",
"version": "1.1.8",
"description": "Utils library for Javascript",
"keywords": [],
"author": {
Expand Down
13 changes: 6 additions & 7 deletions src/lambda/crudHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import { lambdaGetParameters } from './lambdaGetParameters'
import { error } from '../error'
import { getDefaultResponse, HttpNames } from '../http'
import { CrudInputParams } from '../'
import type { APIGatewayEvent } from 'aws-lambda/trigger/api-gateway-proxy'

export const lambdaCrudHandler = (
event: APIGatewayEvent,
event: any,
customParameters: {[key: string]: string} = {}
): CrudInputParams => {
return switchMethod(event, customParameters)
}

const switchMethod = (event: APIGatewayEvent, customParameters): CrudInputParams => {
const switchMethod = (event: any, customParameters): CrudInputParams => {
const { httpMethod } = event

switch (httpMethod) {
Expand All @@ -35,7 +34,7 @@ const switchMethod = (event: APIGatewayEvent, customParameters): CrudInputParams
}
}

const getEvent = (event: APIGatewayEvent, customParameters): CrudInputParams => {
const getEvent = (event: any, customParameters): CrudInputParams => {
const parameters = lambdaGetParameters(event,
{
sort: 'headers',
Expand All @@ -61,7 +60,7 @@ const getEvent = (event: APIGatewayEvent, customParameters): CrudInputParams =>
}
}

const postEvent = (event: APIGatewayEvent, customParameters): CrudInputParams => {
const postEvent = (event: any, customParameters): CrudInputParams => {
const parameters: {body?: string} = lambdaGetParameters(event, {
body: 'body'

Expand All @@ -78,7 +77,7 @@ const postEvent = (event: APIGatewayEvent, customParameters): CrudInputParams =>
}
}

const putEvent = (event: APIGatewayEvent, customParameters): CrudInputParams => {
const putEvent = (event: any, customParameters): CrudInputParams => {
const parameters: {body?: string} = lambdaGetParameters(event,
{
body: 'body'
Expand All @@ -96,7 +95,7 @@ const putEvent = (event: APIGatewayEvent, customParameters): CrudInputParams =>
}
}

const deleteEvent = (event: APIGatewayEvent, customParameters): CrudInputParams => {
const deleteEvent = (event: any, customParameters): CrudInputParams => {
const parameters = lambdaGetParameters(event,
{

Expand Down
5 changes: 2 additions & 3 deletions src/lambda/lambdaResponses.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type { ProxyResult } from 'aws-lambda/trigger/api-gateway-proxy'
import { isNumber } from '../number'
import { objToStr } from '../object'
import type { Error, Headers } from './interfaces'

export const lambdaResp = (statusCode: number, body?: object | string, headers?: Headers): ProxyResult => ({
export const lambdaResp = (statusCode: number, body?: object | string, headers?: Headers) => ({
statusCode,
...(body ? { body: objToStr(body) } : { body: '' }),
...(headers ? { headers } : null)
})

export const lambdaRespError = (err: Error): ProxyResult => {
export const lambdaRespError = (err: Error) => {
err.statusCode = err.status ?? err.statusCode
err.message = err.error ?? err.message

Expand Down

0 comments on commit 830b5cd

Please sign in to comment.