chore: Update devcontainer.json and pbTools.ts

This commit is contained in:
zhaoyingbo 2024-05-24 19:32:39 +08:00
parent b7d858f246
commit 004044a085
3 changed files with 6 additions and 10 deletions

View File

@ -10,9 +10,7 @@
"editor.guides.bracketPairs": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": true
}
"github.copilot.chat.localeOverride": "zh-CN"
},
"extensions": [
"dbaeumer.vscode-eslint",
@ -24,7 +22,6 @@
"ChakrounAnas.turbo-console-log",
"Gruntfuggly.todo-tree",
"MS-CEINTL.vscode-language-pack-zh-hans",
"stylelint.vscode-stylelint",
"GitHub.copilot"
]
}

View File

@ -11,19 +11,19 @@ export interface UserRecordModel extends RecordModel {
}
const getOne = (id: string) =>
managePb404(
managePb404<UserRecordModel>(
async () => await pbClient.collection("user").getOne(id)
) as Promise<UserRecordModel>;
);
const getOneByUserId = (user_id: number) => {
return managePb404(
return managePb404<UserRecordModel>(
async () =>
await pbClient
.collection("user")
.getFirstListItem(`user_id="${user_id}"`, {
sort: "-created",
})
) as Promise<UserRecordModel>;
);
};
const create = async (data: Partial<UserRecordModel>) =>

View File

@ -1,8 +1,7 @@
export const managePb404 = async (dbFunc: Function) => {
export const managePb404 = async <T>(dbFunc: Function): Promise<T | null> => {
try {
return await dbFunc();
} catch (err: any) {
// 没有这个提醒就返回空
if (err?.message === "The requested resource wasn't found.") {
return null;
} else throw err;