feat: duplicate REST/GraphQL collections (#4211)
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com> Co-authored-by: nivedin <nivedinp@gmail.com>
This commit is contained in:
@@ -21,7 +21,11 @@ import {
|
||||
TEAM_MEMBER_NOT_FOUND,
|
||||
} from '../errors';
|
||||
import { PubSubService } from '../pubsub/pubsub.service';
|
||||
import { escapeSqlLikeString, isValidLength } from 'src/utils';
|
||||
import {
|
||||
escapeSqlLikeString,
|
||||
isValidLength,
|
||||
transformCollectionData,
|
||||
} from 'src/utils';
|
||||
import * as E from 'fp-ts/Either';
|
||||
import * as O from 'fp-ts/Option';
|
||||
import {
|
||||
@@ -134,11 +138,13 @@ export class TeamCollectionService {
|
||||
},
|
||||
});
|
||||
|
||||
const data = transformCollectionData(collection.right.data);
|
||||
|
||||
const result: CollectionFolder = {
|
||||
name: collection.right.title,
|
||||
folders: childrenCollectionObjects,
|
||||
requests: requests.map((x) => x.request),
|
||||
data: JSON.stringify(collection.right.data),
|
||||
data,
|
||||
};
|
||||
|
||||
return E.right(result);
|
||||
@@ -309,11 +315,13 @@ export class TeamCollectionService {
|
||||
* @returns TeamCollection model
|
||||
*/
|
||||
private cast(teamCollection: DBTeamCollection): TeamCollection {
|
||||
const data = transformCollectionData(teamCollection.data);
|
||||
|
||||
return <TeamCollection>{
|
||||
id: teamCollection.id,
|
||||
title: teamCollection.title,
|
||||
parentID: teamCollection.parentID,
|
||||
data: !teamCollection.data ? null : JSON.stringify(teamCollection.data),
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,11 @@ import {
|
||||
UserCollectionExportJSONData,
|
||||
} from './user-collections.model';
|
||||
import { ReqType } from 'src/types/RequestTypes';
|
||||
import { isValidLength, stringToJson } from 'src/utils';
|
||||
import {
|
||||
isValidLength,
|
||||
stringToJson,
|
||||
transformCollectionData,
|
||||
} from 'src/utils';
|
||||
import { CollectionFolder } from 'src/types/CollectionFolder';
|
||||
|
||||
@Injectable()
|
||||
@@ -43,13 +47,15 @@ export class UserCollectionService {
|
||||
* @returns UserCollection model
|
||||
*/
|
||||
private cast(collection: UserCollection) {
|
||||
const data = transformCollectionData(collection.data);
|
||||
|
||||
return <UserCollectionModel>{
|
||||
id: collection.id,
|
||||
title: collection.title,
|
||||
type: collection.type,
|
||||
parentID: collection.parentID,
|
||||
userID: collection.userUid,
|
||||
data: !collection.data ? null : JSON.stringify(collection.data),
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -871,6 +877,8 @@ export class UserCollectionService {
|
||||
},
|
||||
});
|
||||
|
||||
const data = transformCollectionData(collection.right.data);
|
||||
|
||||
const result: CollectionFolder = {
|
||||
id: collection.right.id,
|
||||
name: collection.right.title,
|
||||
@@ -882,7 +890,7 @@ export class UserCollectionService {
|
||||
...(x.request as Record<string, unknown>), // type casting x.request of type Prisma.JSONValue to an object to enable spread
|
||||
};
|
||||
}),
|
||||
data: JSON.stringify(collection.right.data),
|
||||
data,
|
||||
};
|
||||
|
||||
return E.right(result);
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { ExecutionContext, HttpException } from '@nestjs/common';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import * as A from 'fp-ts/Array';
|
||||
import * as E from 'fp-ts/Either';
|
||||
import { pipe } from 'fp-ts/lib/function';
|
||||
import * as O from 'fp-ts/Option';
|
||||
import * as TE from 'fp-ts/TaskEither';
|
||||
import * as T from 'fp-ts/Task';
|
||||
import * as E from 'fp-ts/Either';
|
||||
import * as A from 'fp-ts/Array';
|
||||
import { TeamMemberRole } from './team/team.model';
|
||||
import { User } from './user/user.model';
|
||||
import * as TE from 'fp-ts/TaskEither';
|
||||
import { AuthProvider } from './auth/helper';
|
||||
import {
|
||||
ENV_EMPTY_AUTH_PROVIDERS,
|
||||
ENV_NOT_FOUND_KEY_AUTH_PROVIDERS,
|
||||
ENV_NOT_SUPPORT_AUTH_PROVIDERS,
|
||||
JSON_INVALID,
|
||||
} from './errors';
|
||||
import { AuthProvider } from './auth/helper';
|
||||
import { TeamMemberRole } from './team/team.model';
|
||||
import { RESTError } from './types/RESTError';
|
||||
|
||||
/**
|
||||
@@ -297,3 +297,22 @@ export function calculateExpirationDate(expiresOn: null | number) {
|
||||
if (expiresOn === null) return null;
|
||||
return new Date(Date.now() + expiresOn * 24 * 60 * 60 * 1000);
|
||||
}
|
||||
|
||||
/*
|
||||
* Transforms the collection level properties (authorization & headers) under the `data` field.
|
||||
* Preserves `null` values and prevents duplicate stringification.
|
||||
*
|
||||
* @param {Prisma.JsonValue} collectionData - The team collection data to transform.
|
||||
* @returns {string | null} The transformed team collection data as a string.
|
||||
*/
|
||||
export function transformCollectionData(
|
||||
collectionData: Prisma.JsonValue,
|
||||
): string | null {
|
||||
if (!collectionData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return typeof collectionData === 'string'
|
||||
? collectionData
|
||||
: JSON.stringify(collectionData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user