import {IShortenedLink, ShortenedLink} from "../models/ShortenedLink"; /** * Gets a link object from an id * @param shortenedId The link id (shortened) */ export const getLinkById = (shortenedId: string) => ShortenedLink.findOne({where: {shortenedId}}); /** * Gets the complete link object from an id * @param shortenedId The link id (shortened) */ export const getLinkObjectById = (shortenedId: string) => ShortenedLink.findOne({where: {shortenedId}}); /** * 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: string) => 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: string) => ShortenedLink.findAll({where: {clientId}}); /** Lists all created links from the database */ export const listAllLinks = () => ShortenedLink.findAll({});