From 0909c60fe06e5ce59b2a87a8582fed60933772c5 Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Wed, 8 Nov 2023 15:37:50 +0100 Subject: [PATCH] Remove unused code --- src/back/routes/common/form.ts | 54 ---------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 src/back/routes/common/form.ts diff --git a/src/back/routes/common/form.ts b/src/back/routes/common/form.ts deleted file mode 100644 index c961328..0000000 --- a/src/back/routes/common/form.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { BaseContext } from "koa"; -import { hasShape, is, predicates } from "@sealcode/ts-predicates"; -import { Collection, Errors } from "sealious"; -import ItemFields from "sealious/@types/src/chip-types/collection-item-body"; - -export interface CollectionTiedFormData { - values: Partial<{ [field in keyof ItemFields]: string }>; - errors?: Errors.FieldsError; -} - -export interface FormFields { - values: Partial<{ [field in Fields]: string }>; - errors?: Partial<{ [field in Fields]: string }>; -} - -export function formHasAllFields( - ctx: BaseContext, - fields: Fields, - obj: unknown -): obj is { [field in Fields[number]]: string } { - const valid = - is(obj, predicates.object) && - hasShape( - Object.fromEntries(fields.map((field) => [field, predicates.string])), - obj - ); - if (!valid) { - ctx.status = 422; - if (is(obj, predicates.object)) { - ctx.body = `Missing params: ${fields - .filter((field) => !Object.keys(obj).includes(field)) - .join(", ")}`; - } - } - return valid; -} - -export function formHasSomeFields( - ctx: BaseContext, - fields: Fields, - obj: unknown -): obj is Partial<{ [field in Fields[number]]: string }> { - const valid = - is(obj, predicates.object) && - hasShape( - Object.fromEntries(fields.map((field) => [field, predicates.string])), - obj - ); - if (!valid) { - ctx.status = 422; - ctx.body = "Wrong type of params, expected string or undefined"; - } - return valid; -}