testimonial-npm
Version:
A simple plug-and-play Testimonial Manager NPM package
198 lines (174 loc) • 4.97 kB
JavaScript
const BASE_URL = "https://testimonial-m.onrender.com/api/npm/v1";
export function connectToTestimonialsDB(passcode, passkey) {
if (!passcode || !passkey) {
throw new Error("Passcode and Passkey are required to connect.");
}
console.log(passcode, passkey);
return {
addReview: async (data) => {
const res = await fetch(
`${BASE_URL}/add-review/5627e8cd1a4ac5b71d31e?passkey=08a74dc3-9205-da65-0f27c7446b8c`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ ...data, passcode, passkey }),
}
);
return res.json();
},
getReview: async (reviewerEmail) => {
const res = await fetch(
`${BASE_URL}/get-review?passcode=${passcode}&reviewerEmail=${reviewerEmail}&passkey=${passkey}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
return res.json();
},
getAllReviews: async () => {
const res = await fetch(
`${BASE_URL}/get-all-reviews/${passcode}?passkey=${passkey}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
return res.json();
},
reportSus: async (data) => {
const res = await fetch(
`${BASE_URL}/report-sus/${passcode}?passkey=${passkey}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ ...data, passcode, passkey }),
}
);
return res.json();
},
normalReport: async (data) => {
const res = await fetch(
`${BASE_URL}/normal-report/${passcode}?passkey=${passkey}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ ...data, passcode, passkey }),
}
);
return res.json();
},
getAnalyticsOfTestimonialForTheProject: async () => {
const res = await fetch(
`${BASE_URL}/get-analytics/${passcode}?passkey=${passkey}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
return res.json();
},
getTopReviews: async () => {
const res = await fetch(
`${BASE_URL}/get-top-reviews/${passcode}?passkey=${passkey}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
return res.json();
},
getSusReviews: async () => {
const res = await fetch(
`${BASE_URL}/get-sus-reviews/${passcode}?passkey=${encodeURIComponent(
passkey
)}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
return res.json();
},
getBadReviews: async () => {
const res = await fetch(
`${BASE_URL}/get-bad-reviews/${passcode}?passkey=${encodeURIComponent(
passkey
)}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
return res.json();
},
getReviewsByRating: async (rating) => {
const res = await fetch(
`${BASE_URL}/get-reviews-by-rating?passcode=${passcode}&rating=${rating}&passkey=${passkey}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
return res.json();
},
deleteReview: async (data) => {
const res = await fetch(
`${BASE_URL}/delete-review/${passcode}?passkey=${passkey}`,
{
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ ...data, passcode, passkey }),
}
);
return res.json();
},
editReview: async (data) => {
const res = await fetch(
`${BASE_URL}/edit-review/${passcode}?passkey=${passkey}`,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ ...data, passcode, passkey }),
}
);
return res.json();
},
getProjectDetails: async () => {
const res = await fetch(
`${BASE_URL}/get-project-details/${passcode}?passkey=${passkey}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
return res.json();
},
};
}