Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.

Commit 40a77ec

Browse files
committed
Fixed the code according to new doc.
findById was the the function used to find the objects using sequelize by using ID. It has now been changed to findByPk.
1 parent 025b2db commit 40a77ec

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ DB_USER=root
22
DB_PASSWORD=null
33
DB_HOST=localhost
44
DB_PORT=5432
5-
DB_NAME=openrank-dev
5+
DB_NAME=coderplex-org
66
JWT_SECRET=jwt-secret

src/models/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ const models = {
2727
EventProfile: eventProfile(sequelize, Sequelize.DataTypes)
2828
}
2929

30-
console.log(models)
31-
3230
Object.keys(models).forEach(key => {
3331
if ('associate' in models[key]) {
3432
models[key].associate(models)

src/resolvers/authorization.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const isSelfDeleteAuth = combineResolvers(
1717
// { id },
1818
// { models, me },
1919
// ) => {
20-
// const message = await models.Message.findById(id, { raw: true });
20+
// const message = await models.Message.findByPk(id, { raw: true });
2121

2222
// if (message.userId !== me.id) {
2323
// throw new ForbiddenError('Not authenticated as owner.');

src/resolvers/user.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,24 @@ export default {
1515
Query: {
1616
allUsers: async (parent, args, { models }) => {
1717
const allUsers = await models.User.findAll()
18-
console.log(allUsers)
1918
return allUsers
2019
},
21-
user: async (parent, { id }, { models }) => {
22-
return await models.User.findById(id)
20+
userById: async (parent, { id }, { models }) => {
21+
return await models.User.findByPk(id)
22+
},
23+
userByEmail: async (parent, { email }, { models }) => {
24+
return await models.User.findOne({
25+
where: {
26+
email
27+
}
28+
})
2329
},
2430
currentUser: async (parent, args, { models, loggedInUser }) => {
2531
if (!loggedInUser) {
2632
return null;
2733
}
2834

29-
return await models.User.findById(loggedInUser.id);
35+
return await models.User.findByPk(loggedInUser.id);
3036
}
3137
},
3238

@@ -59,7 +65,7 @@ export default {
5965
updateUser: combineResolvers(
6066
isAuthenticated,
6167
async (parent, args, { models, loggedInUser }) => {
62-
const user = await models.User.findById(loggedInUser.id);
68+
const user = await models.User.findByPk(loggedInUser.id);
6369
return await user.update({ ...args });
6470
}
6571
),

src/schema/user.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { gql } from 'apollo-server-express'
33
export default gql`
44
extend type Query {
55
allUsers: [User!]
6-
user(id: ID!): User
6+
userById(id: ID!): User
7+
userByEmail(email: String!): User
78
currentUser: User
89
}
910

0 commit comments

Comments
 (0)