Commit 9d00e81b authored by Ermolaev Timur's avatar Ermolaev Timur

#17 Реализовал задачи в фикстуре

parent 402aad11
...@@ -40,10 +40,48 @@ Data Source has been initialized! ...@@ -40,10 +40,48 @@ Data Source has been initialized!
await user.save(); await user.save();
users.push(user) users.push(user)
} }
const tasks = []
type taskFinishType = "opened" | "done" |"failed";
type priorityType = "A" | "B" |"C";
const priorities:priorityType[] = ["A", "B" , "C"]
const accomplish:taskFinishType[] = ["opened", "done" , "failed"]
for (let i = 0; i < 15; i++) {
if (i <= 10) {
const newTask = new Task();
newTask.title = `Buy ${faker.commerce.productName()}`;
newTask.description = faker.random.words(4);
newTask.executors = faker.helpers.arrayElements(users, randomIntFromInterval(0, 3));
newTask.dateTimeDue = faker.date.soon(randomIntFromInterval(1, 15));
newTask.dateTimeStart = faker.date.recent((randomIntFromInterval(0, 8)));
newTask.author = faker.helpers.arrayElement(users);
newTask.accomplish = faker.helpers.arrayElement(accomplish);
newTask.priority = faker.helpers.arrayElement(priorities);
await newTask.save();
tasks.push(newTask)
} else {
const newTask = new Task();
newTask.title = `Buy ${faker.commerce.productName()}`;
newTask.description = faker.random.words(4);
newTask.executors = faker.helpers.arrayElements(users, randomIntFromInterval(0, 3));
newTask.dateTimeDue = null;
newTask.dateTimeStart = null;
newTask.author = faker.helpers.arrayElement(users);
newTask.accomplish = accomplish[0];
newTask.priority = faker.helpers.arrayElement(priorities);
await newTask.save();
tasks.push(newTask)
}
}
console.log(`
==========================
}) Fixtures done!
==========================
`)
})
.catch((err) => { .catch((err) => {
......
...@@ -14,6 +14,7 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -14,6 +14,7 @@ const tasksReduсer = (state = initialState, action) => {
const newArr = [] const newArr = []
action.tasks.forEach((task)=>{ action.tasks.forEach((task)=>{
if (task.dateTimeStart && task.dateTimeDue) { if (task.dateTimeStart && task.dateTimeDue) {
if (new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() < (4 * 3600000)) {
const dateStart = task.dateTimeStart.split('T')[0] const dateStart = task.dateTimeStart.split('T')[0]
const timeStart = task.dateTimeStart.split('T')[1] const timeStart = task.dateTimeStart.split('T')[1]
const timeEnd = task.dateTimeDue.split('T')[1] const timeEnd = task.dateTimeDue.split('T')[1]
...@@ -34,6 +35,7 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -34,6 +35,7 @@ const tasksReduсer = (state = initialState, action) => {
endMinute: timeEndMinute, endMinute: timeEndMinute,
} }
} ) } )
}
} }
}) })
return {...state, loading: false, tasks: newArr}; return {...state, loading: false, tasks: newArr};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment