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