porridger/front/utils/addFetchApiRoute.sh
dm1sh 0218cdced5
Code styling
Added brackets for const lambdas
Converted const lambdas with multiple instructions to functions
2023-07-15 12:55:25 +03:00

50 lines
850 B
Bash

NAME=${1:-Route}
NAME=${NAME^}
mkdir -p src/api/${NAME,}
cat > src/api/${NAME,}/index.ts << EOF
import { API_URL } from '../../config'
import { ${NAME}Response, ${NAME} } from './types'
const initial${NAME}: ${NAME} = {}
const compose${NAME}URL = () => (
API_URL + '/${NAME,}?'
)
const process${NAME} = (data: ${NAME}Response): ${NAME} => {
return data
}
export { initial${NAME}, compose${NAME}URL, process${NAME} }
EOF
cat > src/api/${NAME,}/types.ts << EOF
import { isObject } from '../../utils/types'
type ${NAME}Response = {
}
const is${NAME}Response = (obj: unknown): obj is ${NAME}Response => (
isObject(obj, {
})
)
type ${NAME} = {
}
const is${NAME} = (obj: unknown): obj is ${NAME} => (
isObject(obj, {
})
)
export type { ${NAME}Response, ${NAME} }
export { is${NAME}Response, is${NAME} }
EOF