From a7a2a56044717eaeb054ca767639269ad4c20c05 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 4 Dec 2024 15:00:05 +0000 Subject: [PATCH] User metadata API typing. --- packages/server/src/api/controllers/user.ts | 23 ++++++++++++++------- packages/types/src/api/web/app/user.ts | 20 ++++++++++++++++-- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/packages/server/src/api/controllers/user.ts b/packages/server/src/api/controllers/user.ts index 108e29fd3d..d8ce37edb4 100644 --- a/packages/server/src/api/controllers/user.ts +++ b/packages/server/src/api/controllers/user.ts @@ -7,19 +7,24 @@ import { FetchUserMetadataResponse, FindUserMetadataResponse, Flags, - SetFlagRequest, + SetUserFlagRequest, + UpdateSelfMetadataRequest, + UpdateSelfMetadataResponse, + UpdateUserMetadataResponse, + UpdateUserMetadataRequest, UserCtx, - UserMetadata, + DeleteUserMetadataResponse, + SetUserFlagResponse, + GetUserFlagsResponse, } from "@budibase/types" import sdk from "../../sdk" -import { DocumentInsertResponse } from "@budibase/nano" export async function fetchMetadata(ctx: Ctx) { ctx.body = await sdk.users.fetchMetadata() } export async function updateSelfMetadata( - ctx: UserCtx + ctx: UserCtx ) { // overwrite the ID with current users ctx.request.body._id = ctx.user?._id @@ -31,7 +36,7 @@ export async function updateSelfMetadata( } export async function updateMetadata( - ctx: UserCtx + ctx: UserCtx ) { const db = context.getAppDB() const user = ctx.request.body @@ -44,7 +49,9 @@ export async function updateMetadata( ctx.body = await db.put(metadata) } -export async function destroyMetadata(ctx: UserCtx) { +export async function destroyMetadata( + ctx: UserCtx +) { const db = context.getAppDB() try { const dbUser = await sdk.users.get(ctx.params.id) @@ -64,7 +71,7 @@ export async function findMetadata( } export async function setFlag( - ctx: UserCtx + ctx: UserCtx ) { const userId = ctx.user?._id const { flag, value } = ctx.request.body @@ -84,7 +91,7 @@ export async function setFlag( ctx.body = { message: "Flag set successfully" } } -export async function getFlags(ctx: UserCtx) { +export async function getFlags(ctx: UserCtx) { const userId = ctx.user?._id const docId = generateUserFlagID(userId!) const db = context.getAppDB() diff --git a/packages/types/src/api/web/app/user.ts b/packages/types/src/api/web/app/user.ts index f5f2049724..ebdc43ea27 100644 --- a/packages/types/src/api/web/app/user.ts +++ b/packages/types/src/api/web/app/user.ts @@ -1,11 +1,27 @@ -import { ContextUserMetadata } from "../../../" +import { ContextUserMetadata, Flags, UserMetadata } from "../../../" +import { DocumentInsertResponse } from "@budibase/nano" export type FetchUserMetadataResponse = ContextUserMetadata[] export type FindUserMetadataResponse = ContextUserMetadata -export interface SetFlagRequest { +export interface SetUserFlagRequest { flag: string value: any } +export interface SetUserFlagResponse { + message: string +} + +export interface GetUserFlagsResponse extends Flags {} export type AppSelfResponse = ContextUserMetadata | {} + +export interface UpdateSelfMetadataRequest extends UserMetadata {} +export interface UpdateSelfMetadataResponse extends DocumentInsertResponse {} + +export interface UpdateUserMetadataRequest extends UserMetadata {} +export interface UpdateUserMetadataResponse extends DocumentInsertResponse {} + +export interface DeleteUserMetadataResponse { + message: string +}