Fix main product ws update (#2381)

* Fix main product ws update

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>

* Fix list workspaces

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>

* Fix formatting

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2022-11-15 18:03:27 +06:00 committed by GitHub
parent 074eabbce6
commit 55e3cbea59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -340,7 +340,7 @@ export async function listWorkspaces (db: Db, productId: string): Promise<Worksp
if (productId === '') {
return await db
.collection<Workspace>(WORKSPACE_COLLECTION)
.find({ productId: { $exists: false } })
.find({ $or: [{ productId: { $exists: false } }, { productId: '' }] })
.toArray()
}
return await db.collection<Workspace>(WORKSPACE_COLLECTION).find({ productId }).toArray()
@ -397,7 +397,9 @@ export async function upgradeWorkspace (
throw new PlatformError(new Status(Severity.ERROR, accountPlugin.status.WorkspaceNotFound, { workspace }))
}
if (ws.productId !== productId) {
throw new PlatformError(new Status(Severity.ERROR, accountPlugin.status.ProductIdMismatch, { productId }))
if (productId !== '' || ws.productId !== undefined) {
throw new PlatformError(new Status(Severity.ERROR, accountPlugin.status.ProductIdMismatch, { productId }))
}
}
await db.collection(WORKSPACE_COLLECTION).updateOne(
{ workspace },