mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
add tenancy crud
This commit is contained in:
parent
a7acab4646
commit
0f9b372cbd
@ -0,0 +1,26 @@
|
||||
import { createCrudHandlers } from "@/route-handlers/crud-handler";
|
||||
import { tenancyCrud } from "@stackframe/stack-shared/dist/interface/crud/tenancy";
|
||||
import { yupObject } from "@stackframe/stack-shared/dist/schema-fields";
|
||||
import { createLazyProxy } from "@stackframe/stack-shared/dist/utils/proxies";
|
||||
|
||||
export const tenancyCrudHandlers = createLazyProxy(() => createCrudHandlers(tenancyCrud, {
|
||||
paramsSchema: yupObject({}),
|
||||
onRead: async ({ auth }) => {
|
||||
return {
|
||||
id: auth.tenancy.id,
|
||||
project_id: auth.project.id,
|
||||
branch_id: auth.tenancy.branchId,
|
||||
organization_id: auth.tenancy.organization?.id,
|
||||
config: auth.tenancy.completeConfig,
|
||||
};
|
||||
},
|
||||
onUpdate: async ({ auth, data }) => {
|
||||
return {
|
||||
id: auth.tenancy.id,
|
||||
project_id: auth.project.id,
|
||||
branch_id: auth.tenancy.branchId,
|
||||
organization_id: auth.tenancy.organization?.id,
|
||||
config: auth.tenancy.completeConfig,
|
||||
};
|
||||
},
|
||||
}));
|
||||
33
packages/stack-shared/src/interface/crud/tenancy.ts
Normal file
33
packages/stack-shared/src/interface/crud/tenancy.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { CrudTypeOf, createCrud } from "../../crud";
|
||||
import * as schemaFields from "../../schema-fields";
|
||||
import { yupObject } from "../../schema-fields";
|
||||
|
||||
export const tenancyCrudAdminReadSchema = yupObject({
|
||||
project_id: schemaFields.yupString().defined(),
|
||||
branch_id: schemaFields.yupString().defined(),
|
||||
organization_id: schemaFields.yupString().optional(),
|
||||
id: schemaFields.yupString().defined(),
|
||||
config: schemaFields.yupMixed().defined(),
|
||||
}).defined();
|
||||
|
||||
export const tenancyCrudAdminUpdateSchema = yupObject({
|
||||
config: schemaFields.yupMixed().optional(),
|
||||
}).defined();
|
||||
|
||||
export const tenancyCrud = createCrud({
|
||||
adminReadSchema: tenancyCrudAdminReadSchema,
|
||||
adminUpdateSchema: tenancyCrudAdminUpdateSchema,
|
||||
docs: {
|
||||
adminRead: {
|
||||
summary: 'Get the current tenancy',
|
||||
description: 'Get the current tenancy information and configuration',
|
||||
tags: ['Tenancies'],
|
||||
},
|
||||
adminUpdate: {
|
||||
summary: 'Update the current tenancy',
|
||||
description: 'Update the current tenancy information and configuration',
|
||||
tags: ['Tenancies'],
|
||||
},
|
||||
},
|
||||
});
|
||||
export type TenancyCrud = CrudTypeOf<typeof tenancyCrud>;
|
||||
Loading…
Reference in New Issue
Block a user