diff --git a/CHANGELOG.md b/CHANGELOG.md index dfa6a595..23b24f49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ with the current date and the next changes should go under a **[Next]** header. * Show queue name and location on queue page. ([@sgorse](https://github.com/sgorse) in [#81](https://github.com/illinois/queue/pull/81)) * Add ability to edit existing queues. ([@zwang180](https://github.com/zwang180) in [#78](https://github.com/illinois/queue/pull/78)) * Fix [#89](https://github.com/illinois/queue/issues/89) by only checking in one queue for another question being answered by the same user. ([@nwalters512](https://github.com/nwalters512) in [#90](https://github.com/illinois/queue/pull/90)) +* Correctly display number of questions when first creating a queue. ([@zwang180](https://github.com/zwang180) in [#84](https://github.com/illinois/queue/pull/84)) ## 28 March 2018 diff --git a/api/queues.js b/api/queues.js index 60f49d19..ad6425ae 100644 --- a/api/queues.js +++ b/api/queues.js @@ -49,11 +49,11 @@ router.post( ]), failIfErrors, ], - (req, res, _next) => { + async (req, res, _next) => { const { id: courseId } = res.locals.course const data = matchedData(req) - const queue = Queue.build({ + const queue = await Queue.create({ name: data.name, location: data.location, fixedLocation: data.fixedLocation === true, @@ -61,7 +61,9 @@ router.post( createdByUserId: res.locals.userAuthn.id, }) - queue.save().then(newQueue => res.status(201).json(newQueue)) + Queue.scope('questionCount') + .findById(queue.id) + .then(newQueue => res.status(201).json(newQueue)) } ) diff --git a/api/queues.test.js b/api/queues.test.js index 56991373..bdb7f7a1 100644 --- a/api/queues.test.js +++ b/api/queues.test.js @@ -102,6 +102,7 @@ describe('Queues API', () => { expect(res.statusCode).toBe(201) expect(res.body.name).toBe('CS225 Queue 2') expect(res.body.location).toBe('Where') + expect(res.body.questionCount).toBe(0) }) test('succeeds for course staff', async () => { @@ -112,6 +113,7 @@ describe('Queues API', () => { expect(res.statusCode).toBe(201) expect(res.body.name).toBe('CS225 Queue 2') expect(res.body.location).toBe('Where') + expect(res.body.questionCount).toBe(0) }) test('fails if name is missing', async () => {