DONE
This commit is contained in:
17
routes/methods/delete.js
Normal file
17
routes/methods/delete.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { setResp500 } from '../../helpers/http.js'
|
||||
import NotesService from '../../services/NotesService.js'
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {NotesService}
|
||||
*/
|
||||
const db = new NotesService()
|
||||
|
||||
export const deleteNote = async (req, res) => {
|
||||
try{
|
||||
const data = await db.deleteNote(req.validatedData)
|
||||
res.status(data.code || 200).json(data)
|
||||
}catch (e) {
|
||||
res.status(500).json(setResp500())
|
||||
}
|
||||
}
|
||||
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())
|
||||
}
|
||||
}
|
||||
18
routes/methods/patch.js
Normal file
18
routes/methods/patch.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { setResp500 } from '../../helpers/http.js'
|
||||
import NotesService from '../../services/NotesService.js'
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {NotesService}
|
||||
*/
|
||||
const db = new NotesService()
|
||||
|
||||
export const editNote = async (req, res) => {
|
||||
|
||||
try{
|
||||
const data = await db.updateNote(req.validatedData)
|
||||
res.status(data.code || 200).json(data)
|
||||
}catch (e) {
|
||||
res.status(500).json(setResp500())
|
||||
}
|
||||
}
|
||||
18
routes/methods/post.js
Normal file
18
routes/methods/post.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { setResp500 } from '../../helpers/http.js'
|
||||
import NotesService from '../../services/NotesService.js'
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {NotesService}
|
||||
*/
|
||||
const db = new NotesService()
|
||||
|
||||
export const addNote = async (req, res) => {
|
||||
|
||||
try{
|
||||
const data = await db.insertNote(req.validatedData)
|
||||
res.status(data.code || 200).json(data)
|
||||
}catch (e) {
|
||||
res.status(500).json(setResp500())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user