feat(ui): new SettingsNotification using antd
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
import { type SettingsModel } from "@/domain/settings";
|
||||
import { ClientResponseError } from "pocketbase";
|
||||
|
||||
import { SETTINGS_NAMES, type SettingsModel } from "@/domain/settings";
|
||||
import { getPocketBase } from "./pocketbase";
|
||||
|
||||
export const get = async <T>(name: string) => {
|
||||
export const get = async <T>(name: (typeof SETTINGS_NAMES)[keyof typeof SETTINGS_NAMES]) => {
|
||||
try {
|
||||
const resp = await getPocketBase().collection("settings").getFirstListItem<SettingsModel<T>>(`name='${name}'`);
|
||||
const resp = await getPocketBase().collection("settings").getFirstListItem<SettingsModel<T>>(`name='${name}'`, {
|
||||
requestKey: null,
|
||||
});
|
||||
return resp;
|
||||
} catch {
|
||||
return {
|
||||
name: name,
|
||||
content: {} as T,
|
||||
} as SettingsModel<T>;
|
||||
} catch (err) {
|
||||
if (err instanceof ClientResponseError && err.status === 404) {
|
||||
return {
|
||||
name: name,
|
||||
content: {} as T,
|
||||
} as SettingsModel<T>;
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user