Add document and api types

This commit is contained in:
Rory Powell 2022-10-03 14:02:58 +01:00
parent 9c9d2de4a5
commit 29659813ef
12 changed files with 104 additions and 12 deletions

View File

@ -0,0 +1,15 @@
import { AppBackupTrigger } from "../../../documents"
export interface SearchAppBackupsRequest {
trigger: AppBackupTrigger
startDate: string
endDate: string
}
export interface CreateAppBackupRequest {
name: string
}
export interface UpdateAppBackupRequest {
name: string
}

View File

@ -0,0 +1 @@
export * from "./backup"

View File

@ -1,3 +1,5 @@
export * from "./analytics"
export * from "./user"
export * from "./errors"
export * from "./schedule"
export * from "./app"

View File

@ -0,0 +1,15 @@
import {
ScheduleMetadata,
ScheduleRepeatPeriod,
ScheduleType,
} from "../../documents"
export interface CreateScheduleRequest {
type: ScheduleType
name: string
startDate: string
repeat: ScheduleRepeatPeriod
metadata: ScheduleMetadata
}
export interface UpdateScheduleRequest extends CreateScheduleRequest {}

View File

@ -44,3 +44,10 @@ export interface InviteUsersResponse {
successful: { email: string }[]
unsuccessful: { email: string; reason: string }[]
}
export interface SearchUsersRequest {
page?: string
email?: string
appId?: string
userIds?: string[]
}

View File

@ -0,0 +1,21 @@
import { Document } from "../document"
export enum AppBackupTrigger {
PUBLISH = "publish",
MANUAL = "manual",
SCHEDULED = "scheduled",
}
export interface AppBackupContents {
datasources: string[]
screens: string[]
automations: string[]
}
export interface AppBackup extends Document {
trigger: AppBackupTrigger
name: string
date: string
userId: string
contents: AppBackupContents
}

View File

@ -10,3 +10,4 @@ export * from "./view"
export * from "../document"
export * from "./row"
export * from "./user"
export * from "./backup"

View File

@ -3,4 +3,4 @@ export * from "./user"
export * from "./userGroup"
export * from "./plugin"
export * from "./quotas"
export * from "./schedules"
export * from "./schedule"

View File

@ -0,0 +1,32 @@
import { Document } from "../document"
export enum ScheduleType {
APP_BACKUP = "app_backup",
}
export enum ScheduleRepeatPeriod {
DAILY = "daily",
WEEKLY = "weekly",
MONTHLY = "monthly",
}
export interface Schedule extends Document {
type: ScheduleType
name: string
startDate: string
repeat: ScheduleRepeatPeriod
metadata: ScheduleMetadata
}
export type ScheduleMetadata = AppBackupScheduleMetadata
export const isAppBackupMetadata = (
type: ScheduleType,
metadata: ScheduleMetadata
): metadata is AppBackupScheduleMetadata => {
return type === ScheduleType.APP_BACKUP
}
export interface AppBackupScheduleMetadata {
apps: string[]
}

View File

@ -1,9 +0,0 @@
export enum ScheduleType {
APP_BACKUP = "app_backup",
}
export enum ScheduleRepeatPeriod {
DAILY = "daily",
WEEKLY = "weekly",
MONTHLY = "monthly",
}

View File

@ -7,6 +7,7 @@ import {
CloudAccount,
InviteUserRequest,
InviteUsersRequest,
SearchUsersRequest,
User,
} from "@budibase/types"
import {
@ -144,7 +145,8 @@ export const destroy = async (ctx: any) => {
}
export const search = async (ctx: any) => {
const paginated = await sdk.users.paginatedUsers(ctx.request.body)
const body = ctx.request.body as SearchUsersRequest
const paginated = await sdk.users.paginatedUsers(body)
// user hashed password shouldn't ever be returned
for (let user of paginated.data) {
if (user) {

View File

@ -27,6 +27,7 @@ import {
MigrationType,
PlatformUserByEmail,
RowResponse,
SearchUsersRequest,
User,
} from "@budibase/types"
import { sendEmail } from "../../utilities/email"
@ -56,7 +57,8 @@ export const paginatedUsers = async ({
page,
email,
appId,
}: { page?: string; email?: string; appId?: string } = {}) => {
userIds,
}: SearchUsersRequest = {}) => {
const db = tenancy.getGlobalDB()
// get one extra document, to have the next page
const opts: any = {
@ -77,6 +79,9 @@ export const paginatedUsers = async ({
} else if (email) {
userList = await usersCore.searchGlobalUsersByEmail(email, opts)
property = "email"
}
if (userIds) {
// TODO: search users by userIds
} else {
// no search, query allDocs
const response = await db.allDocs(dbUtils.getGlobalUserParams(null, opts))