admin管理员组

文章数量:815076

如何在节点js中获取用户的所有数据

我在节点js上遇到问题。我在节点js上还没有做很多工作。问题是我创建了用于注册的注册表和用于获取PAN卡详细信息的PAN卡表单。我的PAN卡的数据已被所有用户显示。而且我还能够通过PAN卡ID正确显示PAN卡数据。但是我想显示一个用户的所有PAN卡。这样每个用户都可以看到他们所有的PAN卡。该用户已申请的。一些细节在下面给出

请帮助我。我怎样才能做到这一点我可以对gate方法应用什么逻辑,以便可以正确显示用户应用的所有PAN卡。

pan card应用代码发布方法

// @route    POST pan/newpan
// @desc     Create a post
// @access   Private
router.post(
  '/newpan',
  [
    auth,
    [
      check('areaoffice', 'Area Office is required')
        .not()
        .isEmpty(),
      check('aocode', 'aocode is required')
        .not()
        .isEmpty(),
      check('ao', 'Ao is required')
        .not()
        .isEmpty(),
      check('range', 'Range is required')
        .not()
        .isEmpty(),
      check('aonumber', 'AO number is required')
        .not()
        .isEmpty(),
      check('application', 'Application Type is required')
        .not()
        .isEmpty(),
      check('old_pan', 'Old Pan Type is required')
        .not()
        .isEmpty(),
      check('category', 'Category Type is required')
        .not()
        .isEmpty(),
      check('applicant', 'Applicant Type is required')
        .not()
        .isEmpty(),
      check('firstname', 'First name is required')
        .not()
        .isEmpty(),
      check('middlename', 'Middle Name is required')
        .not()
        .isEmpty(),
      check('lastname', 'Last Name is required')
        .not()
        .isEmpty(),
      check('ffirstname', 'Father first Name is required')
        .not()
        .isEmpty(),
      check('fmiddlename', 'Father Middle Name is required')
        .not()
        .isEmpty(),
      check('flastname', 'Father Last Name is required')
        .not()
        .isEmpty(),
      check('mfirstname', 'Mother First Name is required')
        .not()
        .isEmpty(),
      check('mmiddlename', 'Mother Middle Name is required')
        .not()
        .isEmpty(),
      check('mlastname', 'Mother Last Name is required')
        .not()
        .isEmpty(),
      check('cardHolder', 'Card Holder Name is required')
        .not()
        .isEmpty(),
      check('dob', 'Date of Birth is required')
        .not()
        .isEmpty(),
      check('contect_number', 'Contact Number is required')
        .not()
        .isEmpty(),
      check('email', 'Email is required')
        .not()
        .isEmpty(),
      check('proofid', 'Id Proof is required')
        .not()
        .isEmpty(),
      check('proofadd', 'Id Address is required')
        .not()
        .isEmpty(),
      check('proofdob', 'Id Date of Birth is required')
        .not()
        .isEmpty(),
      check('gender', 'Gender is required')
        .not()
        .isEmpty(),
      check('adhar_number', 'Adhar Number is required')
        .not()
        .isEmpty(),
      check('address_f', 'Address is required')
        .not()
        .isEmpty(),
      check('address_v', 'Address is required')
        .not()
        .isEmpty(),
      check('address_p', 'Post office Address is required')
        .not()
        .isEmpty(),
      check('address_divi', 'Address of Division is required')
        .not()
        .isEmpty(),
      check('address_d', 'Address of Dist. is required')
        .not()
        .isEmpty(),
      check('state', 'State is required')
        .not()
        .isEmpty(),
      check('pin_code', 'Pin Code is required')
        .not()
        .isEmpty()
    ]
  ],
  async (req, res, next) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) {
      return res.status(400).json({ msg: errors.array() });
    }

    try {
      const user = await users.findById(req.user.id).select('-password');
      let image = req.files.image;
      let pdf = req.files.pdf;
      let sig = req.files.sig;
      const newPan = new Pan({
        areaoffice: req.body.areaoffice,
        aocode: req.body.aocode,
        ao: req.body.ao,
        range: req.body.range,
        aonumber: req.body.aonumber,
        application: req.body.application,
        old_pan: req.body.old_pan,
        category: req.body.category,
        applicant: req.body.applicant,
        firstname: req.body.firstname,
        middlename: req.body.middlename,
        lastname: req.body.lastname,
        ffirstname: req.body.ffirstname,
        fmiddlename: req.body.fmiddlename,
        flastname: req.body.flastname,
        mfirstname: req.body.mfirstname,
        mmiddlename: req.body.mmiddlename,
        mlastname: req.body.mlastname,
        cardHolder: req.body.cardHolder,
        dob: req.body.dob,
        contect_number: req.body.contect_number,
        email: req.body.email,
        proofid: req.body.proofid,
        proofadd: req.body.proofadd,
        proofdob: req.body.proofdob,
        gender: req.body.gender,
        adhar_number: req.body.adhar_number,
        address_f: req.body.address_f,
        address_v: req.body.address_v,
        address_p: req.body.address_p,
        address_divi: req.body.address_divi,
        address_d: req.body.address_d,
        state: req.body.state,
        pin_code: req.body.pin_code,
        image: image.name,
        pdf: pdf.name,
        sig: sig.name,
        imagepath: image.tempFilePath,
        username: user.username,
        avatar: user.avatar,
        user: req.user.id
      });

      image.mv(`./client/public/panImages/${image.name}`, function (err) {
        if (err) {
          return res.status(500).json({ msg: 'something Error' });
        }
      })
      sig.mv(`./client/public/panImages/${sig.name}`, function (err) {
        if (err) {
          return res.status(500).json({ msg: 'something Error' });
        }
      })
      pdf.mv(`./client/public/panImages/${pdf.name}`, function (err) {
        if (err) {
          return res.status(500).json({ msg: 'something Error' });
        }
      })
      const pan = await newPan.save();

      res.json(pan);
    } catch (err) {
      console.error(err.message);
      res.status(500).send('Server Error');
    }
  }
);

在mongoDB中的全盘结果

  {
    "_id": "5eb81c00265d1a2404b2d5e6",
    "areaoffice": "JKHJHKJ",
    "aocode": "FADSF",
    "ao": "FDAFDF",
    "range": "ADSFAS",
    "aonumber": "JLK",
    "application": "KJLKJ",
    "old_pan": "KJLKJ",
    "category": "KJLKJ",
    "applicant": "KJLKJ",
    "firstname": "KJLJ",
    "middlename": "JJKHJK",
    "lastname": "JHJKHK",
    "ffirstname": "JHKJH",
    "fmiddlename": "JHJH",
    "flastname": "JHJHK",
    "mfirstname": "JHJKHK",
    "mmiddlename": "HKJHKJ",
    "mlastname": "KJKJHJKLH",
    "cardHolder": "SATENDRA SINGH",
    "dob": "HJKJHKJH",
    "contect_number": "HJKHLKJ",
    "email": "JHKJHK",
    "proofid": "JKHJHK",
    "proofadd": "JHJKHJ",
    "proofdob": "JHKJ",
    "gender": "HJKHJ",
    "adhar_number": "JHJKLH",
    "address_f": "JKHKJH",
    "address_v": "JKHKJH",
    "address_p": "JKHJK",
    "address_divi": "FG",
    "address_d": "HUHUJK",
    "state": "UIGHBJKJK",
    "pin_code": "JKHKJHJKJ",
    "image": "Festivals-and-Occasions.jpg",
    "pdf": "sample.pdf",
    "sig": "showcase.jpg",
    "username": "s",
    "user": "5eb2fa29d37d9a08741621c8",
    "date": "2020-05-10T15:21:36.675Z",
    "__v": 0
}

获取所有平底锅数据方法

// @route    GET pan/pans
// @desc     Get all pans
// @access   Private
router.get('/pans', adminAuth, async (req, res) => {
  try {
    const pans = await Pan.find().sort({ data: -1 });
    res.json(pans)
  } catch (error) {
    console.error(error.message)
    res.status(500).send('Server Error')
  }
});

获取用户个人资料数据

{
    "_id": "5eb2fa29d37d9a08741621c8",
    "username": "s",
    "name": "s",
    "email": "[email protected]",
    "mobile": "s",
    "address": "s",
    "city": "s",
    "state": "s",
    "zipCode": "s",
    "date": "2020-05-06T17:55:53.001Z",
    "__v": 0
}
回答如下:

要获取特定用户的平移详细信息,您应该在路由中获取user_id,然后可以在Pan.find中传递该user_id。>

router.get('/pans/:user_id', adminAuth, async (req, res) => {
  try {
    var query = {}
    if (req.params.user_id != "" && req.params.user_id != undefined {
     query.user_id = req.params.user_id
    }
    const pans = await Pan.find(query).sort({ data: -1 });
    res.json(pans)
  } catch (error) {
    console.error(error.message)
    res.status(500).send('Server Error')
  }
});

本文标签: 如何在节点js中获取用户的所有数据