This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
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.
Merge pull request #29 from hurtigruten/feat/NEL-650/delete-quote
feat: delete quote
- Loading branch information
Showing
4 changed files
with
97 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { BOOKING_DOMAIN_URL } = process.env; | ||
|
||
export const deleteQuote = async (quoteId: string) => { | ||
const delete_ = (url: string) => | ||
fetch(url, { | ||
method: "DELETE", | ||
}) | ||
.then((resp) => { | ||
if (resp.status.toString()[0] !== "2") { | ||
throw new Error(`${resp.status} ${resp.statusText}`); | ||
} | ||
return resp; | ||
}) | ||
.then((resp) => resp.text()); | ||
|
||
const res = await delete_(`${BOOKING_DOMAIN_URL || ""}/Api/Quote/${quoteId}`); | ||
|
||
return res; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { deleteQuote } from "../../../api/quote"; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
if (req.method !== "GET") { | ||
res.status(405).json("Unsupported method"); | ||
return; | ||
} | ||
const { quoteId: quoteIdRaw } = req.query; | ||
const quoteId = Array.isArray(quoteIdRaw) ? quoteIdRaw[0] : quoteIdRaw; | ||
try { | ||
await deleteQuote(quoteId); | ||
res.status(200).json({ success: true }); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({ success: false }); | ||
} | ||
} |
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