From 912b316fcb2647ec458f00f129141eb2fe16d82a Mon Sep 17 00:00:00 2001 From: "Michael.Taylor" Date: Tue, 7 Dec 2021 17:07:10 -0500 Subject: [PATCH] feat: implement staging crud --- src/controllers/staging.controller.js | 41 ++++++++++----------------- src/routes/v1/resources/stagings.js | 21 ++++++++++++++ 2 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 src/routes/v1/resources/stagings.js diff --git a/src/controllers/staging.controller.js b/src/controllers/staging.controller.js index 51e3eae1..0fa0a33a 100644 --- a/src/controllers/staging.controller.js +++ b/src/controllers/staging.controller.js @@ -1,11 +1,5 @@ import { Staging, StagingMock } from '../models'; -export const create = (req, res) => { - res.json({ - message: 'Not Yet Implemented', - }); -}; - export const findAll = async (req, res) => { if (req.query.useMock) { res.json(StagingMock.findAll()); @@ -15,25 +9,20 @@ export const findAll = async (req, res) => { res.json(Staging.findAll()); }; -export const findOne = async (req, res) => { - if (req.query.useMock) { - res.json(StagingMock.findOne(req.query.id)); - return; - } - - res.json({ - message: 'Not Yet Implemented', - }); -}; - -export const update = (req, res) => { - res.json({ - message: 'Not Yet Implemented', - }); -}; - export const destroy = (req, res) => { - res.json({ - message: 'Not Yet Implemented', - }); + Staging.destroy({ + where: { + uuid: req.body.uuid, + }, + }) + .then(() => { + res.json({ + message: 'Deleted', + }); + }) + .catch((err) => { + res.json({ + message: err, + }); + }); }; diff --git a/src/routes/v1/resources/stagings.js b/src/routes/v1/resources/stagings.js new file mode 100644 index 00000000..6bc3ffe9 --- /dev/null +++ b/src/routes/v1/resources/stagings.js @@ -0,0 +1,21 @@ +'use strict'; + +import express from 'express'; +import { StagingController } from './staging./../../controllers'; +const StagingRouter = express.Router(); + +StagingRouter.get('/', (req, res) => { + return StagingController.findAll(req, res); +}); + +const querySchemaDelete = { + id: Joi.string().required(), +}; + +StagingRouter.delete( + '/', + validator.body(querySchemaDelete), + StagingController.destroy, +); + +export { StagingRouter };