/
capabilities.ts
41 lines (34 loc) · 1.1 KB
/
capabilities.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Static, Type } from "@sinclair/typebox";
import fp from "fastify-plugin";
const CapabilitiesSchema = Type.Object({
createUser: Type.Boolean({ description: "是否可以创建用户" }),
changePassword: Type.Boolean({ description: "是否可以修改密码" }),
validateName: Type.Boolean({ description: "是否可以验证用户名的密码" }),
getUser: Type.Boolean({ description: "是否可以查询用户" }),
});
export type Capabilities = Static<typeof CapabilitiesSchema>;
const ResponsesSchema = Type.Object({
200: CapabilitiesSchema,
});
export const getCapabilitiesRoute = fp(async (f) => {
f.get<{
Querystring: {},
Responses: Static<typeof ResponsesSchema>,
}>(
"/capabilities",
{
schema: {
response: ResponsesSchema.properties,
},
},
async () => {
const provider = f.auth;
return {
createUser: provider.createUser !== undefined,
validateName: provider.validateName !== undefined,
changePassword: provider.changePassword !== undefined,
getUser: provider.getUser !== undefined,
};
},
);
});