Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WIE_202021_CSBillero11
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bernard Roland (Student Com20)
WIE_202021_CSBillero11
Commits
f742a0b3
Commit
f742a0b3
authored
3 years ago
by
Bernard Roland (Student Com20)
Browse files
Options
Downloads
Patches
Plain Diff
Added project creation and updating api paths
parent
db3a4ff1
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
server/migrations/0000_initial.ts
+13
-6
13 additions, 6 deletions
server/migrations/0000_initial.ts
server/src/v1/project.ts
+232
-1
232 additions, 1 deletion
server/src/v1/project.ts
server/src/v1/task.ts
+4
-2
4 additions, 2 deletions
server/src/v1/task.ts
with
249 additions
and
9 deletions
server/migrations/0000_initial.ts
+
13
−
6
View file @
f742a0b3
...
...
@@ -41,8 +41,8 @@ export async function up(database: Knex): Promise<void> {
table
.
text
(
'
text
'
).
notNullable
();
table
.
enum
(
'
status
'
,
[
'
open
'
,
'
closed
'
,
'
suspended
'
]).
notNullable
();
table
.
enum
(
'
priority
'
,
[
'
low
'
,
'
medium
'
,
'
high
'
,
'
urgent
'
]).
notNullable
();
table
.
dateTime
(
'
created
'
).
notNullable
();
table
.
dateTime
(
'
edited
'
).
notNullable
();
table
.
timestamp
(
'
created
'
).
notNullable
();
table
.
timestamp
(
'
edited
'
).
notNullable
();
})
.
createTable
(
'
task_dependencies
'
,
table
=>
{
table
.
uuid
(
'
task_id
'
).
notNullable
().
references
(
'
tasks.id
'
);
...
...
@@ -59,7 +59,6 @@ export async function up(database: Knex): Promise<void> {
table
.
uuid
(
'
user_id
'
).
notNullable
().
references
(
'
users.id
'
);
table
.
uuid
(
'
task_id
'
).
notNullable
().
references
(
'
tasks.id
'
);
table
.
primary
([
'
user_id
'
,
'
task_id
'
]);
table
.
integer
(
'
time
'
).
notNullable
();
table
.
boolean
(
'
assigned
'
).
notNullable
();
table
.
boolean
(
'
working
'
).
notNullable
();
})
...
...
@@ -68,8 +67,15 @@ export async function up(database: Knex): Promise<void> {
table
.
uuid
(
'
task_id
'
).
notNullable
().
references
(
'
tasks.id
'
);
table
.
uuid
(
'
user_id
'
).
notNullable
().
references
(
'
users.id
'
);
table
.
text
(
'
text
'
).
notNullable
();
table
.
dateTime
(
'
created
'
).
notNullable
();
table
.
dateTime
(
'
edited
'
).
notNullable
();
table
.
timestamp
(
'
created
'
).
notNullable
();
table
.
timestamp
(
'
edited
'
).
notNullable
();
})
.
createTable
(
'
workhours
'
,
table
=>
{
table
.
uuid
(
'
id
'
).
notNullable
().
primary
();
table
.
uuid
(
'
user_id
'
).
notNullable
().
references
(
'
users.id
'
);
table
.
uuid
(
'
task_id
'
).
notNullable
().
references
(
'
tasks.id
'
);
table
.
timestamp
(
'
started
'
).
notNullable
();
table
.
timestamp
(
'
finished
'
);
});
}
...
...
@@ -84,6 +90,7 @@ export async function down(database: Knex): Promise<void> {
.
dropTable
(
'
roles
'
)
.
dropTable
(
'
team_members
'
)
.
dropTable
(
'
teams
'
)
.
dropTable
(
'
users
'
);
.
dropTable
(
'
users
'
)
.
dropTable
(
'
workhours
'
);
}
This diff is collapsed.
Click to expand it.
server/src/v1/project.ts
+
232
−
1
View file @
f742a0b3
import
express
from
'
express
'
;
import
{
v4
as
uuid
,
validate
}
from
'
uuid
'
;
import
{
requireVerification
}
from
'
./auth
'
;
import
database
from
'
../database
'
;
import
{
isOfType
}
from
'
../util
'
;
import
{
requireVerification
,
Token
}
from
'
./auth
'
;
const
project
=
express
();
project
.
use
(
requireVerification
);
project
.
get
(
'
/
'
,
async
(
req
,
res
)
=>
{
try
{
const
projects
=
await
database
(
'
users
'
)
.
innerJoin
(
'
team_members
'
,
'
users.id
'
,
'
team_members.user_id
'
)
.
innerJoin
(
'
team_projects
'
,
'
team_members.team_id
'
,
'
team_projects.team_id
'
)
.
innerJoin
(
'
projects
'
,
'
team_projects.project_id
'
,
'
projects.id
'
)
.
select
({
id
:
'
projects.id
'
,
name
:
'
projects.name
'
,
})
.
where
({
'
users.id
'
:
req
.
body
.
token
.
id
,
})
.
groupBy
(
'
projects.id
'
);
res
.
status
(
200
).
json
({
status
:
'
success
'
,
projects
:
projects
,
});
}
catch
(
e
)
{
console
.
log
(
e
);
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
failed to get project
'
,
});
}
});
project
.
get
(
'
/:uuid
'
,
async
(
req
,
res
)
=>
{
try
{
const
id
=
req
.
params
.
uuid
;
if
(
validate
(
id
))
{
const
projects
=
await
database
(
'
users
'
)
.
innerJoin
(
'
team_members
'
,
'
users.id
'
,
'
team_members.user_id
'
)
.
innerJoin
(
'
team_projects
'
,
'
team_members.team_id
'
,
'
team_projects.team_id
'
)
.
innerJoin
(
'
projects
'
,
'
team_projects.project_id
'
,
'
projects.id
'
)
.
select
({
id
:
'
projects.id
'
,
name
:
'
projects.name
'
,
team_id
:
'
team_projects.team_id
'
,
})
.
where
({
'
users.id
'
:
req
.
body
.
token
.
id
,
'
projects.id
'
:
id
,
});
if
(
projects
.
length
>=
1
)
{
res
.
status
(
200
).
json
({
status
:
'
success
'
,
project
:
{
id
:
projects
[
0
].
id
,
name
:
projects
[
0
].
name
,
teams
:
projects
.
map
(
task
=>
task
.
team_id
),
}
});
}
else
{
res
.
status
(
404
).
json
({
status
:
'
error
'
,
message
:
'
project not found
'
,
});
}
}
else
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
malformed uuid
'
,
});
}
}
catch
(
e
)
{
console
.
log
(
e
);
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
failed to get project
'
,
});
}
});
interface
AddProjectBody
{
teams
:
Array
<
string
>
;
name
:
string
;
token
:
Token
;
}
project
.
post
(
'
/
'
,
async
(
req
,
res
)
=>
{
if
(
isOfType
<
AddProjectBody
>
(
req
.
body
,
[[
'
teams
'
,
'
object
'
],
[
'
name
'
,
'
string
'
]]))
{
try
{
const
team_ids
=
req
.
body
.
teams
;
for
(
const
team_id
of
team_ids
)
{
if
(
!
validate
(
team_id
))
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
malformed uuid
'
,
});
return
;
}
}
const
project_id
=
uuid
();
const
team
=
await
database
(
'
users
'
)
.
innerJoin
(
'
team_members
'
,
'
users.id
'
,
'
team_members.user_id
'
)
.
select
({
id
:
'
team_members.team_id
'
})
.
where
({
'
users.id
'
:
req
.
body
.
token
.
id
,
})
.
whereIn
(
'
team_members.team_id
'
,
team_ids
);
if
(
team
.
length
===
team_ids
.
length
)
{
await
database
.
transaction
(
async
transaction
=>
{
await
transaction
(
'
projects
'
).
insert
({
id
:
project_id
,
name
:
req
.
body
.
name
,
});
await
transaction
(
'
team_projects
'
).
insert
(
team_ids
.
map
(
team_id
=>
({
project_id
:
project_id
,
team_id
:
team_id
,
}))
);
});
res
.
status
(
200
).
json
({
status
:
'
success
'
,
id
:
project_id
,
});
}
else
{
res
.
status
(
404
).
json
({
status
:
'
error
'
,
message
:
'
team not found
'
,
});
}
}
catch
(
e
)
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
failed to create project
'
,
});
}
}
else
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
missing request fields
'
,
});
}
});
interface
UpdateProjectBody
{
add_teams
?:
Array
<
string
>
;
remove_teams
?:
Array
<
string
>
;
name
?:
string
;
token
:
Token
;
}
project
.
put
(
'
/:uuid
'
,
async
(
req
,
res
)
=>
{
if
(
isOfType
<
UpdateProjectBody
>
(
req
.
body
,
[]))
{
try
{
const
id
=
req
.
params
.
uuid
;
if
(
validate
(
id
))
{
const
add_team_ids
=
req
.
body
.
add_teams
??
[];
const
remove_team_ids
=
req
.
body
.
remove_teams
??
[];
for
(
const
team_id
of
add_team_ids
.
concat
(
remove_team_ids
))
{
if
(
!
validate
(
team_id
))
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
malformed uuid
'
,
});
return
;
}
}
const
projects
=
await
database
(
'
users
'
)
.
innerJoin
(
'
team_members
'
,
'
users.id
'
,
'
team_members.user_id
'
)
.
innerJoin
(
'
team_projects
'
,
'
team_members.team_id
'
,
'
team_projects.team_id
'
)
.
innerJoin
(
'
projects
'
,
'
team_projects.project_id
'
,
'
projects.id
'
)
.
select
({
id
:
'
projects.id
'
,
name
:
'
projects.name
'
,
team_id
:
'
team_projects.team_id
'
,
})
.
where
({
'
users.id
'
:
req
.
body
.
token
.
id
,
'
projects.id
'
:
id
,
});
if
(
projects
.
length
>=
1
)
{
await
database
.
transaction
(
async
transaction
=>
{
if
(
typeof
req
.
body
.
name
===
'
string
'
)
{
await
transaction
(
'
projects
'
)
.
update
({
name
:
req
.
body
.
name
,
}).
where
({
id
:
id
,
});
}
if
(
add_team_ids
.
length
!==
0
)
{
await
transaction
(
'
team_projects
'
).
insert
(
add_team_ids
.
map
(
team_id
=>
({
project_id
:
id
,
team_id
:
team_id
,
}))
);
}
if
(
remove_team_ids
.
length
!==
0
)
{
await
transaction
(
'
team_projects
'
)
.
delete
()
.
where
({
'
project_id
'
:
id
,
})
.
whereIn
(
'
team_id
'
,
remove_team_ids
);
}
});
res
.
status
(
200
).
json
({
status
:
'
success
'
,
});
}
else
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
project not found
'
,
});
}
}
else
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
malformed uuid
'
,
});
}
}
catch
(
e
)
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
failed to create project
'
,
});
}
}
else
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
missing request fields
'
,
});
}
});
export
default
project
;
This diff is collapsed.
Click to expand it.
server/src/v1/task.ts
+
4
−
2
View file @
f742a0b3
import
express
from
'
express
'
;
import
{
validate
}
from
'
uuid
'
;
import
{
v4
as
uuid
,
validate
}
from
'
uuid
'
;
import
database
from
'
../database
'
;
import
{
requireVerification
}
from
'
./auth
'
;
import
{
requireVerification
,
Token
}
from
'
./auth
'
;
import
{
isOfType
}
from
'
../util
'
;
const
task
=
express
();
...
...
@@ -56,5 +57,6 @@ task.get('/:uuid', async (req, res) => {
}
});
export
default
task
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment