-
Notifications
You must be signed in to change notification settings - Fork 0
crud-001-new #9
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
Open
bilalAhmad69
wants to merge
12
commits into
main
Choose a base branch
from
revert-8-revert-7-crud-001
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
crud-001-new #9
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
73db16a
Revert "Revert "Crud-001""
bilalAhmad69 550b5d3
chnages added in ignore file
bilalAhmad69 35c857f
gitigonore file changes
bilalAhmad69 85d3362
development.json file is deleted
bilalAhmad69 07b45b4
added unique property to email
bilalAhmad69 8ed7d92
removal for associate function
bilalAhmad69 744e84b
correct the file path in .ignore
bilalAhmad69 4d6dc24
user signIn and hashing functionality added
bilalAhmad69 4b83848
signIn route added
bilalAhmad69 11f8858
bcrypt library added
bilalAhmad69 d917c74
firebase integration
bilalAhmad69 ee7c70e
console.log removed
bilalAhmad69 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,3 +104,8 @@ dist | |
|
|
||
| # TernJS port file | ||
| .tern-port | ||
|
|
||
| # development.josn file | ||
| config/environments/ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| const ApiError = require("../utils/ApiError"); | ||
| const { db } = require("../config/environments/firebase.js"); | ||
| const { collection, getDocs } = require("firebase/firestore"); | ||
| module.exports = { | ||
| getAll: async (req, res, next) => { | ||
| try { | ||
| const users = collection(db, "users"); | ||
| const userDocs = await getDocs(users); | ||
| const userList = userDocs.docs.map((doc) => doc.data()); | ||
| res.send({ | ||
| code: 200, | ||
| success: true, | ||
| message: "Users list", | ||
| data: userList, | ||
| }); | ||
| } catch (err) { | ||
| next(err); | ||
| } | ||
| }, | ||
| }; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| const { User } = require("../models"); | ||
| const ApiError = require("../utils/ApiError"); | ||
| const bcrypt = require("bcrypt"); | ||
| module.exports = { | ||
| getAll: async (req, res, next) => { | ||
| try { | ||
| const users = await User.findAll({ where: { archive: false } }); | ||
| if (!users.length) throw new ApiError(404, "User not found"); | ||
| res.send({ | ||
| code: 200, | ||
| success: true, | ||
| message: "Users list", | ||
| data: users, | ||
| }); | ||
| } catch (err) { | ||
| next(err); | ||
| } | ||
| }, | ||
| getOne: async (req, res, next) => { | ||
| try { | ||
| const { id } = req.params; | ||
| const user = await User.findOne({ | ||
| where: { | ||
| id, | ||
| archive: false, | ||
| }, | ||
| }); | ||
| if (!user) { | ||
| throw new ApiError(404, "User not found"); | ||
| } | ||
| res.send({ | ||
| code: 200, | ||
| success: true, | ||
| message: "User data", | ||
| data: user, | ||
| }); | ||
| } catch (err) { | ||
| next(err); | ||
| } | ||
| }, | ||
| signIn: async (req, res, next) => { | ||
| try { | ||
| const { email, password } = req.body; | ||
| if (!email || !password) { | ||
| throw new ApiError(400, "Some data is missing"); | ||
| } | ||
| const user = await User.findOne({ | ||
| where: { email: email, archive: false }, | ||
| }); | ||
| if (!user) throw new ApiError(400, "Email or Password is Incorrect"); | ||
| const verifyPassword = await bcrypt.compare(password, user.password); | ||
| if (!verifyPassword) | ||
| throw new ApiError(400, "Email or Password is Incorrect"); | ||
| res.send({ | ||
| code: 200, | ||
| success: true, | ||
| message: "User Signed In SuccessFully", | ||
| data: user.email, | ||
| }); | ||
| } catch (err) { | ||
| next(err); | ||
| } | ||
| }, | ||
| create: async (req, res, next) => { | ||
| try { | ||
| const { name, email, password } = req.body; | ||
| if (!name || !email || !password) { | ||
| throw new ApiError(400, "Some data is missing"); | ||
| } | ||
| const genSalt = await bcrypt.genSalt(10); | ||
| const hashedPassword = await bcrypt.hash(password, genSalt); | ||
| const createdUser = await User.create({ | ||
| email, | ||
| password: hashedPassword, | ||
| name, | ||
| }); | ||
| res.send({ | ||
| code: 200, | ||
| success: true, | ||
| message: "User Created Succcessfully", | ||
| data: createdUser.email, | ||
| }); | ||
| } catch (err) { | ||
| next(err); | ||
| } | ||
| }, | ||
|
|
||
| archive: async (req, res, next) => { | ||
| try { | ||
| const { id } = req.params; | ||
|
|
||
| const user = await User.update( | ||
| { | ||
| archive: true, | ||
| }, | ||
| { | ||
| where: { id }, | ||
| } | ||
| ); | ||
| if (!user[0]) throw new ApiError(404, "User not found"); | ||
| res.send({ | ||
| code: 200, | ||
| success: true, | ||
| message: "User Removed", | ||
| data: user.email, | ||
| }); | ||
| } catch (err) { | ||
| next(err); | ||
| } | ||
| }, | ||
|
|
||
| update: async (req, res, next) => { | ||
| try { | ||
| const { id } = req.params; | ||
| const { name, password, email } = req.body; | ||
| const user = await User.update( | ||
| { | ||
| name, | ||
| email, | ||
| password, | ||
| }, | ||
| { | ||
| where: { id }, | ||
| } | ||
| ); | ||
| if (!user[0]) throw new ApiError(404, "User not found"); | ||
| res.send({ | ||
| code: 200, | ||
| success: true, | ||
| message: "User Updated Successfully", | ||
| data: user.email, | ||
| }); | ||
| } catch (err) { | ||
| next(err); | ||
| } | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| const { isEmailValid } = require("../utils/"); | ||
| ("use strict"); | ||
| module.exports = (sequelize, DataTypes) => { | ||
| const User = sequelize.define( | ||
| "User", | ||
| { | ||
| email: { | ||
| allowNull: false, | ||
| type: DataTypes.STRING, | ||
| unique: true, | ||
| validate: { isEmail: true }, | ||
| }, | ||
| password: { | ||
| type: DataTypes.STRING, | ||
| allowNull: false, | ||
| }, | ||
| name: { | ||
| type: DataTypes.STRING, | ||
| allowNull: false, | ||
| }, | ||
| archive: { | ||
| type: DataTypes.BOOLEAN, | ||
| }, | ||
| createdAt: { | ||
| allowNull: false, | ||
| type: DataTypes.DATE, | ||
| }, | ||
| updatedAt: { | ||
| allowNull: false, | ||
| type: DataTypes.DATE, | ||
| }, | ||
| }, | ||
| {} | ||
| ); | ||
|
|
||
| User.beforeCreate(async (user, options) => { | ||
| if (!isEmailValid(user.email)) throw new Error(); | ||
| if (!user.archive) user.archive = false; | ||
| }); | ||
| return User; | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nextalways take it to the next function, can you explain where is the next leading to in this case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the function(middleware) is located in app.js . when ever we pass the err obj to next function it take to the error handler function.