Skip to content

Commit

Permalink
Merge pull request #9 from kandarppatel28/master
Browse files Browse the repository at this point in the history
Added hit rate feature #5
  • Loading branch information
bmusuko authored Oct 3, 2020
2 parents ba7d694 + 26a691c commit b64a175
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions models/Shortener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const ShortenerSchema = new mongoose.Schema({
password: {
type: String,
},
visitCount: {
type: Number
},
});

const Shortener =
Expand Down
6 changes: 6 additions & 0 deletions pages/api/short/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
if (!realLink) {
return responseGenerator(res, 404, "link not found");
}
//Increment visitCount
await Shortener.findOneAndUpdate(
{ generated_link: link },
{ visitCount: ( realLink.visitCount || 0 ) + 1 }
);

if (realLink["is_password"]) {
return responseGenerator(res, 200, "get link", {
is_password: true,
Expand Down

1 comment on commit b64a175

@vercel
Copy link

@vercel vercel bot commented on b64a175 Oct 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.