Skip to content

Commit

Permalink
feat: reverse links order in MyLinks Page (srm-kzilla#264)
Browse files Browse the repository at this point in the history
* chore: reverse link order

* now newest links now show first

* refact: update link order

* chore: resolve comments
  • Loading branch information
HarshPatel5940 authored Feb 21, 2024
1 parent 0e5f3d7 commit 3798f70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions api/controllers/link-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export const createLink = async (
const analyticsCode = generateRandomCode(5);
const linkId = generateRandomCode(12);

const database = await DatabaseService.getInstance()
.database!!.collection(Collections.LINKS)
const database = await DatabaseService.getInstance().database!!.collection(
Collections.LINKS
);

let result = await database
.find({
Expand All @@ -38,11 +39,7 @@ export const createLink = async (

if (result.length !== 0) {
if (!customCode) return createLink(longUrl, ipAddress);
result = await database
.find(
{ shortCode: shortCode }
)
.toArray();
result = await database.find({ shortCode: shortCode }).toArray();

if (result.length !== 0) throw CUSTOM_CODE_ALREADY_EXISTS;
return createLink(longUrl, ipAddress, customCode);
Expand Down Expand Up @@ -102,10 +99,11 @@ export const fetchLink = async (shortCode: string) => {
}

try {
if (result.longUrl.startsWith("https://"))
if (result.longUrl.startsWith("https://")) {
result.meta = await metaget.fetch(result.longUrl);
else
} else {
result.meta = await metaget.fetch("https://" + result.longUrl);
}
} catch (e) {
result.meta = {};
}
Expand Down Expand Up @@ -134,7 +132,9 @@ export const fetchMyLinks = async (linkIds: string[]) => {
linkId: 1,
timestamp: 1,
})
.sort({ timestamp: -1 })
.toArray();

if (result.length === 0) throw 404;
return result;
} catch (error) {
Expand Down Expand Up @@ -211,4 +211,4 @@ export const updateLink = async (
export const catchAllRoutes = async (req: Request, res: Response) => {
const html = await generatePageNotFound();
res.status(404).send(html as string);
}
};
2 changes: 1 addition & 1 deletion client/src/myLinksPage/MyLinks.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//Attaching my links API...
let dataset = [];
onMount(async () => {
dataset = (await fetchMyLinks()).links
dataset = (await fetchMyLinks()).links;
loading = false;
});
</script>
Expand Down

0 comments on commit 3798f70

Please sign in to comment.