Fix ai bot workspace assign (#7116)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina
2024-11-07 13:18:25 +07:00
committed by GitHub
parent 43c681236b
commit aa4eaeae84
3 changed files with 65 additions and 52 deletions
+58 -1
View File
@@ -13,7 +13,15 @@
// limitations under the License.
//
import { type BaseWorkspaceInfo, type Data, type Version, BackupStatus } from '@hcengineering/core'
import {
type BaseWorkspaceInfo,
type Data,
type Version,
BackupStatus,
AccountRole,
Ref,
Doc
} from '@hcengineering/core'
import { getMetadata, PlatformError, unknownError } from '@hcengineering/platform'
import plugin from './plugin'
@@ -296,3 +304,52 @@ function getAccoutsUrlOrFail (): string {
}
return accountsUrl
}
export async function assignWorkspace (
token: string,
email: string,
workspace: string,
role: AccountRole = AccountRole.User,
personId?: Ref<Doc>,
shouldReplaceAccount = false,
personAccountId?: Ref<Doc>
): Promise<WorkspaceLoginInfo> {
const accountsUrl = getAccoutsUrlOrFail()
const res = await (
await fetch(accountsUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
method: 'assignWorkspace',
params: [token, email, workspace, role, personId, shouldReplaceAccount, undefined, personAccountId]
})
})
).json()
return res.result as WorkspaceLoginInfo
}
export async function createAccount (
email: string,
password: string,
firstName: string,
lastName: string
): Promise<WorkspaceLoginInfo> {
const accountsUrl = getAccoutsUrlOrFail()
const workspace = await (
await fetch(accountsUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
method: 'createAccount',
params: [email, password, firstName, lastName]
})
})
).json()
return workspace.result as WorkspaceLoginInfo
}