Created the link controller

This commit is contained in:
Mathias Wagner 2022-09-09 15:06:17 +02:00
parent 1fdf9c84f6
commit f018392067
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

25
controller/links.ts Normal file
View 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});