Skip to content

Instantly share code, notes, and snippets.

@talcual
Last active November 2, 2022 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talcual/6fb56b8f20cb38ff629be1427a00f4fa to your computer and use it in GitHub Desktop.
Save talcual/6fb56b8f20cb38ff629be1427a00f4fa to your computer and use it in GitHub Desktop.
var express = require('express');
var router = express.Router();
var Publicaciones = require('../models/Publicaciones');
/* Creating Device */
router.post('/create', async function(req, res, next) {
try {
const response = await Publicaciones.create({
titulo : req.body.title,
contenido : req.body.content,
create_at : req.body.create_at,
owner : req.body.owner
}).then(function(data){
const res = { success: true, data: data, message:"created successful" }
return res;
}).catch(error=>{
const res = { success: false, error: error }
return res;
})
res.json(response);
} catch (e) {
console.log(e);
}
});
/* Update device data */
router.post('/update_publicacion', async function(req, res, next) {
try {
const response = await Publicaciones.findByPk(req.body.serial)
.then(function(publicacion){
if (publicacion) {
device.update(req.body).success(function () {
const res = { success: true, data: data }
})
}
return res;
}).catch(error =>{
const res = { success: false, error: error }
return res;
})
res.json(response);
} catch (e) {
console.log(e);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment