Skip to content

Commit 5cb74a0

Browse files
authored
Merge pull request #1 from Vividh25/feat/userBadges
resolved merge conflicts
2 parents 4b10978 + 53604b9 commit 5cb74a0

File tree

14 files changed

+128
-17
lines changed

14 files changed

+128
-17
lines changed

controllers/tasks.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,33 @@ const updateTask = async (req, res) => {
123123
}
124124
}
125125

126+
/**
127+
* Updates self task status
128+
* @param req {Object} - Express request object
129+
* @param res {Object} - Express response object
130+
*/
131+
const updateTaskStatus = async (req, res) => {
132+
try {
133+
const taskId = req.params.id
134+
const { id: userId } = req.userData
135+
const task = await tasks.fetchSelfTask(taskId, userId)
136+
137+
if (task.taskNotFound) return res.boom.notFound('Task doesn\'t exist')
138+
if (task.notAssignedToYou) return res.boom.forbidden('This task is not assigned to you')
139+
140+
await tasks.updateTask(req.body, taskId)
141+
return res.json({ message: 'Task updated successfully!' })
142+
} catch (err) {
143+
logger.error(`Error while updating task status : ${err}`)
144+
return res.boom.badImplementation('An internal server error occured')
145+
}
146+
}
147+
126148
module.exports = {
127149
addNewTask,
128150
fetchTasks,
129151
updateTask,
130152
getSelfTasks,
131-
getUserTasks
153+
getUserTasks,
154+
updateTaskStatus
132155
}

firebase.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
"port": 4000
99
}
1010
}
11-
}
11+
}

middlewares/validators/auctions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const joi = require('joi')
22

33
const createAuction = async (req, res, next) => {
4-
const schema = joi.object().keys({
4+
const schema = joi.object().strict().keys({
55
item_type: joi.string().required(),
66
quantity: joi.number().required(),
77
initial_price: joi.number().required(),
@@ -17,7 +17,7 @@ const createAuction = async (req, res, next) => {
1717
}
1818

1919
const placeBid = async (req, res, next) => {
20-
const schema = joi.object().keys({
20+
const schema = joi.object().strict().keys({
2121
bid: joi.number().required()
2222
})
2323
try {

middlewares/validators/featureFlags.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const joi = require('joi')
22

33
const validateFeatureFlag = async (req, res, next) => {
4-
const schema = joi.object().keys({
4+
const schema = joi.object().strict().keys({
55
name: joi.string().required(),
66
title: joi.string().required(),
77
created_at: joi.number().optional(),
@@ -22,7 +22,7 @@ const validateFeatureFlag = async (req, res, next) => {
2222
}
2323

2424
const updateFeatureFlags = async (req, res, next) => {
25-
const schema = joi.object().keys({
25+
const schema = joi.object().strict().keys({
2626
title: joi.string().optional(),
2727
config: joi.object({
2828
enabled: joi.boolean().required()

middlewares/validators/recruiter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const joi = require('joi')
22

33
const validateRecruiter = async (req, res, next) => {
4-
const schema = joi.object().keys({
4+
const schema = joi.object().strict().keys({
55
company: joi.string().required(),
66
first_name: joi.string().required(),
77
last_name: joi.string().required(),

middlewares/validators/stocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const joi = require('joi')
22

33
const createStock = async (req, res, next) => {
4-
const schema = joi.object().keys({
4+
const schema = joi.object().strict().keys({
55
name: joi.string().required(),
66
quantity: joi.number().required(),
77
price: joi.number().required()

middlewares/validators/tasks.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const joi = require('joi')
22
const { DINERO, NEELAM } = require('../../constants/wallets')
33

44
const createTask = async (req, res, next) => {
5-
const schema = joi.object().keys({
5+
const schema = joi.object().strict().keys({
66
title: joi.string().required(),
77
purpose: joi.string().optional(),
88
featureUrl: joi.string().optional(),
@@ -36,7 +36,7 @@ const createTask = async (req, res, next) => {
3636
}
3737

3838
const updateTask = async (req, res, next) => {
39-
const schema = joi.object().keys({
39+
const schema = joi.object().strict().keys({
4040
title: joi.string().optional(),
4141
purpose: joi.string().optional(),
4242
featureUrl: joi.string().optional(),
@@ -68,7 +68,22 @@ const updateTask = async (req, res, next) => {
6868
}
6969
}
7070

71+
const updateSelfTask = async (req, res, next) => {
72+
const schema = joi.object().strict().keys({
73+
status: joi.string().optional(),
74+
percentCompleted: joi.number().optional()
75+
})
76+
try {
77+
await schema.validateAsync(req.body)
78+
next()
79+
} catch (error) {
80+
logger.error(`Error validating updateSelfTask payload : ${error}`)
81+
res.boom.badRequest(error.details[0].message)
82+
}
83+
}
84+
7185
module.exports = {
7286
createTask,
73-
updateTask
87+
updateTask,
88+
updateSelfTask
7489
}

middlewares/validators/trading.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const joi = require('joi')
22

33
const newTrade = async (req, res, next) => {
4-
const schema = joi.object().keys({
4+
const schema = joi.object().strict().keys({
55
stockId: joi.string().required(),
66
tradeType: joi.string().required(),
77
stockName: joi.string().required(),

middlewares/validators/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const joi = require('joi')
22
const { userStatusEnum } = require('../../constants/users')
33

44
const updateUser = async (req, res, next) => {
5-
const schema = joi.object().keys({
5+
const schema = joi.object().strict().keys({
66
phone: joi.string().optional(),
77
email: joi.string().optional(),
88
username: joi.string().optional(),

models/tasks.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const updateTask = async (taskData, taskId = null) => {
3030

3131
return result
3232
} catch (err) {
33-
logger.error('Error in creating task', err)
33+
logger.error('Error in updating task', err)
3434
throw err
3535
}
3636
}
@@ -94,6 +94,25 @@ const fetchTask = async (taskId) => {
9494
}
9595
}
9696

97+
/**
98+
* Fetch assigned self task
99+
* @param taskId { string }: taskId which will be used to fetch the task
100+
* @param id { string }: id to check task is assigned to self or not
101+
* @return {Promsie<taskData|Object>}
102+
*/
103+
const fetchSelfTask = async (taskId, userId) => {
104+
try {
105+
const task = await tasksModel.doc(taskId).get()
106+
const taskData = task.data()
107+
if (!taskData) return { taskNotFound: true }
108+
if (userId !== taskData.assignee) return { notAssignedToYou: true }
109+
return { taskData: await fromFirestoreData(taskData) }
110+
} catch (err) {
111+
logger.error('Error retrieving self task data', err)
112+
throw err
113+
}
114+
}
115+
97116
/**
98117
* Fetch all the active and blocked tasks of the user
99118
*
@@ -165,5 +184,6 @@ module.exports = {
165184
fetchUserTasks,
166185
fetchUserActiveAndBlockedTasks,
167186
fetchUserCompletedTasks,
168-
fetchActiveTaskMembers
187+
fetchActiveTaskMembers,
188+
fetchSelfTask
169189
}

0 commit comments

Comments
 (0)