From cbd5c8d25a690d1f49db8dd4c473c347276e1ffb Mon Sep 17 00:00:00 2001 From: Maksim Sitnikov Date: Fri, 1 Mar 2024 10:36:56 +0300 Subject: [PATCH] Add yadocs to file connections (#82) --- src/db/models/new/entry/types.ts | 1 + .../entry/actions/copy-to-workbook.ts | 7 +------ src/utils/utils.ts | 20 ++++++++++++------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/db/models/new/entry/types.ts b/src/db/models/new/entry/types.ts index ac571403..8060aaab 100644 --- a/src/db/models/new/entry/types.ts +++ b/src/db/models/new/entry/types.ts @@ -12,5 +12,6 @@ export enum EntryScope { export enum EntryType { File = 'file', GsheetsV2 = 'gsheets_v2', + YaDocs = 'yadocs', // types can be added as needed } diff --git a/src/services/entry/actions/copy-to-workbook.ts b/src/services/entry/actions/copy-to-workbook.ts index 96342473..aa6d8a9b 100644 --- a/src/services/entry/actions/copy-to-workbook.ts +++ b/src/services/entry/actions/copy-to-workbook.ts @@ -3,7 +3,6 @@ import {AppError} from '@gravity-ui/nodekit'; import {getId} from '../../../db'; import {Entry, EntryColumn} from '../../../db/models/new/entry'; -import {EntryScope, EntryType} from '../../../db/models/new/entry/types'; import {JoinedEntryRevision} from '../../../db/presentations/joined-entry-revision'; import {WorkbookModel} from '../../../db/models/new/workbook'; import {CTX} from '../../../types/models'; @@ -58,8 +57,6 @@ export const validateParams = makeSchemaValidator({ }, }); -const fileConnectionTypes: string[] = [EntryType.File, EntryType.GsheetsV2]; - export const copyToWorkbook = async (ctx: CTX, params: Params) => { const { entryIds, @@ -147,9 +144,7 @@ export const copyToWorkbook = async (ctx: CTX, params: Params) => { } } - const isFileConnection = - joinedEntryRevision.scope === EntryScope.Connection && - fileConnectionTypes.includes(joinedEntryRevision.type); + const isFileConnection = Utils.isFileConnection(joinedEntryRevision); if (isFileConnection) { throw new AppError( diff --git a/src/utils/utils.ts b/src/utils/utils.ts index eb517a86..5c88be86 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -5,7 +5,6 @@ import {EntryScope, USAPIResponse} from '../types/models'; import {ID_VARIABLES, CODING_BASE, TRUE_FLAGS, COPY_START, COPY_END} from '../const'; -import type {Entry} from '../db/models/new/entry'; import {EntryScope as EntryScopeEnum, EntryType} from '../db/models/new/entry/types'; const PROFILES: { @@ -351,14 +350,21 @@ export class Utils { .join(''); } - static checkFileConnectionsExistence(entries: Entry[]) { - const fileConnectionTypes: string[] = [EntryType.File, EntryType.GsheetsV2]; + static isFileConnection(entry: {scope: Nullable; type: string}) { + const fileConnectionTypes: string[] = [ + EntryType.File, + EntryType.GsheetsV2, + EntryType.YaDocs, + ]; + return ( + entry.scope === EntryScopeEnum.Connection && fileConnectionTypes.includes(entry.type) + ); + } + + static checkFileConnectionsExistence(entries: {scope: Nullable; type: string}[]) { return entries.some((entry) => { - return ( - entry.scope === EntryScopeEnum.Connection && - fileConnectionTypes.includes(entry.type) - ); + return Utils.isFileConnection(entry); }); }