-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code and add slug to form data
- Loading branch information
1 parent
49e10b2
commit ca1e2b4
Showing
3 changed files
with
33 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
import FormData from "form-data" | ||
import CodedError from "../config/CodedError" | ||
|
||
export default function convertToFormata(json) { | ||
const formData = new FormData() | ||
try { | ||
const formData = new FormData() | ||
|
||
console.log(json) | ||
|
||
const append = (key, value) => { | ||
const keyIsUndefined = typeof value === "undefined" | ||
const valueIsUndefined = typeof value === "undefined" | ||
const valueIsNull = value === null || value === "null" | ||
|
||
if (keyIsUndefined || valueIsUndefined || valueIsNull) return | ||
|
||
for (const key in json) { | ||
if (typeof key !== "undefined" && typeof json?.[key] !== "undefined") { | ||
formData.append(key, json?.[key]) | ||
} | ||
|
||
for (const key in json) { | ||
console.log("key", key) | ||
console.log("value", json?.[key]) | ||
|
||
append(key, json?.[key]) | ||
} | ||
return formData | ||
} catch (error) { | ||
throw new CodedError(error, "CON1") | ||
} | ||
return formData | ||
} |