0

im having trouble in creating an array in postman.

What I want is to post this in the request.body(postman/insomnia)..

{
    "nama": "tests",
    "afco_id": 2,
    "business_area_id": 10,
    "approval_level": [
        {
            "sequence_level": 1,
            "user_id": 1
        },
        {
            "sequence_level": 2,
            "user_id": 2
        },
        {
            "sequence_level": 3,
            "user_id": 3
        }
    ]
}

and this is my controller code:

const postApprovalMaster = async (req, res) => {
    return (
      db.Bb_t2_Approval.create(
        {
          nama: req.body.nama,
          afco_id: req.body.afco_id,
          business_area_id: req.body.business_area_id,
          approval_level: [req.body]
        },
        {
          include: [
            {
              model: db.Bb_t3_Approval_Level,
              as: "approval_level",
            },
            {
              model: db.Bb_t1_Organisasi,
              as: "afco",
            },
            {
              model: db.Bb_t1_Organisasi,
              as: "business_area",
            },
          ],
        }
      ).then((result) =>
          res.status(201).json({
            data: result,
            status: true,
            message: "Created new approval master success",
          })
        )
        .catch((err) => {
          res.status(400).json({
            status: false,
            message: err.message,
          })
        })
    )
  }

whenever i hardcoded the req.body into the controllers approval_level, it works just fine. but i dont want it like that can anyone help? thanks a lot I appreciate it

2 Answers 2

1

You can either try this

Solution 1

or if this doesnt work with node.js you can also try to just write the array attribute like this.

Solution 2

One of those should work.

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

I can't comment and I'd love to help but can you try to give more examples or explain a little more @Hafizh Farhandika

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.