Skip to content

Commit

Permalink
MVPPPPPP
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-the-qa committed Oct 23, 2024
1 parent 66cc3ab commit 96923be
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 6 deletions.
43 changes: 41 additions & 2 deletions dist/public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
let userId = '';
let adpListResponse = null;
let adpListResponse = [];
function submitUserId() {
const userIdInput = document.getElementById('userId');
userId = userIdInput.value;
Expand Down Expand Up @@ -71,6 +71,8 @@ document.addEventListener('DOMContentLoaded', () => {
const senjaForm = document.getElementById('senjaForm');
const userIdInput = document.getElementById('userId');
const submitUserIdButton = document.getElementById('submitUserId');
const senjaApiKeyInput = document.getElementById('senjaApiKey');
const submitSenjaApiKeyButton = document.getElementById('submitSenjaApiKey');
const successBanner = document.getElementById('successBanner');
const errorBanner = document.getElementById('errorBanner');
submitUserIdButton.addEventListener('click', () => __awaiter(void 0, void 0, void 0, function* () {
Expand All @@ -91,9 +93,10 @@ document.addEventListener('DOMContentLoaded', () => {
body: JSON.stringify({ userId }),
});
if (!response.ok) {
throw new Error('Failed to fetch ADPList review');
throw new Error('Failed to fetch ADPList reviews');
}
adpListResponse = yield response.json();
successBanner.textContent = `Successfully fetched ${adpListResponse.length} reviews`;
successBanner.style.display = 'block';
userIdForm.style.display = 'none';
senjaForm.style.display = 'block';
Expand All @@ -106,4 +109,40 @@ document.addEventListener('DOMContentLoaded', () => {
submitUserIdButton.disabled = false;
}
}));
submitSenjaApiKeyButton.addEventListener('click', () => __awaiter(void 0, void 0, void 0, function* () {
const senjaApiKey = senjaApiKeyInput.value.trim();
if (!senjaApiKey) {
alert('Please enter a Senja API Key');
return;
}
submitSenjaApiKeyButton.disabled = true;
successBanner.style.display = 'none';
errorBanner.style.display = 'none';
try {
const response = yield fetch('/api/senja-testimonial', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
senjaApiKey,
adpListReviews: adpListResponse
}),
});
if (!response.ok) {
throw new Error('Failed to create Senja testimonials');
}
const results = yield response.json();
successBanner.textContent = `Successfully created ${results.length} testimonials`;
successBanner.style.display = 'block';
}
catch (error) {
console.error('Error:', error);
errorBanner.textContent = 'Failed to create testimonials. Please try again.';
errorBanner.style.display = 'block';
}
finally {
submitSenjaApiKeyButton.disabled = false;
}
}));
});
46 changes: 44 additions & 2 deletions dist/public/script.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let userId: string = '';
let adpListResponse: any = null;
let adpListResponse: any[] = [];

function submitUserId(): void {
const userIdInput = document.getElementById('userId') as HTMLInputElement;
Expand Down Expand Up @@ -64,6 +64,8 @@ document.addEventListener('DOMContentLoaded', () => {
const senjaForm = document.getElementById('senjaForm') as HTMLDivElement;
const userIdInput = document.getElementById('userId') as HTMLInputElement;
const submitUserIdButton = document.getElementById('submitUserId') as HTMLButtonElement;
const senjaApiKeyInput = document.getElementById('senjaApiKey') as HTMLInputElement;
const submitSenjaApiKeyButton = document.getElementById('submitSenjaApiKey') as HTMLButtonElement;
const successBanner = document.getElementById('successBanner') as HTMLDivElement;
const errorBanner = document.getElementById('errorBanner') as HTMLDivElement;

Expand All @@ -88,10 +90,11 @@ document.addEventListener('DOMContentLoaded', () => {
});

if (!response.ok) {
throw new Error('Failed to fetch ADPList review');
throw new Error('Failed to fetch ADPList reviews');
}

adpListResponse = await response.json();
successBanner.textContent = `Successfully fetched ${adpListResponse.length} reviews`;
successBanner.style.display = 'block';
userIdForm.style.display = 'none';
senjaForm.style.display = 'block';
Expand All @@ -102,4 +105,43 @@ document.addEventListener('DOMContentLoaded', () => {
submitUserIdButton.disabled = false;
}
});

submitSenjaApiKeyButton.addEventListener('click', async () => {
const senjaApiKey = senjaApiKeyInput.value.trim();
if (!senjaApiKey) {
alert('Please enter a Senja API Key');
return;
}

submitSenjaApiKeyButton.disabled = true;
successBanner.style.display = 'none';
errorBanner.style.display = 'none';

try {
const response = await fetch('/api/senja-testimonial', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
senjaApiKey,
adpListReviews: adpListResponse
}),
});

if (!response.ok) {
throw new Error('Failed to create Senja testimonials');
}

const results = await response.json();
successBanner.textContent = `Successfully created ${results.length} testimonials`;
successBanner.style.display = 'block';
} catch (error) {
console.error('Error:', error);
errorBanner.textContent = 'Failed to create testimonials. Please try again.';
errorBanner.style.display = 'block';
} finally {
submitSenjaApiKeyButton.disabled = false;
}
});
});
36 changes: 36 additions & 0 deletions dist/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,42 @@ app.post('/api/adplist-review', (req, res) => __awaiter(void 0, void 0, void 0,
}
}
}));
app.post('/api/senja-testimonial', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { senjaApiKey, adpListReviews } = req.body;
try {
const results = yield Promise.all(adpListReviews.map((review) => __awaiter(void 0, void 0, void 0, function* () {
const testimonialData = {
type: "text",
title: `Mentorship Call with ${review.mentor.name}`,
text: review.review,
rating: review.rating,
url: review.swag_image_url,
date: review.date_reviewed,
approved: true,
thumbnail_url: "",
customer_name: review.reviewed_by.name,
customer_company: review.reviewed_by.employer,
customer_avatar: review.reviewed_by.profile_photo_url,
};
const response = yield axios_1.default.post('https://api.senja.io/v1/testimonials', testimonialData, {
headers: {
'Authorization': `Bearer ${senjaApiKey}`,
'Content-Type': 'application/json',
},
});
return response.data;
})));
res.json(results);
}
catch (error) {
if (axios_1.default.isAxiosError(error)) {
res.status(500).json({ error: error.message });
}
else {
res.status(500).json({ error: 'An unexpected error occurred' });
}
}
}));
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
46 changes: 44 additions & 2 deletions src/public/script.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let userId: string = '';
let adpListResponse: any = null;
let adpListResponse: any[] = [];

function submitUserId(): void {
const userIdInput = document.getElementById('userId') as HTMLInputElement;
Expand Down Expand Up @@ -64,6 +64,8 @@ document.addEventListener('DOMContentLoaded', () => {
const senjaForm = document.getElementById('senjaForm') as HTMLDivElement;
const userIdInput = document.getElementById('userId') as HTMLInputElement;
const submitUserIdButton = document.getElementById('submitUserId') as HTMLButtonElement;
const senjaApiKeyInput = document.getElementById('senjaApiKey') as HTMLInputElement;
const submitSenjaApiKeyButton = document.getElementById('submitSenjaApiKey') as HTMLButtonElement;
const successBanner = document.getElementById('successBanner') as HTMLDivElement;
const errorBanner = document.getElementById('errorBanner') as HTMLDivElement;

Expand All @@ -88,10 +90,11 @@ document.addEventListener('DOMContentLoaded', () => {
});

if (!response.ok) {
throw new Error('Failed to fetch ADPList review');
throw new Error('Failed to fetch ADPList reviews');
}

adpListResponse = await response.json();
successBanner.textContent = `Successfully fetched ${adpListResponse.length} reviews`;
successBanner.style.display = 'block';
userIdForm.style.display = 'none';
senjaForm.style.display = 'block';
Expand All @@ -102,4 +105,43 @@ document.addEventListener('DOMContentLoaded', () => {
submitUserIdButton.disabled = false;
}
});

submitSenjaApiKeyButton.addEventListener('click', async () => {
const senjaApiKey = senjaApiKeyInput.value.trim();
if (!senjaApiKey) {
alert('Please enter a Senja API Key');
return;
}

submitSenjaApiKeyButton.disabled = true;
successBanner.style.display = 'none';
errorBanner.style.display = 'none';

try {
const response = await fetch('/api/senja-testimonial', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
senjaApiKey,
adpListReviews: adpListResponse
}),
});

if (!response.ok) {
throw new Error('Failed to create Senja testimonials');
}

const results = await response.json();
successBanner.textContent = `Successfully created ${results.length} testimonials`;
successBanner.style.display = 'block';
} catch (error) {
console.error('Error:', error);
errorBanner.textContent = 'Failed to create testimonials. Please try again.';
errorBanner.style.display = 'block';
} finally {
submitSenjaApiKeyButton.disabled = false;
}
});
});
44 changes: 44 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ interface ADPListReviewRequest {
userId: string;
}

interface SenjaTestimonialRequest {
senjaApiKey: string;
adpListReviews: any[];
}

app.post('/api/adplist-review', async (req: Request<{}, {}, ADPListReviewRequest>, res: Response) => {
const { userId } = req.body;

Expand All @@ -33,6 +38,45 @@ app.post('/api/adplist-review', async (req: Request<{}, {}, ADPListReviewRequest
}
});

app.post('/api/senja-testimonial', async (req: Request<{}, {}, SenjaTestimonialRequest>, res: Response) => {
const { senjaApiKey, adpListReviews } = req.body;

try {
const results = await Promise.all(adpListReviews.map(async (review) => {
const testimonialData = {
type: "text",
title: `Mentorship Call with ${review.mentor.name}`,
text: review.review,
rating: review.rating,
url: review.swag_image_url,
date: review.date_reviewed,
approved: true,
thumbnail_url: "",
customer_name: review.reviewed_by.name,
customer_company: review.reviewed_by.employer,
customer_avatar: review.reviewed_by.profile_photo_url,
};

const response = await axios.post('https://api.senja.io/v1/testimonials', testimonialData, {
headers: {
'Authorization': `Bearer ${senjaApiKey}`,
'Content-Type': 'application/json',
},
});

return response.data;
}));

res.json(results);
} catch (error) {
if (axios.isAxiosError(error)) {
res.status(500).json({ error: error.message });
} else {
res.status(500).json({ error: 'An unexpected error occurred' });
}
}
});

app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});

0 comments on commit 96923be

Please sign in to comment.