54 lines
973 B
JavaScript
54 lines
973 B
JavaScript
import { 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 notesIndex = 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())
|
|
}
|
|
} |