-
Notifications
You must be signed in to change notification settings - Fork 1
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
feature: populate game room with questions #293
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tuanthanh2067/seeksi/ALUvcYcmRoVGgrth47X52rikeDdR |
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.
I've merged my PR, can you please get new codes and update your code accordingly.
Another thing is that we don't have query to get questions but we will set questions to a game room. And then we will have a query to get the game room, which we have another issue for that.
yes I merged the latest PR and updated the codes in the last two commits |
const questions = await this.getQuestion(); | ||
const gameRoom = new GameRoom({ | ||
_id, | ||
answers, | ||
questions, |
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.
Can you save the Mongo Object ID of the questions only? I think it's specified in the schema.
seeksi/backend/src/schemas/GameRoom/GameRoom.js
Lines 6 to 12 in c6b6247
const gameRoom = new Schema({ | |
questions: { | |
type: [Schema.Types.ObjectId], | |
ref: "Questions", | |
}, | |
answers: [gameAnswerSchema], | |
}); |
Then, if we need to return the questions, we only need to populate()
them. This should be resolved in #295 if I'm not mistaken.
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.
Yeah sorry about my mistake earlier, we will store Id and then I'll populate it later when I get game room
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.
Awesome! 💯
Related issue
Fixes #248
Type of Change
Description
Notes:
I'll take care of it afterconflicts are resolvedcurrently allows to create another gameRoom and overwrite the gameRoomID in a chatRoom, if there is any restriction please tell me.users are allowed to play the game only 1 timeAdd questionAPI and query to test getQuestion()
![image](https://user-images.githubusercontent.com/42020668/158042384-ff051f6a-6834-4fef-931b-cef815360dac.png)
Pupulate gameRoom with 10 questions from questionAPI.getQuestion()
![image](https://user-images.githubusercontent.com/42020668/158093334-9fc40c8c-4191-482f-8a26-f783ac705c14.png)
Add createGameRoom mutation and getGameRoomById for manually testing.
![image](https://user-images.githubusercontent.com/42020668/158042428-92c18c60-2eb4-44c6-a948-3541a679b3c4.png)
![image](https://user-images.githubusercontent.com/42020668/158042437-ea24b8aa-90ac-45d4-b188-7dfe0211f7b1.png)
Screenshot
First, we have a chatRoom that has no gameRoom
![image](https://user-images.githubusercontent.com/42020668/158093397-dc585b52-e541-4df1-98ed-56c12b0c6d80.png)
Grab the _id (62114891f032396dff000000) and try to create a new gameRoom with createGameRoom mutation
![image](https://user-images.githubusercontent.com/42020668/158093455-43739dd3-dfe2-4408-8bea-6a1b9bd29bf1.png)
-> If the muta creates the gameRoom successfully, it will return the gameRoom id
Otherwise throws error
![image](https://user-images.githubusercontent.com/42020668/158045855-2f08efff-c7e9-4495-b968-1375e96368bd.png)
Use the getGameRoomById query to get the gameRoom we have just created
![image](https://user-images.githubusercontent.com/42020668/158093513-f23fd646-ff46-4dd3-b4c6-9402d5ca69a8.png)
Double check the gameRoom in mongo express => everything matches
![image](https://user-images.githubusercontent.com/42020668/158093554-66c532f9-053a-4861-9d86-8d37d32a535d.png)
Also the chatRoom
![image](https://user-images.githubusercontent.com/42020668/158093612-8728ce8b-c964-4dc8-91d4-5683526d6264.png)
Testing
Has this pull request been tested?
Yes
Please describe shortly how you tested it:
please refer to the screenshots
Note
The title of your PR should follow this format:
[Type](area): Title