feat: 更新用户数据库操作,统一使用数据库名称常量
This commit is contained in:
parent
8c42f639ba
commit
abca5fcf87
@ -4,6 +4,8 @@ import { Context } from "../../types"
|
|||||||
import { managePbError } from "../../utils/pbTools"
|
import { managePbError } from "../../utils/pbTools"
|
||||||
import pbClient from "../pbClient"
|
import pbClient from "../pbClient"
|
||||||
|
|
||||||
|
const DB_NAME = "users"
|
||||||
|
|
||||||
// 用户接口定义
|
// 用户接口定义
|
||||||
interface User {
|
interface User {
|
||||||
email: string
|
email: string
|
||||||
@ -25,7 +27,7 @@ export type UserModel = User & RecordModel
|
|||||||
* @returns {Promise<UserModel>} - 创建的用户模型
|
* @returns {Promise<UserModel>} - 创建的用户模型
|
||||||
*/
|
*/
|
||||||
const create = async (user: User) =>
|
const create = async (user: User) =>
|
||||||
managePbError<UserModel>(() => pbClient.collection("user").create(user))
|
managePbError<UserModel>(() => pbClient.collection(DB_NAME).create(user))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户ID获取用户
|
* 通过用户ID获取用户
|
||||||
@ -34,7 +36,7 @@ const create = async (user: User) =>
|
|||||||
*/
|
*/
|
||||||
const getByUserId = async (userId: string) =>
|
const getByUserId = async (userId: string) =>
|
||||||
managePbError<UserModel>(() =>
|
managePbError<UserModel>(() =>
|
||||||
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 = {
|
const user = {
|
||||||
getByCtx,
|
getByCtx,
|
||||||
|
getByUserId,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default user
|
export default user
|
||||||
|
5
test/user/index.ts
Normal file
5
test/user/index.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import pbClient from "../../db/pbClient"
|
||||||
|
|
||||||
|
const userId = "zhaoyingbo"
|
||||||
|
|
||||||
|
pbClient.collection("users").getFirstListItem(`userId = "${userId}"`)
|
Loading…
x
Reference in New Issue
Block a user