From e3fba930d2e054925a9350f59c356ab40bed6e75 Mon Sep 17 00:00:00 2001 From: Spacelord Date: Fri, 31 Jan 2025 23:49:16 +0100 Subject: [PATCH] Remove/Deprecate parseIntOrUndefined --- src/helpers/prisma_helpers.ts | 4 ++-- src/routes/api/v1/alertContacts.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/helpers/prisma_helpers.ts b/src/helpers/prisma_helpers.ts index 0b26d70..6c8dd6b 100644 --- a/src/helpers/prisma_helpers.ts +++ b/src/helpers/prisma_helpers.ts @@ -12,11 +12,11 @@ export function parseDynamicSortBy(SortField: string, Order: string) { /** * Function to parse a string into a number or return undefined if it is not a number - * + * Deprecated since all empty strings in bodys are now undefined. This happens in api/v1 router * @export * @param {string || any} data * @returns {object} */ export function parseIntOrUndefined(data: any) { return isNaN(parseInt(data)) ? undefined : parseInt(data); -} \ No newline at end of file +} diff --git a/src/routes/api/v1/alertContacts.ts b/src/routes/api/v1/alertContacts.ts index de8c470..4aff399 100644 --- a/src/routes/api/v1/alertContacts.ts +++ b/src/routes/api/v1/alertContacts.ts @@ -1,7 +1,7 @@ import { Request, Response } from 'express'; import db, { handlePrismaError } from '../../../handlers/db.js'; // Database import log from '../../../handlers/log.js'; -import { parseIntOrUndefined, parseDynamicSortBy } from '../../../helpers/prisma_helpers.js'; +import { parseDynamicSortBy } from '../../../helpers/prisma_helpers.js'; import { schema_get, schema_post, schema_patch, schema_del } from './alertContacts_schema.js'; // MARK: GET alertContact @@ -22,11 +22,11 @@ async function get(req: Request, res: Response) { await db.alertContacts .findMany({ where: { - OR: [{ id: parseIntOrUndefined(value.id) }, { name: { search: value.search } }, { phone: { search: value.search } }, { comment: { search: value.search } }] + OR: [{ id: value.id }, { name: { search: value.search } }, { phone: { search: value.search } }, { comment: { search: value.search } }] }, orderBy: parseDynamicSortBy(value.sort.toString(), value.order.toString()), - skip: parseIntOrUndefined(value.skip), - take: parseIntOrUndefined(value.take) + skip: value.skip, + take: value.take }) .then((result) => { if (result.length !== 0) { @@ -41,7 +41,7 @@ async function get(req: Request, res: Response) { await db.alertContacts .count({ where: { - OR: [{ id: parseIntOrUndefined(value.id) }, { name: { search: value.search } }, { phone: { search: value.search } }, { comment: { search: value.search } }] + OR: [{ id: value.id }, { name: { search: value.search } }, { phone: { search: value.search } }, { comment: { search: value.search } }] }, orderBy: parseDynamicSortBy(value.sort.toString(), value.order.toString()) }) @@ -55,7 +55,7 @@ async function get(req: Request, res: Response) { // get all entrys log.api?.trace('get all entrys - without FullTextSearch'); await db.alertContacts - .findMany({ orderBy: parseDynamicSortBy(value.sort.toString(), value.order.toString()), take: parseIntOrUndefined(value.take), skip: parseIntOrUndefined(value.skip) }) + .findMany({ orderBy: parseDynamicSortBy(value.sort.toString(), value.order.toString()), take: value.take, skip: value.skip }) .then((result) => { if (result.length !== 0) { res.status(200).json(result);