Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
planner-team-one
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
21
Issues
21
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Евгений Положенцев
planner-team-one
Commits
dbf94cc2
Commit
dbf94cc2
authored
Dec 12, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#95
added check on edit of latest dateTimeTask dates
parent
523297dc
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
49 deletions
+113
-49
helpers.ts
planner-api/src/helpers.ts
+42
-16
copyTasks.ts
planner-api/src/routers/copyTasks.ts
+68
-30
usersReducer.js
planner-front/src/store/reducers/usersReducer.js
+3
-3
No files found.
planner-api/src/helpers.ts
View file @
dbf94cc2
...
@@ -45,6 +45,7 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
...
@@ -45,6 +45,7 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
relations
:{
relations
:{
executor
:
true
,
executor
:
true
,
author
:
true
,
author
:
true
,
dateTimeTasks
:
true
,
},
},
where
:[
where
:[
{
{
...
@@ -61,6 +62,7 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
...
@@ -61,6 +62,7 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
},
},
]})
]})
if
(
!
task
)
return
res
.
status
(
404
).
send
({
message
:
'task with possible user involved is not found'
})
if
(
!
task
)
return
res
.
status
(
404
).
send
({
message
:
'task with possible user involved is not found'
})
req
.
body
=
{...
req
.
body
,
task
:
task
}
if
(
task
?.
executor
?.
token
===
token
)
{
if
(
task
?.
executor
?.
token
===
token
)
{
req
.
body
=
{...
req
.
body
,
executorStatus
:
true
}
req
.
body
=
{...
req
.
body
,
executorStatus
:
true
}
}
}
...
@@ -83,24 +85,30 @@ export const authAuthorOrExecutorOfDateTimeTask = async(req: Request,res: Respon
...
@@ -83,24 +85,30 @@ export const authAuthorOrExecutorOfDateTimeTask = async(req: Request,res: Respon
}
else
if
(
req
.
params
?.
dateTimeTaskId
){
}
else
if
(
req
.
params
?.
dateTimeTaskId
){
dateTimeTaskId
=
req
.
params
.
dateTimeTaskId
dateTimeTaskId
=
req
.
params
.
dateTimeTaskId
}
else
return
res
.
send
({
vessage
:
"there are no dateTimeTaskId found"
})
}
else
return
res
.
send
({
vessage
:
"there are no dateTimeTaskId found"
})
const
task
=
await
dataSource
const
task
=
await
dataSource
.
createQueryBuilder
()
.
getRepository
(
Task
)
.
select
([
"task"
])
.
findOne
({
.
from
(
Task
,
"task"
)
relations
:
.
leftJoinAndSelect
(
"task.executor"
,
"user"
)
{
.
leftJoinAndSelect
(
"task.dateTimeTasks"
,
"dateTimeTask"
)
dateTimeTasks
:
true
,
.
leftJoinAndSelect
(
"task.author"
,
"users"
)
executor
:
true
,
.
where
(
"dateTimeTask.id = :dateTimeTaskId"
,
{
dateTimeTaskId
})
author
:
true
,
.
getOne
()
},
where
:{
dateTimeTasks
:
{
id
:
dateTimeTaskId
}
}})
if
(
!
task
)
return
res
.
status
(
404
).
send
({
message
:
'task with possible user involved is not found'
})
if
(
!
task
)
return
res
.
status
(
404
).
send
({
message
:
'task with possible user involved is not found'
})
req
.
body
=
{...
req
.
body
,
task
:
task
}
if
(
task
?.
executor
?.
token
===
token
)
{
if
(
task
?.
executor
?.
token
===
token
)
{
req
.
body
=
{...
req
.
body
,
executorStatus
:
true
}
req
.
body
=
{...
req
.
body
,
executorStatus
:
true
}
}
}
if
(
task
?.
author
?.
token
===
token
)
{
if
(
task
?.
author
?.
token
===
token
)
{
req
.
body
=
{...
req
.
body
,
authorStatus
:
true
}
req
.
body
=
{...
req
.
body
,
authorStatus
:
true
}
}
}
if
(
req
.
body
.
authorStatus
===
false
&&
req
.
body
.
executorStatus
===
false
)
return
res
.
status
(
403
).
send
({
Message
:
'user is not uathorized'
})
next
()
next
()
}
}
...
@@ -147,6 +155,25 @@ export const taskFinderById = async (taskId:string):Promise<null | Task>=>{
...
@@ -147,6 +155,25 @@ export const taskFinderById = async (taskId:string):Promise<null | Task>=>{
return
task
return
task
}
}
/** find task by dateTimeTaskId */
export
const
taskFinderByDateTimeTaskId
=
async
(
dateTimeTaskId
:
string
):
Promise
<
null
|
Task
>=>
{
const
task
=
await
dataSource
.
getRepository
(
Task
)
.
findOne
({
relations
:
{
dateTimeTasks
:
true
},
where
:{
dateTimeTasks
:
{
id
:
dateTimeTaskId
}
}})
return
task
}
/**member finder by userId and projectId, return one task */
/**member finder by userId and projectId, return one task */
export
const
memberFinderById
=
async
(
userId
:
string
,
projectId
:
string
)
=>
{
export
const
memberFinderById
=
async
(
userId
:
string
,
projectId
:
string
)
=>
{
...
@@ -171,8 +198,6 @@ export const memberFinderById = async (userId:string, projectId:string)=>{
...
@@ -171,8 +198,6 @@ export const memberFinderById = async (userId:string, projectId:string)=>{
}
}
export
let
transporter
=
nodemailer
.
createTransport
({
export
let
transporter
=
nodemailer
.
createTransport
({
service
:
'Yandex'
,
service
:
'Yandex'
,
// host: "smtp.yandex.ru",
// host: "smtp.yandex.ru",
...
@@ -185,5 +210,6 @@ export let transporter = nodemailer.createTransport({
...
@@ -185,5 +210,6 @@ export let transporter = nodemailer.createTransport({
})
})
export
const
FRONTEND_URL
=
'localhost:3000'
;
export
const
FRONTEND_URL
=
'localhost:3000'
\ No newline at end of file
planner-api/src/routers/copyTasks.ts
View file @
dbf94cc2
...
@@ -3,6 +3,7 @@ import {Task} from '../models/Task';
...
@@ -3,6 +3,7 @@ import {Task} from '../models/Task';
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
DateTimeTask
}
from
'../models/DateTimeTask'
;
import
{
DateTimeTask
}
from
'../models/DateTimeTask'
;
import
{
auth
,
authAuthorOrExecutorOfDateTimeTask
,
authAuthorOrExecutorOfTask
,
taskFinderById
}
from
'../helpers'
;
import
{
auth
,
authAuthorOrExecutorOfDateTimeTask
,
authAuthorOrExecutorOfTask
,
taskFinderById
}
from
'../helpers'
;
import
{
info
}
from
'console'
;
const
router
:
Router
=
express
.
Router
();
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
...
@@ -24,7 +25,7 @@ router.post("/make-copy",authAuthorOrExecutorOfTask, async(req:Request, res:Resp
...
@@ -24,7 +25,7 @@ router.post("/make-copy",authAuthorOrExecutorOfTask, async(req:Request, res:Resp
/** change date time of copy of task in calendar view */
/** change date time of copy of task in calendar view */
router
.
put
(
"/change-copy/:dateTimeTaskId"
,
authAuthorOrExecutorOfTask
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
put
(
"/change-copy/:dateTimeTaskId"
,
authAuthorOrExecutorOfTask
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
{
dateTimeTaskId
}
=
req
.
params
const
{
dateTimeTaskId
}
=
req
.
params
const
{
executorStatus
,
taskId
,
dateTimeStart
,
dateTimeDue
,
description
,
title
,
priority
}
=
req
.
body
const
{
executorStatus
,
authorStatus
,
task
,
dateTimeStart
,
dateTimeDue
,
description
,
title
,
priority
}
=
req
.
body
const
dateTimeTask
=
await
dataSource
const
dateTimeTask
=
await
dataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
.
select
(
'dateTimeTask'
)
.
select
(
'dateTimeTask'
)
...
@@ -32,11 +33,40 @@ router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req
...
@@ -32,11 +33,40 @@ router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req
.
where
(
"dateTimeTask.id = :dateTimeTaskId"
,{
dateTimeTaskId
})
.
where
(
"dateTimeTask.id = :dateTimeTaskId"
,{
dateTimeTaskId
})
.
getOne
()
.
getOne
()
if
(
!
dateTimeTask
)
return
res
.
send
({
message
:
"such dateTimeTask does not exists"
})
if
(
!
dateTimeTask
)
return
res
.
send
({
message
:
"such dateTimeTask does not exists"
})
let
allDateTimeTasks
=
task
.
dateTimeTasks
if
(
allDateTimeTasks
.
length
===
1
)
{
if
(
executorStatus
&&
!
authorStatus
)
{
if
(
task
.
dateTimeDeadLine
>
dateTimeStart
&&
task
.
dateTimeDeadLine
>
dateTimeDue
)
{
dateTimeTask
.
dateTimeStart
=
dateTimeStart
dateTimeTask
.
dateTimeDue
=
dateTimeDue
await
dateTimeTask
.
save
()
return
res
.
send
({
message
:
"copyTask changed succesfully"
})
}
}
else
if
(
authorStatus
){
dateTimeTask
.
dateTimeStart
=
dateTimeStart
dateTimeTask
.
dateTimeDue
=
dateTimeDue
await
dateTimeTask
.
save
()
return
res
.
send
({
message
:
"copyTask changed succesfully"
})
}
}
else
if
(
allDateTimeTasks
.
length
>
1
)
{
let
dateTimeTasks
=
task
.
dateTimeTasks
dateTimeTasks
.
sort
(
function
(
a
:
DateTimeTask
,
b
:
DateTimeTask
)
{
return
(
a
.
dateTimeDue
>
b
.
dateTimeDue
)
?
-
1
:
((
a
.
dateTimeDue
<
b
.
dateTimeDue
)
?
1
:
0
);
});
let
latestDueDateCopyTask
=
dateTimeTasks
[
0
]
if
(
latestDueDateCopyTask
.
id
===
dateTimeTaskId
)
if
(
authorStatus
)
{
dateTimeTask
.
dateTimeStart
=
dateTimeStart
dateTimeTask
.
dateTimeDue
=
dateTimeDue
await
dateTimeTask
.
save
()
return
res
.
send
({
message
:
"copyTask changed succesfully"
})
}
}
dateTimeTask
.
dateTimeStart
=
dateTimeStart
dateTimeTask
.
dateTimeStart
=
dateTimeStart
dateTimeTask
.
dateTimeDue
=
dateTimeDue
dateTimeTask
.
dateTimeDue
=
dateTimeDue
await
dateTimeTask
.
save
()
await
dateTimeTask
.
save
()
const
task
=
await
taskFinderById
(
taskId
)
if
(
!
task
)
return
res
.
status
(
404
).
send
({
Message
:
'task not found'
})
task
.
title
=
title
;
task
.
title
=
title
;
task
.
description
=
description
;
task
.
description
=
description
;
task
.
priority
=
priority
;
task
.
priority
=
priority
;
...
@@ -46,36 +76,44 @@ router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req
...
@@ -46,36 +76,44 @@ router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req
/**delete copyTask by dateTimeTaskId */
/**delete copyTask by dateTimeTaskId */
router
.
delete
(
'/:dateTimeTaskId'
,
authAuthorOrExecutorOfDateTimeTask
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
|
void
>=>
{
router
.
delete
(
'/:dateTimeTaskId'
,
authAuthorOrExecutorOfDateTimeTask
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
|
void
>=>
{
const
{
executorStatus
,
authorStatus
}
=
req
.
body
const
{
authorStatus
,
executorStatus
,
task
}
=
req
.
body
if
(
executorStatus
){
const
{
dateTimeTaskId
}
=
req
.
params
const
{
dateTimeTaskId
}
=
req
.
params
const
task
=
await
dataSource
.
getRepository
(
Task
)
.
findOne
({
relations
:
{
dateTimeTasks
:
true
},
where
:{
dateTimeTasks
:
{
id
:
dateTimeTaskId
}
}})
if
(
!
task
)
return
res
.
status
(
404
).
send
({
message
:
'task with possible copytask involved is not found'
})
if
(
executorStatus
)
{
const
deadLine
=
task
?.
dateTimeDeadLine
let
dateTimeTasks
=
task
?.
dateTimeTasks
let
dateTimeTasks
=
task
?.
dateTimeTasks
const
deadlineTaskCopy
=
dateTimeTasks
?.
map
(
dateTimeTask
=>
{
if
(
dateTimeTask
.
dateTimeDue
===
deadLine
)
return
dateTimeTask
})
if
(
authorStatus
||
executorStatus
)
{
}
if
(
dateTimeTasks
.
length
>
1
)
{
dateTimeTasks
.
sort
(
function
(
a
:
DateTimeTask
,
b
:
DateTimeTask
)
{
return
(
a
.
dateTimeDue
>
b
.
dateTimeDue
)
?
-
1
:
((
a
.
dateTimeDue
<
b
.
dateTimeDue
)
?
1
:
0
);
});
const
latestDueDateCopyTask
=
dateTimeTasks
[
0
]
await
myDataSource
await
myDataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
.
delete
()
.
delete
()
.
from
(
DateTimeTask
)
.
from
(
DateTimeTask
)
.
where
(
"id = :dateTimeTaskId"
,
{
dateTimeTaskId
})
.
where
(
"id = :dateTimeTaskId"
,
{
dateTimeTaskId
})
.
execute
()
.
execute
()
if
(
latestDueDateCopyTask
.
id
===
dateTimeTaskId
)
{
task
.
dateTimeDeadLine
=
dateTimeTasks
[
1
].
dateTimeDue
await
task
.
save
()
}
else
{
task
.
dateTimeDeadLine
=
dateTimeTasks
[
0
].
dateTimeDue
}
return
res
.
send
({
message
:
"copyTask delete succesfully"
})
return
res
.
send
({
message
:
"copyTask delete succesfully"
})
}
}
}
if
(
dateTimeTasks
.
length
===
1
)
{
if
(
authorStatus
)
{
Task
.
remove
(
task
)
return
res
.
send
({
message
:
"task delete succesfully"
})
}
else
{
return
res
.
send
({
message
:
"not uathorized to delete task"
})
}
}
}
}
)
)
...
...
planner-front/src/store/reducers/usersReducer.js
View file @
dbf94cc2
...
@@ -14,15 +14,15 @@ const usersReducer = (state = initialState, action) => {
...
@@ -14,15 +14,15 @@ const usersReducer = (state = initialState, action) => {
case
REGISTER_USER_REQUEST
:
case
REGISTER_USER_REQUEST
:
return
{...
state
,
loading
:
true
};
return
{...
state
,
loading
:
true
};
case
REGISTER_USER_SUCCESS
:
case
REGISTER_USER_SUCCESS
:
console
.
log
(
"register.user "
+
action
)
console
.
log
(
"register.user "
,
action
)
return
{...
state
,
loading
:
false
};
return
{...
state
,
loading
:
false
};
case
REGISTER_USER_FAILURE
:
case
REGISTER_USER_FAILURE
:
return
{...
state
,
loading
:
false
,
registerError
:
action
.
error
};
return
{...
state
,
loading
:
false
,
registerError
:
action
.
error
};
case
LOGIN_USER_SUCCESS
:
case
LOGIN_USER_SUCCESS
:
console
.
log
(
"action.user "
+
action
)
console
.
log
(
"action.user "
,
action
)
return
{...
state
,
user
:
action
.
user
};
return
{...
state
,
user
:
action
.
user
};
case
LOGIN_USER_FAILURE
:
case
LOGIN_USER_FAILURE
:
console
.
log
(
"action.error"
+
action
.
error
)
console
.
log
(
"action.error"
,
action
.
error
)
return
{...
state
,
loginError
:
action
.
error
};
return
{...
state
,
loginError
:
action
.
error
};
case
LOGOUT_USER_SUCCESS
:
case
LOGOUT_USER_SUCCESS
:
return
{...
state
,
user
:
null
};
return
{...
state
,
user
:
null
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment