PHP -> NodeJS

PHP -> NodeJS

FreedyFreedy Posts: 30Questions: 4Answers: 0

Hi,
I'm converting a project from PHP to NodeJS, in PHP I'm passing a variable to PHP how do I do this in node?

JS side:
        editor = new $.fn.dataTable.Editor( {
            ajax: {
                url: 'php/table.MuffinLift.php',
                type: 'POST',
                data: function ( d ) {
                    d.WorkOrder = JobNumber;
                }
            },

PHP side:
    ->debug( false )
    ->where( 'MuffinLift.JobNumber', $_POST['WorkOrder']) 
    ->process( $_POST )
    ->json();

Replies

  • allanallan Posts: 48,315Questions: 1Answers: 6,976 Site admin

    The NodeJS documentation for Editor shows how you can use its where conditions.

    Depending on the Node framework you are using the parameters are usually in req.body.WorkOrder, but you'd need to refer to the documentation for whatever framework you are using to confirm that.

    Allan

  • FreedyFreedy Posts: 30Questions: 4Answers: 0

    Hi,
    I've converted my PHP to Node.JS, the value entered from a bubble edit are
    not being sent to my Node server. In the server I can see the value entered in the
    values['MuffinLift']['PartsCut'] field. When I look in my data sent to the server:

    data: [{DT_RowId: "row_1782",…}]
    0: {DT_RowId: "row_1782",…}
    DT_RowId: "row_1782"
    MuffinLift: {ID: 1782, JobNumber: 8200, category: "Frame", part_name: "BACK PartsCut: 0

    PartsCut always is zero. The PHP version works fine.

    Any suggestion?

  • allanallan Posts: 48,315Questions: 1Answers: 6,976 Site admin

    I'd need a link to a page showing the issue and also be able to see your NodeJS code please?

    Thanks,
    Allan

  • FreedyFreedy Posts: 30Questions: 4Answers: 0

    Hi,

    Here is my NodeJS, I won't be able to do a linked page.

    /*
    * Controller for DB table Muffin
    * Created by http://editor.datatables.net/generator
    */
    let db = require('./db');
    let router = require('express').Router();
    
    let {
        Editor,
        Field,
        Validate,
        Format,
        Options
    } = require("datatables.net-editor-server");
    
    /*
    ** Setup Console Logging connection
    */
    
    let logger = winston.createLogger({
        level: 'info',
        format: winston.format.combine(
            winston.format.timestamp(),
            winston.format.printf(info => {
                return `${info.timestamp} ${info.level}: ${info.message}`;
            })
        ),
        transports: [new winston.transports.Console()]
    });
    
    router.all('/api/muffin', async function(req, res) {
        let editor = new Editor(db, 'muffinlift').fields(
            new Field( 'MuffinLift.ID' ),
            new Field( 'MuffinLift.JobNumber' ),
            new Field( 'MuffinLift.category' ),
            new Field( 'MuffinLift.part_name' ),
            new Field( 'MuffinLift.Part_Number' ),
            new Field( 'fma_customer.Name' ),
            new Field( 'MuffinLift.material' ),
            new Field( 'MuffinLift.description' ),
            new Field( 'MuffinLift.comments' ),
            new Field( 'MuffinLift.cut_wj' ),
            new Field( 'MuffinLift.component_name' ),
            new Field( 'employeedata.Name' ),
            new Field( 'MuffinLift.NumberPerUnit' ),        
            new Field( 'MuffinLift.TotalUnits' ),       
            new Field( 'MuffinLift.PartsRemaining' ),
            new Field( 'MuffinLift.ParentPartId' ),
            new Field( 'MuffinLift.PartsCut' ),
            new Field( 'MuffinLift.TotalCut' ),
            new Field( 'MuffinLift.isBeingEdited' )
        )
        .leftJoin ('muffinlift_orders', 'muffinlift_orders.OrderID', '=' , 'MuffinLift.JobNumber')
        .leftJoin ('fma_customer', 'fma_customer.FMA_CustomerID', '=', 'muffinlift_orders.Customer')
        .leftJoin ('employeedata', 'employeedata.EmployeeNameID', '=', 'MuffinLift.Employee')
        .where( 'jobnumber', '=', req.body.WorkOrder );
    
        await editor.process(req.body);
        res.json(editor.data());
    });
    
    module.exports = router;
    

    Thanks.

  • allanallan Posts: 48,315Questions: 1Answers: 6,976 Site admin

    muffinlift in the constructor and MuffinLift in the list of fields. I'm not sure that will be the issue, but it would be the first thing to check. Make it all consistent with how your database is setup.

    Allan

  • FreedyFreedy Posts: 30Questions: 4Answers: 0

    Thanks, that was the problem.

    Thanks again.

Sign In or Register to comment.