chore: made data field optional in team and user collections

This commit is contained in:
Balu Babu
2023-12-05 13:12:06 +05:30
parent 1f2aaf528a
commit 337c79447e
4 changed files with 22 additions and 10 deletions

View File

@@ -18,6 +18,7 @@ export class CreateRootTeamCollectionArgs {
@Field({ @Field({
name: 'data', name: 'data',
description: 'JSON string representing the collection data', description: 'JSON string representing the collection data',
nullable: true,
}) })
data: string; data: string;
} }
@@ -36,6 +37,7 @@ export class CreateChildTeamCollectionArgs {
@Field({ @Field({
name: 'data', name: 'data',
description: 'JSON string representing the collection data', description: 'JSON string representing the collection data',
nullable: true,
}) })
data: string; data: string;
} }
@@ -131,6 +133,7 @@ export class UpdateTeamCollectionArgs {
@Field({ @Field({
name: 'data', name: 'data',
description: 'JSON string representing the collection data', description: 'JSON string representing the collection data',
nullable: true,
}) })
data: string; data: string;
} }

View File

@@ -491,7 +491,7 @@ export class TeamCollectionService {
async createCollection( async createCollection(
teamID: string, teamID: string,
title: string, title: string,
data: string, data: string | null = null,
parentTeamCollectionID: string | null, parentTeamCollectionID: string | null,
) { ) {
const isTitleValid = isValidLength(title, this.TITLE_LENGTH); const isTitleValid = isValidLength(title, this.TITLE_LENGTH);
@@ -503,8 +503,11 @@ export class TeamCollectionService {
if (O.isNone(isOwner)) return E.left(TEAM_NOT_OWNER); if (O.isNone(isOwner)) return E.left(TEAM_NOT_OWNER);
} }
const collectionData = stringToJson(data); if (data) {
if (E.isLeft(collectionData)) return E.left(TEAM_COLL_DATA_INVALID); const jsonReq = stringToJson(data);
if (E.isLeft(jsonReq)) return E.left(TEAM_COLL_DATA_INVALID);
data = jsonReq.right;
}
const isParent = parentTeamCollectionID const isParent = parentTeamCollectionID
? { ? {
@@ -523,7 +526,7 @@ export class TeamCollectionService {
}, },
}, },
parent: isParent, parent: isParent,
data: collectionData.right, data: data ?? undefined,
orderIndex: !parentTeamCollectionID orderIndex: !parentTeamCollectionID
? (await this.getRootCollectionsCount(teamID)) + 1 ? (await this.getRootCollectionsCount(teamID)) + 1
: (await this.getChildCollectionsCount(parentTeamCollectionID)) + 1, : (await this.getChildCollectionsCount(parentTeamCollectionID)) + 1,

View File

@@ -10,6 +10,7 @@ export class CreateRootUserCollectionArgs {
@Field({ @Field({
name: 'data', name: 'data',
description: 'JSON string representing the collection data', description: 'JSON string representing the collection data',
nullable: true,
}) })
data: string; data: string;
} }
@@ -27,6 +28,7 @@ export class CreateChildUserCollectionArgs {
@Field({ @Field({
name: 'data', name: 'data',
description: 'JSON string representing the collection data', description: 'JSON string representing the collection data',
nullable: true,
}) })
data: string; data: string;
} }
@@ -126,6 +128,7 @@ export class UpdateUserCollectionsArgs {
@Field({ @Field({
name: 'data', name: 'data',
description: 'JSON string representing the collection data', description: 'JSON string representing the collection data',
nullable: true,
}) })
data: string; data: string;
} }

View File

@@ -222,15 +222,18 @@ export class UserCollectionService {
async createUserCollection( async createUserCollection(
user: AuthUser, user: AuthUser,
title: string, title: string,
data: string, data: string | null = null,
parentUserCollectionID: string | null, parentUserCollectionID: string | null,
type: ReqType, type: ReqType,
) { ) {
const isTitleValid = isValidLength(title, this.TITLE_LENGTH); const isTitleValid = isValidLength(title, this.TITLE_LENGTH);
if (!isTitleValid) return E.left(USER_COLL_SHORT_TITLE); if (!isTitleValid) return E.left(USER_COLL_SHORT_TITLE);
const collectionData = stringToJson(data); if (data) {
if (E.isLeft(collectionData)) return E.left(USER_COLL_DATA_INVALID); const jsonReq = stringToJson(data);
if (E.isLeft(jsonReq)) return E.left(USER_COLL_DATA_INVALID);
data = jsonReq.right;
}
// If creating a child collection // If creating a child collection
if (parentUserCollectionID !== null) { if (parentUserCollectionID !== null) {
@@ -266,7 +269,7 @@ export class UserCollectionService {
}, },
}, },
parent: isParent, parent: isParent,
data: collectionData.right, data: data ?? undefined,
orderIndex: !parentUserCollectionID orderIndex: !parentUserCollectionID
? (await this.getRootCollectionsCount(user.uid)) + 1 ? (await this.getRootCollectionsCount(user.uid)) + 1
: (await this.getChildCollectionsCount(parentUserCollectionID)) + 1, : (await this.getChildCollectionsCount(parentUserCollectionID)) + 1,
@@ -1092,7 +1095,7 @@ export class UserCollectionService {
*/ */
async updateUserCollection( async updateUserCollection(
newTitle: string = null, newTitle: string = null,
collectionData: string, collectionData: string | null = null,
userCollectionID: string, userCollectionID: string,
userID: string, userID: string,
) { ) {
@@ -1117,7 +1120,7 @@ export class UserCollectionService {
id: userCollectionID, id: userCollectionID,
}, },
data: { data: {
data: collectionData, data: collectionData ?? undefined,
title: newTitle ?? undefined, title: newTitle ?? undefined,
}, },
}); });