diff --git a/db/user/index.ts b/db/user/index.ts index 8e08470..3572d5d 100644 --- a/db/user/index.ts +++ b/db/user/index.ts @@ -4,6 +4,8 @@ import { Context } from "../../types" import { managePbError } from "../../utils/pbTools" import pbClient from "../pbClient" +const DB_NAME = "users" + // 用户接口定义 interface User { email: string @@ -25,7 +27,7 @@ export type UserModel = User & RecordModel * @returns {Promise} - 创建的用户模型 */ const create = async (user: User) => - managePbError(() => pbClient.collection("user").create(user)) + managePbError(() => pbClient.collection(DB_NAME).create(user)) /** * 通过用户ID获取用户 @@ -34,7 +36,7 @@ const create = async (user: User) => */ const getByUserId = async (userId: string) => managePbError(() => - pbClient.collection("user").getFirstListItem(`userId = "${userId}"`) + pbClient.collection(DB_NAME).getFirstListItem(`userId = "${userId}"`) ) /** @@ -76,6 +78,7 @@ const getByCtx = async ({ larkBody, larkService }: Context) => { // 用户对象 const user = { getByCtx, + getByUserId, } export default user diff --git a/test/user/index.ts b/test/user/index.ts new file mode 100644 index 0000000..298e746 --- /dev/null +++ b/test/user/index.ts @@ -0,0 +1,5 @@ +import pbClient from "../../db/pbClient" + +const userId = "zhaoyingbo" + +pbClient.collection("users").getFirstListItem(`userId = "${userId}"`)