Type request and body
This commit is contained in:
parent
23266bd456
commit
946cc35ff7
|
@ -7,10 +7,10 @@ import {
|
|||
roles as rolesCore,
|
||||
db as dbCore,
|
||||
} from "@budibase/backend-core"
|
||||
import { BBContext, Ctx, isUser, User } from "@budibase/types"
|
||||
import { BBContext, Ctx, SyncUserRequest, User } from "@budibase/types"
|
||||
import sdk from "../../sdk"
|
||||
|
||||
export async function syncUser(ctx: Ctx) {
|
||||
export async function syncUser(ctx: Ctx<SyncUserRequest>) {
|
||||
let deleting = false,
|
||||
user: User | any
|
||||
const userId = ctx.params.id
|
||||
|
@ -28,10 +28,9 @@ export async function syncUser(ctx: Ctx) {
|
|||
}
|
||||
}
|
||||
|
||||
let previousApps =
|
||||
previousUser && isUser(previousUser)
|
||||
? Object.keys(previousUser.roles).map(appId => appId)
|
||||
: []
|
||||
let previousApps = previousUser
|
||||
? Object.keys(previousUser.roles).map(appId => appId)
|
||||
: []
|
||||
|
||||
const roles = deleting ? {} : user.roles
|
||||
// remove props which aren't useful to metadata
|
||||
|
|
|
@ -57,3 +57,7 @@ export interface CreateAdminUserRequest {
|
|||
password: string
|
||||
tenantId: string
|
||||
}
|
||||
|
||||
export interface SyncUserRequest {
|
||||
previousUser?: User
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import fetch from "node-fetch"
|
|||
import { constants, tenancy } from "@budibase/backend-core"
|
||||
import { checkSlashesInUrl } from "../utilities"
|
||||
import env from "../environment"
|
||||
import { User } from "@budibase/types"
|
||||
import { SyncUserRequest, User } from "@budibase/types"
|
||||
|
||||
async function makeAppRequest(url: string, method: string, body: any) {
|
||||
if (env.isTest()) {
|
||||
|
@ -22,10 +22,14 @@ async function makeAppRequest(url: string, method: string, body: any) {
|
|||
}
|
||||
|
||||
export async function syncUserInApps(userId: string, previousUser?: User) {
|
||||
const body: SyncUserRequest = {
|
||||
previousUser,
|
||||
}
|
||||
|
||||
const response = await makeAppRequest(
|
||||
`/api/users/metadata/sync/${userId}`,
|
||||
"POST",
|
||||
{ previousUser }
|
||||
body
|
||||
)
|
||||
if (response && response.status !== 200) {
|
||||
throw "Unable to sync user."
|
||||
|
|
Loading…
Reference in New Issue