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.4 KiB
2.4 KiB
Dictionary API
plugs/api/dictionary.ts- Dictionary data management.
Overview
Dictionary/config key-value storage API with standard CRUD operations.
Endpoint
- Root:
dict
Exports
| Function | HTTP | Description |
|---|---|---|
list |
GET | List dictionary entries with filter |
add |
POST | Create new dictionary entry |
set |
PUT | Update existing dictionary entry |
del |
DELETE | Delete dictionary entry |
Functions
list
export const list = (example) => {
return queryPage(root, example);
};
- Uses:
queryPagefrom base (notqueryList) - URL:
dict - Parameters:
example- Filter criteria (optional) - Returns: Paginated result (PageResult)
add
export const add = (dictionary) => {
return save(root, dictionary);
};
- Uses:
savefrom base (POST) - Parameters:
dictionary- Dictionary entry to create
set
export const set = (dictionary) => {
return update(root, dictionary);
};
- Uses:
updatefrom base (PUT) - Parameters:
dictionary- Dictionary entry to update
del
export const del = (dictionary) => {
return new Promise((resolve, reject) => {
delate(root, dictionary).then(
(rsp: any) => {
if (rsp) {
resolve(rsp);
} else {
resolve(false);
}
},
(err) => {
resolve(false);
}
);
});
};
- Uses: Custom implementation using
delatedirectly - Note: Does NOT use
deleteByIdfrom base - passes full dictionary object - Difference from base pattern:
deleteByIdpassesidas second param, butdelpasses entire object
Usage Example
import { dictionary } from 'plugs/api';
// List dictionary entries
const entries = await dictionary.list({ type: 'status' });
// Add entry
await dictionary.add({ type: 'status', label: 'Active', value: '1' });
// Update entry
await dictionary.set({ type: 'status', label: 'Active', value: '1', id: 1 });
// Delete entry
await dictionary.del({ id: 1 });
Pattern Differences
| Aspect | Pattern Used | Explanation |
|---|---|---|
| List | queryPage |
Returns paginated results |
| Delete | Custom Promise | Passes full object, not just ID |
This differs from role.ts and permission.ts which use queryList for list and deleteById for delete.