forked from mengyxu/noob-components
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.2 KiB
2.2 KiB
Config API
plugs/api/config.ts- System configuration management.
Overview
System configuration API with list and update operations, plus single value retrieval.
Endpoint
- Root:
config
Exports
| Function | HTTP | Description |
|---|---|---|
list |
GET | List config entries with filter |
set |
PUT | Update existing config entry |
getValue |
GET | Get config value by key |
Functions
list
export const list = (example) => {
return queryPage(root, example);
};
- Uses:
queryPagefrom base - URL:
config - Parameters:
example- Filter criteria (optional) - Returns: Paginated result
set
export const set = (config) => {
return update(root, config);
};
- Uses:
updatefrom base (PUT) - Parameters:
config- Config object to update
getValue
export const getValue = (key) => {
return new Promise((resolve, reject) => {
get(root + '/' + key, null, true, true).then(
(rsp: any) => {
resolve(rsp);
},
(err) => {
resolve(null);
}
);
});
};
- URL:
config/{key} - Parameters:
key- Configuration key - noMsg:
true- Suppress success message - noLoading:
true- Suppress loading indicator - Returns:
nullon error (notfalseor{})
Usage Example
import { config } from 'plugs/api';
// List all configs
const configs = await config.list();
// List filtered configs
const dbConfigs = await config.list({ category: 'database' });
// Update config
await config.set({ key: 'app.name', value: 'My App', id: 1 });
// Get single config value
const appName = await config.getValue('app.name');
Pattern Notes
- No
addfunction - configs are typically only updated, not created getValuereturnsnullon error (different from other APIs that returnfalse)getValueuses custom implementation instead ofgetByIdfrom base
Anti-Patterns
- Missing
addfunction - Inconsistent with other CRUD APIs - Custom
getValueinstead ofgetById- Could use base'sgetByIdwith URL template