hotfix: forgot to refine controllers for dev-exp
This commit is contained in:
@@ -1,18 +1,26 @@
|
|||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
import Example from './../models/model.js';
|
import Example from './../models/model.js';
|
||||||
|
// more about response status codes ---> https://restapitutorial.com/httpstatuscodes.html
|
||||||
|
|
||||||
export const getExamples = (request, response, next) =>
|
export const getExamples = async (request, response, next) => {
|
||||||
Example.find() // what is .find() ??? ---> https://mongoosejs.com/docs/queries.html
|
try {
|
||||||
.then((data) => response.status(200).json(data))
|
const allExamples = await Example.find(); // what is .find() ??? ---> https://mongoosejs.com/docs/queries.html
|
||||||
.catch((error) => response.status(500).json(error));
|
response.status(200).json(allExamples);
|
||||||
|
} catch (error) {
|
||||||
|
response.status(500).json(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const uploadExample = (request, response, next) =>
|
export const uploadExample = async (request, response, next) => {
|
||||||
new Example({
|
let newExample = new Example({
|
||||||
_id: mongoose.Types.ObjectId(), // _id is set by default, (you can remove this line)
|
_id: mongoose.Types.ObjectId(), // _id is set by default, (you can remove this line)
|
||||||
name: request.body.fieldName, // fieldName === name used on client side
|
name: request.body.fieldName, // fieldName === name used on client side
|
||||||
})
|
});
|
||||||
.save() // what is .save() ??? ---> https://mongoosejs.com/docs/api.html#document_Document-save
|
|
||||||
.then.then((data) => response.status(201).json(data))
|
|
||||||
.catch((error) => response.status(500).json(error));
|
|
||||||
|
|
||||||
// more about response status codes ---> https://restapitutorial.com/httpstatuscodes.html
|
try {
|
||||||
|
const savedExample = await newExample.save(); // what is .save() ??? ---> https://mongoosejs.com/docs/api.html#document_Document-save
|
||||||
|
response.status(201).json(savedExample);
|
||||||
|
} catch (error) {
|
||||||
|
response.status(500).json(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user