Created the link controller
This commit is contained in:
parent
1fdf9c84f6
commit
f018392067
25
controller/links.ts
Normal file
25
controller/links.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import {ShortenedLink} from "../models/ShortenedLink";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a link object from an id
|
||||||
|
* @param shortenedId The link id (shortened)
|
||||||
|
*/
|
||||||
|
export const getLinkById = (shortenedId: string) => ShortenedLink.findOne({shortenedId: shortenedId}, {_id: 0, __v: 0});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shorts a new link
|
||||||
|
* @param originalUrl The url to short
|
||||||
|
* @param shortenedId The custom id of the link (optional)
|
||||||
|
* @param clientId The client id of the user that created the link
|
||||||
|
*/
|
||||||
|
export const shortLink = (originalUrl: string, shortenedId: string | undefined, clientId: Number) =>
|
||||||
|
ShortenedLink.create({originalUrl, shortenedId, clientId});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists all links created by a specific user
|
||||||
|
* @param clientId The user to get the links from
|
||||||
|
*/
|
||||||
|
export const listLinksByUser = (clientId: Number) => ShortenedLink.find({clientId}, {_id: 0, __v: 0});
|
||||||
|
|
||||||
|
/** Lists all created links from the database */
|
||||||
|
export const listAllLinks = () => ShortenedLink.find({}, {_id: 0, __v: 0});
|
Loading…
x
Reference in New Issue
Block a user