-
Notifications
You must be signed in to change notification settings - Fork 264
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 #942 from hngprojects/layobright
Layobright
- Loading branch information
Showing
13 changed files
with
1,113 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
"use server"; | ||
|
||
import axios from "axios"; | ||
|
||
import { auth } from "~/lib/auth"; | ||
|
||
const apiUrl = process.env.API_URL; | ||
|
||
interface Properties { | ||
question: string; | ||
answer: string; | ||
category: string; | ||
} | ||
|
||
interface UpdateProperties { | ||
question: string; | ||
answer: string; | ||
category: string; | ||
} | ||
|
||
export const CreateFaqs = async (payload: Properties) => { | ||
// | ||
try { | ||
const session = await auth(); | ||
|
||
const response = await axios.post(`${apiUrl}/api/v1/faqs`, payload, { | ||
headers: { | ||
Authorization: `Bearer ${session?.access_token}`, | ||
}, | ||
}); | ||
|
||
return { | ||
data: response.data, | ||
status: response.status, | ||
}; | ||
} catch (error) { | ||
return axios.isAxiosError(error) && error.response | ||
? { | ||
error: error.response.data.message || "Unable to Create FAQS", | ||
status: error.response.status, | ||
} | ||
: { | ||
error: "An unexpected error occurred.", | ||
}; | ||
} | ||
}; | ||
|
||
export const UpdateFaqs = async (payload: UpdateProperties, id: string) => { | ||
// | ||
try { | ||
const session = await auth(); | ||
|
||
const response = await axios.put(`${apiUrl}/api/v1/faqs/${id}`, payload, { | ||
headers: { | ||
Authorization: `Bearer ${session?.access_token}`, | ||
}, | ||
}); | ||
|
||
return { | ||
data: response.data, | ||
status: response.status, | ||
}; | ||
} catch (error) { | ||
return axios.isAxiosError(error) && error.response | ||
? { | ||
error: error.response.data.message || "Unable to Create FAQS", | ||
status: error.response.status, | ||
} | ||
: { | ||
error: "An unexpected error occurred.", | ||
}; | ||
} | ||
}; | ||
|
||
export const DeleteFaqs = async (id: string) => { | ||
// | ||
try { | ||
const session = await auth(); | ||
|
||
const response = await axios.delete(`${apiUrl}/api/v1/faqs/${id}`, { | ||
headers: { | ||
Authorization: `Bearer ${session?.access_token}`, | ||
}, | ||
}); | ||
|
||
return { | ||
message: response.data.message, | ||
status: response.status, | ||
}; | ||
} catch (error) { | ||
return axios.isAxiosError(error) && error.response | ||
? { | ||
error: error.response.data.message || "Unable to Create FAQS", | ||
status: error.response.status, | ||
} | ||
: { | ||
error: "An unexpected error occurred.", | ||
}; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.