Skip to content

Commit 9678254

Browse files
refactor: merge conflict changes
2 parents 503dbc2 + c63b90b commit 9678254

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

controllers/tasks.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const tasks = require('../models/tasks')
2+
const { TASK_STATUS } = require('../constants/tasks')
23
/**
34
* Creates new task
45
*
@@ -52,8 +53,15 @@ const fetchTasks = async (req, res) => {
5253
*/
5354
const getUserTasks = async (req, res) => {
5455
try {
56+
const { status } = req.query
5557
const { username } = req.params
56-
const allTasks = await tasks.fetchUserTasks(username)
58+
let allTasks = []
59+
60+
if (!Object.values(TASK_STATUS).includes(status)) {
61+
return res.boom.notFound('Status not found!')
62+
}
63+
64+
allTasks = await tasks.fetchUserTasks(username, status ? [status] : [])
5765

5866
if (allTasks.userNotFound) {
5967
return res.boom.notFound('User doesn\'t exist')

test/integration/tasks.test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe('Tasks', function () {
173173
title: 'Assigned task',
174174
purpose: 'To Test mocha',
175175
featureUrl: '<testUrl>',
176-
type: 'Dev | Group',
176+
type: 'group',
177177
links: [
178178
'test1'
179179
],
@@ -185,11 +185,10 @@ describe('Tasks', function () {
185185
'd12',
186186
'd23'
187187
],
188-
participants: [appOwner.username],
188+
participants: ['user1'],
189189
completionAward: { [DINERO]: 3, [NEELAM]: 300 },
190190
lossRate: { [DINERO]: 1 },
191-
isNoteworthy: true,
192-
assignee: 'sagar'
191+
isNoteworthy: true
193192
}
194193
const { taskId } = await tasks.updateTask(assignedTask)
195194
const res = await chai
@@ -261,7 +260,7 @@ describe('Tasks', function () {
261260
it('Should return 200 when username is valid', function (done) {
262261
chai
263262
.request(app)
264-
.get(`/tasks/${appOwner.username}`)
263+
.get(`/tasks/${appOwner.username}?status=active`)
265264
.end((err, res) => {
266265
if (err) { return done(err) }
267266
expect(res).to.have.status(200)
@@ -284,7 +283,7 @@ describe('Tasks', function () {
284283
it('Should return 404 when username is invalid', function (done) {
285284
chai
286285
.request(app)
287-
.get('/tasks/dummyUser')
286+
.get('/tasks/dummyUser?status=active')
288287
.end((err, res) => {
289288
if (err) { return done(err) }
290289
expect(res).to.have.status(404)

utils/tasks.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11

22
const { getUsername, getUserId, getParticipantUsernames, getParticipantUserIds } = require('./users')
3+
const { TASK_TYPE } = require('../constants/tasks')
34

45
const fromFirestoreData = async (task) => {
56
if (!task) {
67
return task
78
}
8-
let { createdBy, assignee, participants } = task
9+
10+
let { createdBy, assignee, participants, type } = task
11+
912
if (createdBy) {
1013
createdBy = await getUsername(createdBy)
1114
}
15+
1216
if (assignee) {
1317
assignee = await getUsername(assignee)
1418
}
1519

16-
if (Array.isArray(participants)) {
20+
if (type === TASK_TYPE.GROUP) {
1721
participants = await getParticipantUsernames(participants)
1822
}
1923

0 commit comments

Comments
 (0)