From 606164bb435a101c6bbc0716c4a39805e95418a2 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Thu, 1 Aug 2019 17:39:53 +0300 Subject: [PATCH] api persons urls --- pages/api/persons/urls.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pages/api/persons/urls.js diff --git a/pages/api/persons/urls.js b/pages/api/persons/urls.js new file mode 100644 index 00000000..da82658f --- /dev/null +++ b/pages/api/persons/urls.js @@ -0,0 +1,20 @@ +import { connect } from '../../../src/core/db' +import Teacher from '../../../src/core/Teacher' + +export default async (req, res) => { + await connect() + + const data = await Teacher.find({}) + + if (data) { + const items = data.map(x => `/teacher/${x.id}`) + res.json({ + items + }) + } else { + res.status(404) + res.json({ + error: `Not found` + }) + } +}