Function onRequestPost
has 104 lines of code (exceeds 25 allowed). Consider refactoring.
export const onRequestPost: PagesFunction<Env> = async function (context) {
const headers = context.request.headers
const input: CreateUrlFormData = convertFormDataToJson(await context.request.formData()) as CreateUrlFormData
const requestDetails = {
short: input.short,
Function onRequestPost
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
export const onRequestPost: PagesFunction<Env> = async function (context) {
const headers = context.request.headers
const input: CreateUrlFormData = convertFormDataToJson(await context.request.formData()) as CreateUrlFormData
const requestDetails = {
short: input.short,
Function onRequestDelete
has 62 lines of code (exceeds 25 allowed). Consider refactoring.
export const onRequestDelete: PagesFunction<Env> = async function (context) {
const headers = context.request.headers
const input: DeleteUrlFormData = convertFormDataToJson(await context.request.formData()) as DeleteUrlFormData
const requestDetails = {
short: input.short,
Function setupDataTable
has 50 lines of code (exceeds 25 allowed). Consider refactoring.
const setupDataTable = () => {
listTable = $('#list').DataTable({
ajax: 'url',
columns: [{ data: 's' }, { data: 'l' }, { data: 'c' }],
columnDefs: [
Function getUrls
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
export const getUrls = async function (
context: any,
orderBy?: object,
limit?: number,
offset?: number
Identical blocks of code found in 2 locations. Consider refactoring.
} catch (err) {
output = JSON.stringify({
action: 'create',
status: 'error',
message: 'Unable to add Short URL',
Identical blocks of code found in 2 locations. Consider refactoring.
} else {
output = JSON.stringify({
action: 'create',
status: 'error',
message: 'Unable to add Short URL',
Identical blocks of code found in 2 locations. Consider refactoring.
} else {
output = JSON.stringify({
action: 'delete',
status: 'error',
message: 'Unable to delete Short URL',
Identical blocks of code found in 2 locations. Consider refactoring.
} catch (err) {
output = JSON.stringify({
action: 'delete',
status: 'error',
message: 'Unable to delete Short URL',
Similar blocks of code found in 5 locations. Consider refactoring.
if (requestDetails.short.length < 1 || !isValidShortCode(requestDetails.short)) {
return new Response(JSON.stringify({ action: 'delete', status: 'error', message: 'Insufficient data supplied' }), {
status: 400,
headers: DEFAULT_RESPONSE_HEADERS
})
Similar blocks of code found in 5 locations. Consider refactoring.
if (!isValidShortCode(requestDetails.short)) {
return new Response(
JSON.stringify({
action: 'create',
status: 'error',
Similar blocks of code found in 5 locations. Consider refactoring.
if (shortRow === null) {
return new Response(
JSON.stringify({
action: 'delete',
status: 'error',
Similar blocks of code found in 5 locations. Consider refactoring.
if (requestDetails.long.length < 1) {
return new Response(JSON.stringify({ action: 'create', status: 'error', message: 'Insufficient data supplied' }), {
status: 400,
headers: DEFAULT_RESPONSE_HEADERS
})
Similar blocks of code found in 5 locations. Consider refactoring.
if (!isValidUrl(requestDetails.long)) {
return new Response(
JSON.stringify({
action: 'create',
status: 'error',
Avoid too many return
statements within this function.
return new Response(output, {
status: returnStatus,
headers: DEFAULT_RESPONSE_HEADERS
})
Function setupDataTable
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
const setupDataTable = () => {
listTable = $('#list').DataTable({
ajax: 'url',
columns: [{ data: 's' }, { data: 'l' }, { data: 'c' }],
columnDefs: [
Function onRequestDelete
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
export const onRequestDelete: PagesFunction<Env> = async function (context) {
const headers = context.request.headers
const input: DeleteUrlFormData = convertFormDataToJson(await context.request.formData()) as DeleteUrlFormData
const requestDetails = {
short: input.short,