mirror of
https://github.com/directus/directus.git
synced 2026-01-27 19:17:55 -05:00
Add services folder, rough in create item
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import express, { RequestHandler } from 'express';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import * as itemsService from '../services/items';
|
||||
|
||||
const readItems: RequestHandler = asyncHandler((req, res) => {
|
||||
res.send('Hi there');
|
||||
});
|
||||
|
||||
const router = express.Router().get('/:collection', readItems);
|
||||
const createItem: RequestHandler = asyncHandler(async (req, res) => {
|
||||
await itemsService.create(req.params.collection, req.body);
|
||||
res.status(200).end();
|
||||
});
|
||||
|
||||
const router = express.Router().get('/:collection', readItems).post('/:collection', createItem);
|
||||
|
||||
export default router;
|
||||
|
||||
6
src/services/items.ts
Normal file
6
src/services/items.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import database from '../database';
|
||||
import { Query } from '../types/query';
|
||||
|
||||
export const create = async (collection: string, data: Record<string, any>, query: Query = {}) => {
|
||||
await database(collection).insert(data);
|
||||
};
|
||||
1
src/types/query.ts
Normal file
1
src/types/query.ts
Normal file
@@ -0,0 +1 @@
|
||||
export type Query = {};
|
||||
Reference in New Issue
Block a user