DONE
This commit is contained in:
65
routes/methods/get.js
Normal file
65
routes/methods/get.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import { setResp403, setResp500 } from '../../helpers/http.js'
|
||||
import NotesService from '../../services/NotesService.js'
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {NotesService}
|
||||
*/
|
||||
const db = new NotesService()
|
||||
|
||||
/**
|
||||
*
|
||||
* @param req
|
||||
* @param res
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export const setForbidden = async (req, res) => {
|
||||
const ip = req.headers['x-real-ip'] || req.connection.remoteAddress
|
||||
res.status(403).json(setResp403(`You are not allowed to access the resource. Your IP is ${ip}`))
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param req
|
||||
* @param res
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export const getAllNotes = async (req, res) => {
|
||||
try{
|
||||
const data = await db.getNotes
|
||||
res.status(data.code || 200).json(data)
|
||||
}catch (e) {
|
||||
res.status(500).json(setResp500())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param req
|
||||
* @param res
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export const getSingleNote = async (req, res) => {
|
||||
|
||||
try{
|
||||
const data = await db.getSingle(req.validatedData)
|
||||
res.status(data.code || 200).json(data)
|
||||
}catch (e) {
|
||||
res.status(500).json(setResp500())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param req
|
||||
* @param res
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export const getStats = (req, res) => {
|
||||
try{
|
||||
const data = db.getStats
|
||||
res.status(data.code || 200).json( data )
|
||||
}catch (e) {
|
||||
res.status(500).json(setResp500())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user