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
1ac87806
Commit
1ac87806
authored
Nov 27, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#67
added adjust fixtures to new model
parent
55c98e79
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
29 deletions
+65
-29
fixtures.ts
planner-api/src/fixtures.ts
+64
-22
Task.ts
planner-api/src/models/Task.ts
+1
-7
No files found.
planner-api/src/fixtures.ts
View file @
1ac87806
...
@@ -5,11 +5,44 @@ import { faker } from '@faker-js/faker';
...
@@ -5,11 +5,44 @@ import { faker } from '@faker-js/faker';
import
{
priorityType
,
Task
,
taskFinishType
}
from
"./models/Task"
;
import
{
priorityType
,
Task
,
taskFinishType
}
from
"./models/Task"
;
import
{
Project
}
from
"./models/Project"
;
import
{
Project
}
from
"./models/Project"
;
import
{
Member
,
MemberRole
}
from
"./models/Member"
;
import
{
Member
,
MemberRole
}
from
"./models/Member"
;
import
{
DateTimeTask
}
from
"./models/DateTimeTask"
;
function
randomIntFromInterval
(
min
:
number
,
max
:
number
)
{
function
randomIntFromInterval
(
min
:
number
,
max
:
number
)
{
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
+
1
)
+
min
)
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
+
1
)
+
min
)
}
}
let
countUsers
=
0
let
countMembers
=
0
let
countProjects
=
0
let
countRolesProject
=
0
const
cycleThroughObject
=
(
countKey
:
number
,
objectObserve
:
any
):
MemberRole
=>
{
let
arrayOfKeys
=
Object
.
keys
(
objectObserve
)
let
keyOfObject
=
arrayOfKeys
[
countKey
]
let
valueOfKey
=
objectObserve
[
keyOfObject
]
countKey
++
if
(
countKey
===
arrayOfKeys
.
length
-
1
){
countKey
=
0
}
return
valueOfKey
}
const
cycleArrayOfMembers
=
(
countIndex
:
number
,
members
:
Member
[]):
Member
=>
{
let
member
=
members
[
countIndex
]
countIndex
++
if
(
countIndex
===
members
.
length
-
1
){
countIndex
=
0
}
return
member
}
const
cycleArrayOfProjects
=
(
countIndex
:
number
,
projects
:
Project
[]):
Project
=>
{
let
project
=
projects
[
countIndex
]
countIndex
++
if
(
countIndex
===
projects
.
length
-
1
){
countIndex
=
0
}
return
project
}
const
loadFixtures
=
async
()
=>
{
const
loadFixtures
=
async
()
=>
{
myDataSource
myDataSource
...
@@ -19,25 +52,27 @@ const loadFixtures = async () => {
...
@@ -19,25 +52,27 @@ const loadFixtures = async () => {
await
repositoryMember
.
delete
({})
await
repositoryMember
.
delete
({})
const
repositoryTask
=
myDataSource
.
getRepository
(
Task
);
const
repositoryTask
=
myDataSource
.
getRepository
(
Task
);
await
repositoryTask
.
delete
({});
await
repositoryTask
.
delete
({});
const
repositoryDateTimeTask
=
myDataSource
.
getRepository
(
DateTimeTask
);
await
repositoryDateTimeTask
.
delete
({})
const
repositoryProject
=
myDataSource
.
getRepository
(
Project
);
const
repositoryProject
=
myDataSource
.
getRepository
(
Project
);
await
repositoryProject
.
delete
({})
await
repositoryProject
.
delete
({})
const
repositoryUser
=
myDataSource
.
getRepository
(
User
);
const
repositoryUser
=
myDataSource
.
getRepository
(
User
);
await
repositoryUser
.
delete
({});
await
repositoryUser
.
delete
({});
console
.
log
(
'========================== '
+
'
\
n'
+
'Data Source has been cleared!'
+
'
\
n'
+
'=========================='
)
console
.
log
(
'========================== '
+
'
\
n'
+
'Data Source has been cleared!'
+
'
\
n'
+
'=========================='
)
const
userRoles
=
[{
role
:
UserRole
.
DIRECTOR
},
{
role
:
UserRole
.
SUPERUSER
},
{
role
:
UserRole
.
USER
},
{
role
:
UserRole
.
USER
}
];
const
userRoles
=
[{
role
:
UserRole
.
SUPERUSER
},
{
role
:
UserRole
.
USER
},
{
role
:
UserRole
.
USER
},{
role
:
UserRole
.
USER
},
];
const
users
=
[]
const
users
=
[]
for
(
let
i
=
0
;
i
<
4
;
i
++
)
{
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
const
name
=
faker
.
name
.
firstName
()
const
name
=
faker
.
name
.
firstName
()
const
surname
=
faker
.
name
.
lastName
()
const
surname
=
faker
.
name
.
lastName
()
const
displayName
=
name
+
' '
+
surname
[
0
]
+
'.'
const
displayName
=
name
+
' '
+
surname
[
0
]
+
'.'
const
user
=
new
User
()
const
user
=
new
User
()
user
.
name
=
name
;
user
.
name
=
name
;
user
.
surname
=
surname
;
user
.
surname
=
surname
;
user
.
password
=
'123
45qwert
'
;
user
.
password
=
'123'
;
user
.
displayName
=
displayName
;
user
.
displayName
=
displayName
;
user
.
phone
=
faker
.
phone
.
number
(
'+77#########'
)
user
.
phone
=
faker
.
phone
.
number
(
'+77#########'
)
user
.
email
=
faker
.
internet
.
email
()
;
user
.
email
=
'a@a.a'
+
i
;
user
.
role
=
userRoles
[
i
].
role
;
user
.
role
=
userRoles
[
i
].
role
;
user
.
generateToken
()
user
.
generateToken
()
await
user
.
save
();
await
user
.
save
();
...
@@ -46,18 +81,28 @@ const loadFixtures = async () => {
...
@@ -46,18 +81,28 @@ const loadFixtures = async () => {
const
tasks
:
Task
[]
=
[]
const
tasks
:
Task
[]
=
[]
const
priorities
:
priorityType
[]
=
[
"A"
,
"B"
,
"C"
]
const
priorities
:
priorityType
[]
=
[
"A"
,
"B"
,
"C"
]
const
accomplish
:
taskFinishType
[]
=
[
"opened"
,
"in-progress"
,
"done"
,
"failed"
]
const
accomplish
:
taskFinishType
[]
=
[
"opened"
,
"done"
,
"failed"
]
for
(
let
i
=
0
;
i
<
20
;
i
++
)
{
for
(
let
i
=
0
;
i
<
20
;
i
++
)
{
let
dateOfMonth
=
randomIntFromInterval
(
20
,
30
)
let
deadLineDateOfMonth
=
randomIntFromInterval
(
1
,
15
)
let
startDateTime
=
new
Date
(
2022
,
11
,
dateOfMonth
,
randomIntFromInterval
(
10
,
15
),
0
,
0
);
let
dueDateTime
=
new
Date
(
2022
,
11
,
dateOfMonth
,
randomIntFromInterval
(
16
,
20
),
0
,
0
);
let
deadLine
=
new
Date
(
2022
,
12
,
deadLineDateOfMonth
,
0
,
0
,
0
);
const
newDateTimeTask
=
new
DateTimeTask
()
newDateTimeTask
.
dateTimeStart
=
startDateTime
;
newDateTimeTask
.
dateTimeDue
=
dueDateTime
;
await
newDateTimeTask
.
save
()
if
(
i
<=
15
)
{
if
(
i
<=
15
)
{
const
newTask
=
new
Task
();
const
newTask
=
new
Task
();
newTask
.
title
=
`Buy
${
faker
.
commerce
.
productName
()}
`
;
newTask
.
title
=
`Buy
${
faker
.
commerce
.
productName
()}
`
;
newTask
.
description
=
faker
.
random
.
words
(
4
);
newTask
.
description
=
faker
.
random
.
words
(
4
);
newTask
.
executor
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
dateTimeDue
=
faker
.
date
.
soon
(
randomIntFromInterval
(
1
,
15
));
newTask
.
dateTimeStart
=
faker
.
date
.
recent
((
randomIntFromInterval
(
0
,
8
)));
newTask
.
dateTimeDeadLine
=
faker
.
date
.
soon
(
randomIntFromInterval
(
1
,
15
));
newTask
.
dateTimeFactDeadLine
=
faker
.
date
.
soon
(
randomIntFromInterval
(
1
,
15
));
newTask
.
author
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
author
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
executor
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
dateTimeTasks
=
[
newDateTimeTask
]
newTask
.
dateTimeDeadLine
=
deadLine
;
newTask
.
dateTimeFactDeadLine
=
deadLine
;
newTask
.
accomplish
=
faker
.
helpers
.
arrayElement
(
accomplish
);
newTask
.
accomplish
=
faker
.
helpers
.
arrayElement
(
accomplish
);
newTask
.
priority
=
faker
.
helpers
.
arrayElement
(
priorities
);
newTask
.
priority
=
faker
.
helpers
.
arrayElement
(
priorities
);
await
newTask
.
save
();
await
newTask
.
save
();
...
@@ -76,36 +121,33 @@ const loadFixtures = async () => {
...
@@ -76,36 +121,33 @@ const loadFixtures = async () => {
}
}
const
members
:
Member
[]
=
[]
const
members
:
Member
[]
=
[]
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
const
newMember
=
new
Member
();
const
newMember
=
new
Member
();
newMember
.
user
=
faker
.
helpers
.
arrayElement
(
users
);
newMember
.
user
=
faker
.
helpers
.
arrayElement
(
users
);
newMember
.
roleProject
=
faker
.
helpers
.
objectValue
(
MemberRole
);
newMember
.
roleProject
=
cycleThroughObject
(
countRolesProject
,
MemberRole
);
await
newMember
.
save
();
await
newMember
.
save
();
members
.
push
(
newMember
)
members
.
push
(
newMember
)
}
}
const
projects
:
Project
[]
=
[]
const
projects
:
Project
[]
=
[]
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
const
newProject
=
new
Project
();
const
newProject
=
new
Project
();
newProject
.
title
=
`Project
${
faker
.
random
.
words
(
1
)}
`
;
newProject
.
title
=
`Project
${
faker
.
random
.
words
(
1
)}
`
;
newProject
.
color
=
faker
.
random
.
words
(
1
);
newProject
.
color
=
faker
.
random
.
words
(
1
);
newProject
.
members
=
faker
.
helpers
.
arrayElements
(
members
,
randomIntFromInterval
(
1
,
3
))
newProject
.
members
=
[
cycleArrayOfMembers
(
countMembers
,
members
),
cycleArrayOfMembers
(
countMembers
,
members
),
cycleArrayOfMembers
(
countMembers
,
members
)]
newProject
.
tasks
=
faker
.
helpers
.
arrayElements
(
tasks
,
randomIntFromInterval
(
1
,
3
));
newProject
.
tasks
=
faker
.
helpers
.
arrayElements
(
tasks
,
randomIntFromInterval
(
2
,
19
));
await
newProject
.
save
();
await
newProject
.
save
();
projects
.
push
(
newProject
)
projects
.
push
(
newProject
)
}
}
console
.
log
(
'========================== '
+
'
\
n'
+
'Fixtures done!'
+
'
\
n'
+
'=========================='
)
console
.
log
(
'========================== '
+
'
\
n'
+
'Fixtures done!'
+
'
\
n'
+
'=========================='
)
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
console
.
error
(
"Error during Data Source initialization:"
,
err
)
console
.
error
(
"Error during Data Source initialization:"
,
err
)
})
})
};
};
...
...
planner-api/src/models/Task.ts
View file @
1ac87806
...
@@ -13,7 +13,7 @@ import {
...
@@ -13,7 +13,7 @@ import {
import
{
Project
}
from
'./Project'
;
import
{
Project
}
from
'./Project'
;
import
{
DateTimeTask
}
from
'./DateTimeTask'
;
import
{
DateTimeTask
}
from
'./DateTimeTask'
;
export
type
taskFinishType
=
"opened"
|
"
in-
progress"
|
"done"
|
"failed"
;
export
type
taskFinishType
=
"opened"
|
"progress"
|
"done"
|
"failed"
;
export
type
priorityType
=
"A"
|
"B"
|
"C"
;
export
type
priorityType
=
"A"
|
"B"
|
"C"
;
interface
ITask
{
interface
ITask
{
...
@@ -22,8 +22,6 @@ import { DateTimeTask } from './DateTimeTask';
...
@@ -22,8 +22,6 @@ import { DateTimeTask } from './DateTimeTask';
description
:
string
;
description
:
string
;
note
:
string
;
note
:
string
;
createdAt
:
Date
;
createdAt
:
Date
;
dateTimeStart
:
Date
|
null
;
dateTimeDue
:
Date
|
null
;
dateTimeDeadLine
:
Date
|
null
;
dateTimeDeadLine
:
Date
|
null
;
dateTimeFactDeadLine
:
Date
|
null
;
dateTimeFactDeadLine
:
Date
|
null
;
accomplish
:
taskFinishType
;
accomplish
:
taskFinishType
;
...
@@ -47,10 +45,6 @@ import { DateTimeTask } from './DateTimeTask';
...
@@ -47,10 +45,6 @@ import { DateTimeTask } from './DateTimeTask';
note
!
:
string
note
!
:
string
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
createdAt
!
:
Date
;
createdAt
!
:
Date
;
@
Column
({
name
:
'dateTimeStart'
,
type
:
Date
,
nullable
:
true
})
dateTimeStart
!
:
Date
;
@
Column
({
name
:
'dateTimeDue'
,
type
:
Date
,
nullable
:
true
})
dateTimeDue
!
:
Date
;
@
Column
({
name
:
'dateTimeDeadLine'
,
type
:
Date
,
nullable
:
true
})
@
Column
({
name
:
'dateTimeDeadLine'
,
type
:
Date
,
nullable
:
true
})
dateTimeDeadLine
!
:
Date
;
dateTimeDeadLine
!
:
Date
;
@
Column
({
name
:
'dateTimeFactDeadLine'
,
type
:
Date
,
nullable
:
true
})
@
Column
({
name
:
'dateTimeFactDeadLine'
,
type
:
Date
,
nullable
:
true
})
...
...
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