diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 2e2c715..62332ca 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -904,7 +904,7 @@ components: _id: type: string readOnly: true - adress: + address: type: string minLength: 10 maxLength: 100 diff --git a/src/controllers/stores.ts b/src/controllers/stores.ts index 1732bfe..76e5da2 100644 --- a/src/controllers/stores.ts +++ b/src/controllers/stores.ts @@ -50,27 +50,23 @@ export const getStoreById = async (req, res) => { export const createStore = async (req, res) => { try { - const storeData = req.body; - const store = await Store.insertOne(storeData); - - const address = storeData.address; + const { address } = req.body; if (!address || address.length < 10 || address.length > 100) { - return res - .status(400) - .json({ - message: 'Invalid input data', - status: 'failure' - }); + return res.status(400).json({ + message: 'Invalid input data', + status: 'failure' + }); } - return res - .status(201) - .json({ - items: store, - message: 'Store created successfully', - status: 'success' - }); + const store = new Store({ address }); + await store.save(); + + return res.status(201).json({ + items: store, + message: 'Store created successfully', + status: 'success' + }); } catch (error) { return res.status(500).json({ @@ -134,7 +130,7 @@ export const deleteStoreById = async (req, res) => { }); } - return res.status(204); + return res.status(204).send(); } catch (error) { return res.status(500).json({