From f270bd9b76970d8ae1e966e4c66b0879808100cf Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Tue, 7 Nov 2023 09:17:04 +0100 Subject: [PATCH] Migrated the links.ts controller --- controller/links.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/controller/links.ts b/controller/links.ts index 9503a7d..36372a1 100644 --- a/controller/links.ts +++ b/controller/links.ts @@ -1,16 +1,16 @@ -import {ShortenedLink} from "../models/ShortenedLink"; +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({shortenedId}, {_id: 0, __v: 0}); +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({shortenedId}); +export const getLinkObjectById = (shortenedId: string) => ShortenedLink.findOne({where: {shortenedId}}); /** * Shorts a new link @@ -18,14 +18,14 @@ export const getLinkObjectById = (shortenedId: string) => ShortenedLink.findOne( * @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) => +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}); +export const listLinksByUser = (clientId: number) => ShortenedLink.findAll({where: {clientId}}); /** Lists all created links from the database */ -export const listAllLinks = () => ShortenedLink.find({}, {_id: 0, __v: 0}); \ No newline at end of file +export const listAllLinks = () => ShortenedLink.findAll({}); \ No newline at end of file