@opengis/fastify-table
Version:
core-plugins
27 lines (22 loc) • 945 B
JavaScript
import update from './controllers/update.js';
import insert from './controllers/insert.js';
import deleteCrud from './controllers/deleteCrud.js';
import table from './controllers/table.js';
const tableSchema = {
type: 'object',
properties: {
params: {
id: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
},
},
};
const policy = ['public'];
async function plugin(app, config = {}) {
const { prefix = '/api' } = config;
app.put(`${prefix}/table/:table/:id?`, { config: { policy }, schema: tableSchema }, update);
app.delete(`${prefix}/table/:table/:id?`, { config: { policy }, schema: tableSchema }, deleteCrud);
app.post(`${prefix}/table/:table/:id?`, { config: { policy }, schema: tableSchema }, insert);
app.get(`${prefix}/table/:table/:id?`, { config: { policy }, schema: tableSchema }, table);
}
export default plugin;