chore: made data field optional in team and user collections
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user