Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing duplicate registration issue #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const registerUser = asyncHandler(async (req, res) => {
const userExists = await userModel.findOne({ user_ID });

if (userExists) {
res.status(400).json({ message: "User already exists" });
return res.status(400).json({ message: "User already exists" });
}
const message = "User registered Successfully"
const salt = await bcrypt.genSalt();
Expand Down
16 changes: 7 additions & 9 deletions register.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we not using async here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SanskarGosavi2003 which line exactly?

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const prompt = require("prompt-sync")();
const csv = require("csv-parser");
const fs = require("fs");
const results = [];
const fetch = require("node-fetch");
const fetch = require("node-fetch"); //in case you are using a newer version of node 20.0 and above comment out this line

//entering register url
console.log("Enter register url");
Expand All @@ -12,9 +12,9 @@ const accessToken = prompt();

fs.createReadStream('./export.csv').pipe(csv({}))
.on('data', (data) => results.push(data))
.on('end', async () => {
.on('end', () => {

results.forEach(async (elm) => {
results.forEach((elm) => {
const request = {
"name": elm.name,
"user_ID": elm.user_ID,
Expand All @@ -24,7 +24,7 @@ fs.createReadStream('./export.csv').pipe(csv({}))
console.log(request)
const bearer = accessToken;

const res = await fetch(registerURL,
fetch(registerURL,
{
method: 'POST',
headers: {
Expand All @@ -33,11 +33,9 @@ fs.createReadStream('./export.csv').pipe(csv({}))
},
body: JSON.stringify(request)
}
)

const data = await res.json();

console.log(data);
).then((data) => {
console.log(data.json())
})

})
});
Expand Down