Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 1 addition & 37 deletions middlewares/validators/userStatus.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const Joi = require("joi");
const { userState, CANCEL_OOO } = require("../../constants/userStatus");
const threeDaysInMilliseconds = 172800000;

const validateUserStatusData = async (todaysTime, req, res, next) => {
const validUserStates = [userState.OOO, userState.ONBOARDING];
const validUserStates = [userState.ONBOARDING];

const statusSchema = Joi.object({
currentStatus: Joi.object().keys({
Expand All @@ -16,41 +15,6 @@ const validateUserStatusData = async (todaysTime, req, res, next) => {
.min(todaysTime)
.required()
.error(new Error(`The 'from' field must have a value that is either today or a date that follows today.`)),
until: Joi.any().when("state", {
is: userState.OOO,
then: Joi.number()
.min(Joi.ref("from"))
.required()
.error(
new Error(
`The 'until' field must have a value that is either 'from' date or a date that comes after 'from' day.`
)
),
otherwise: Joi.optional(),
}),
message: Joi.when("state", {
is: userState.IDLE,
then: Joi.string()
.required()
.error(new Error(`The value for the 'message' field is mandatory for IDLE State.`)),
otherwise: Joi.when(Joi.ref("state"), {
is: userState.OOO,
then: Joi.when(Joi.ref("until"), {
is: Joi.number().greater(
Joi.ref("from", {
adjust: (value) => value + threeDaysInMilliseconds,
})
),
then: Joi.string()
.optional()
.error(
new Error(`The value for the 'message' field is mandatory when State is OOO for more than three days.`)
),
otherwise: Joi.required(),
}),
otherwise: Joi.optional(),
}),
}),
}),
monthlyHours: Joi.object().keys({
committed: Joi.number().required(),
Expand Down
14 changes: 10 additions & 4 deletions test/fixtures/userStatus/userStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,22 @@ const activeStatus = {
},
};

const generateUserStatusData = (state, updatedAt, from, until = "", message = "") => {
return {
const generateUserStatusData = (state, updatedAt, from, until = "") => {
const data = {
currentStatus: {
state,
message,
from,
until,
updatedAt,
},
monthlyHours: {
committed: 40,
updatedAt,
},
};
if (until) {
data.currentStatus.until = until;
}
return data;
};

const generateStatusDataForState = (userId, state) => {
Expand Down
Loading
Loading