From ee9e2ba257f20d152beb39c71f924b6ab0ed21f7 Mon Sep 17 00:00:00 2001 From: Stuart Long Chay Boon Date: Wed, 12 Oct 2022 16:15:44 +0800 Subject: [PATCH] [offers][chore]remove edit token when return single profile --- .../src/server/router/offers-profile-router.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/portal/src/server/router/offers-profile-router.ts b/apps/portal/src/server/router/offers-profile-router.ts index 92b53f24..5d673235 100644 --- a/apps/portal/src/server/router/offers-profile-router.ts +++ b/apps/portal/src/server/router/offers-profile-router.ts @@ -3,7 +3,8 @@ import { z } from 'zod'; import { Prisma } from '@prisma/client'; import { createRouter } from './context'; -import type { offersProfile } from '../../types/offers-profile'; + +import type { offersProfile } from '~/types/offers-profile'; const valuation = z.object({ currency: z.string(), @@ -65,6 +66,16 @@ function computeIsEditable( } } +function exclude>( + profile: WithIsEditable, + ...keys: Array +): Omit, Key> { + for (const key of keys) { + delete profile[key] + } + return profile +} + export const offersProfileRouter = createRouter() .query('listOne', { input: z.object({ @@ -117,7 +128,7 @@ export const offersProfileRouter = createRouter() } }); - return result ? computeIsEditable(result, input.token) : result; + return result ? exclude(computeIsEditable(result, input.token), 'editToken') : result; }, }) .mutation('create', {