Progress
This commit is contained in:
@@ -1,28 +1,26 @@
|
||||
import db from "../../../../lib/db";
|
||||
import { withErrorHandling, withSession } from "../../../../lib/apiHelpers";
|
||||
import { authenticatedJsonApi } from "../../../../lib/jsonapi";
|
||||
import models from "../../../../lib/models";
|
||||
|
||||
const handler = withErrorHandling(
|
||||
withSession(async (req, res, session) => {
|
||||
const { method } = req;
|
||||
const { user } = session;
|
||||
const handler = authenticatedJsonApi(async (req, res, session) => {
|
||||
const { method } = req;
|
||||
const { user } = session;
|
||||
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await getEntity(req, res, user);
|
||||
break;
|
||||
default:
|
||||
res.setHeader("Allow", ["GET"]);
|
||||
res.status(405).end(`Method ${method} Not Allowed`);
|
||||
}
|
||||
})
|
||||
);
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await getEntity(req, res, user);
|
||||
break;
|
||||
default:
|
||||
res.setHeader("Allow", ["GET"]);
|
||||
res.status(405).send(`Method ${method} Not Allowed`);
|
||||
}
|
||||
});
|
||||
|
||||
const getEntity = async (req, res, user) => {
|
||||
const { entityName, entityId } = req.query;
|
||||
|
||||
if (!models[entityName]) {
|
||||
res.status(404).end();
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,7 +28,7 @@ const getEntity = async (req, res, user) => {
|
||||
|
||||
if (!model.validateId(entityId)) {
|
||||
console.warn(model.validateId.errors);
|
||||
res.status(404).end();
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,7 +46,7 @@ const getEntity = async (req, res, user) => {
|
||||
if (entities.Items.length == 1) {
|
||||
res.status(200).json(entities.Items[0]);
|
||||
} else {
|
||||
res.status(404).end();
|
||||
res.status(404);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,31 +1,29 @@
|
||||
import db from "../../../../lib/db";
|
||||
import { withErrorHandling, withSession } from "../../../../lib/apiHelpers";
|
||||
import { authenticatedJsonApi } from "../../../../lib/jsonapi";
|
||||
import models from "../../../../lib/models";
|
||||
|
||||
const handler = withErrorHandling(
|
||||
withSession(async (req, res, session) => {
|
||||
const { method } = req;
|
||||
const { user } = session;
|
||||
const handler = authenticatedJsonApi(async (req, res, session) => {
|
||||
const { method } = req;
|
||||
const { user } = session;
|
||||
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await getEntities(req, res, user);
|
||||
break;
|
||||
case "POST":
|
||||
await createEntity(req, res, user);
|
||||
break;
|
||||
default:
|
||||
res.setHeader("Allow", ["GET", "POST"]);
|
||||
res.status(405).end(`Method ${method} Not Allowed`);
|
||||
}
|
||||
})
|
||||
);
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await getEntities(req, res, user);
|
||||
break;
|
||||
case "POST":
|
||||
await createEntity(req, res, user);
|
||||
break;
|
||||
default:
|
||||
res.setHeader("Allow", ["GET", "POST"]);
|
||||
res.status(405).json(`Method ${method} Not Allowed`);
|
||||
}
|
||||
});
|
||||
|
||||
const getEntities = async (req, res, user) => {
|
||||
const { entityName } = req.query;
|
||||
|
||||
if (!models[entityName]) {
|
||||
res.status(404).end();
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,7 +44,7 @@ const createEntity = async (req, res, user) => {
|
||||
const { entityName } = req.query;
|
||||
|
||||
if (!models[entityName]) {
|
||||
res.status(404).end();
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user