Code Monkey home page Code Monkey logo

paytm's People

Contributors

hkirat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

paytm's Issues

balance is not getting updated after a transfer

if i am making a transfer from one account to another then the request successfully returns the "Transfer Successful" message but the balance in the Database is not getting updated.
PS:
i have already tried the promise.all and findByIdandUpdate and findOneandUpdate nothing changes.
Screenshot 2024-02-01 231249
Screenshot 2024-02-01 231317

Code for updating the user information is wrong

In backend->routes->user

await User.updateOne(req.body, {
    id: req.userId
})

res.json({
    message: "Updated successfully"
})

updateOne takes filter as the first argument and updated information as the second argument, but opposite is been done here.

Balance not showing in the get request in account/balance

the error im getting is :SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at createStrictSyntaxError (C:\Users\nares\OneDrive\Desktop\Paytm\paytm\backend\node_modules\body-parser\lib\types\json.js:160:10)
at parse (C:\Users\nares\OneDrive\Desktop\Paytm\paytm\backend\node_modules\body-parser\lib\types\json.js:83:15)
at C:\Users\nares\OneDrive\Desktop\Paytm\paytm\backend\node_modules\body-parser\lib\read.js:128:18
at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
at invokeCallback (C:\Users\nares\OneDrive\Desktop\Paytm\paytm\backend\node_modules\raw-body\index.js:231:16)
at done (C:\Users\nares\OneDrive\Desktop\Paytm\paytm\backend\node_modules\raw-body\index.js:220:7)
at IncomingMessage.onEnd (C:\Users\nares\OneDrive\Desktop\Paytm\paytm\backend\node_modules\raw-body\index.js:280:7)
at IncomingMessage.emit (node:events:514:28)
at endReadableNT (node:internal/streams/readable:1359:12)

My code:const express=require("express");
const router=express.Router();
const zod=require("zod");
const {user}=require("../db");
const jwt=require("jsonwebtoken");
const {JWT_SEC}=require("../config");
const {authMiddleware}=require("../middleware")

const signupSchema=zod.object({
username:zod.string().email(),
password:zod.string(),
firstname:zod.string(),
lastname:zod.string(),
});

router.post("/signup",async(req,res)=>{
const body=req.body;
const {success}=signupSchema.safeParse(req.body);
if(!success){
return res.status(400).json({
message:" incorrect inputs"
})
}
const existingUser= await user.findOne({
username:body.username
})
if(existingUser){
return res.status(409).json({
message:"Email already taken"
})
}

const dbUser=await user.create({
    username:body.username,
    password:body.password,
    firstname:body.firstname,
    lastname:body.lastname,
});
const token=jwt.sign({
    userId:dbUser._id
},JWT_SEC)
res.status(201).json({
    message:"User created successfully",
    token:token
})

});

const signinBody = zod.object({
username: zod.string().email(),
password: zod.string()
})
router.post("/signin",async(req,res)=>{
const body=req.body;
const {success}=signinBody.safeParse(body);
if(!success){
return res.status(400).json({
message:" incorrect inputs"
})
}
const userRecord = await user.findOne({
username: req.body.username,
password: req.body.password
});

if (userRecord) {
    const token = jwt.sign({
        userId: userRecord._id
    }, JWT_SEC);

    res.json({
        token: token
    })
    return;
}
res.status(401).json({
    message: "Error while logging in"
})

})
const updateBody = zod.object({
password: zod.string().optional(),
firstName: zod.string().optional(),
lastName: zod.string().optional(),
})

router.put("/", authMiddleware, async (req, res) => {
const { success } = updateBody.safeParse(req.body)
if (!success) {
res.status(400).json({
message: "Error while updating information"
})
}

await user.updateOne(req.body, {
    id: req.userId
})

res.json({
    message: "Updated successfully"
})

})
router.get("/bulk", async (req, res) => {
const filter = req.query.filter || "";

const users = await user.find({
    $or: [{
        firstName: {
            "$regex": filter
        }
    }, {
        lastName: {
            "$regex": filter
        }
    }]
})

res.json({
    user: users.map(user => ({
        username: user.username,
        firstName: user.firstname,
        lastName: user.lastname,
        _id: user._id
    }))
})

})

module.exports=router;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.