Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] Tipagens lambda #231

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading