Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- var express = require('express');
- var Web = require("seneca-web");
- var bodyParser = require('body-parser')
- var plugin = require('./products_actions/products_actions');
- module.exports = plugin;
- var entities = require('seneca-entity')
- var seneca = require('seneca')();
- seneca.use(plugin);
- seneca.use(entities);
- seneca.use('mysql-store', {
- name : 'ecrm',
- host : 'localhost',
- user : 'root',
- password : 'ecrm',
- port : 3306
- })
- seneca.ready(function(err) {
- var Routes = [ {
- pin : 'area:product,action:fetch,criteria:*',
- prefix : '/products/fetch',
- map : {
- byId : {
- GET : true,
- suffix : "/:id"
- }
- }
- }, {
- pin : 'area:product,action:*',
- prefix : '/products',
- map : {
- fetch : {
- GET : true
- },
- add : {
- GET : false,
- PUT : true
- }
- }
- } ];
- var app = express();
- app.use(bodyParser.json());
- var config = {
- routes : Routes,
- adapter : require('seneca-web-adapter-express'),
- context : app,
- options : {
- parseBody : false
- }
- }
- seneca.use(Web, config);
- app.listen(3000);
- });
- module.exports = function(options) {
- var seneca = this;
- // ADD
- seneca.add({
- area : "product",
- action : "add"
- }, function(req, done) {
- var products = this.make$("prodotti");
- var args = req.args.body;
- console.log(args);
- products.nome = args.nome;
- products.categoria = args.categoria;
- products.descrizione = args.descrizione;
- products.prezzo = args.prezzo;
- products.save$(function(err, product) {
- done(err, products.data$(false));
- });
- });
- // get by Id , PROBLEM!!!
- seneca.add({
- area : "product",
- action : "fetch",
- criteria : "byId"
- }, function(req, done) {
- console.log("HERE");
- var id = req.args.params.id;
- var product = this.make("prodotti");
- product.load$(id, done);
- });
- // LIST ALL
- seneca.add({
- area : "product",
- action : "fetch"
- }, function(args, done) {
- var products = this.make("prodotti");
- products.list$({}, done);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement