Skip to content

Commit

Permalink
fix: Refactor fetchData function to ensure it returns an array
Browse files Browse the repository at this point in the history
  • Loading branch information
iandebruin98 committed Oct 28, 2024
1 parent 51c9358 commit e5b14c9
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions apps/admin-server/src/pages/projects/[project]/duplicate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,43 @@ export default function ProjectDuplicate() {

async function fetchData( url: string) {
let response = await fetch(url) || [];
if (response.ok) {
let data = await response.json();

if (!Array.isArray(data)) {
return data;
}
return data.map((item) => {
if (item.deletedAt) {
return null;
}
delete item.projectId;
item.originalId = item.id;
delete item.id;
return item;
})
if (!response.ok) {
return [];
}

let data = await response.json();

if (!Array.isArray(data)) {
return [];
}
return data.map((item) => {
if (item.deletedAt) {
return null;
}
delete item.projectId;
item.originalId = item.id;
delete item.id;
return item;
})
}

type DuplicateData = {
areaId: number;
config: any;
emailConfig: any;
hostStatus: any;
name: string;
title: string;
widgets: any[];
tags: any[];
statuses: any[];
resources: any[];
resourceSettings: boolean;
};

async function duplicate(values: z.infer<typeof formSchema>) {
const duplicateData = {
const duplicateData: DuplicateData = {
areaId: data.areaId,
config: data.config,
emailConfig: data.emailConfig,
Expand Down

0 comments on commit e5b14c9

Please sign in to comment.