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
9e071180
Commit
9e071180
authored
3 years ago
by
Bernard Roland (Student Com20)
Browse files
Options
Downloads
Patches
Plain Diff
Added an API route to update a team
parent
982b88eb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/src/v1/team.ts
+77
-30
77 additions, 30 deletions
server/src/v1/team.ts
with
77 additions
and
30 deletions
server/src/v1/team.ts
+
77
−
30
View file @
9e071180
...
...
@@ -10,48 +10,96 @@ const team = express();
team
.
use
(
requireVerification
);
interface
Team
CreateBody
{
interface
Create
Team
Body
{
name
:
string
;
token
:
Token
;
}
team
.
post
(
'
/
'
,
async
(
req
,
res
)
=>
{
if
(
isOfType
<
Team
CreateBody
>
(
req
.
body
,
[[
'
name
'
,
'
string
'
]]))
{
if
(
isOfType
<
Create
Team
Body
>
(
req
.
body
,
[[
'
name
'
,
'
string
'
]]))
{
const
team_id
=
uuid
();
const
team_name
=
req
.
body
.
name
.
trim
();
const
role_id
=
uuid
();
if
(
team_name
.
length
>=
4
)
{
const
team_name
=
req
.
body
.
name
;
try
{
await
database
.
transaction
(
async
transaction
=>
{
await
transaction
(
'
teams
'
).
insert
({
id
:
team_id
,
name
:
team_name
,
});
await
transaction
(
'
roles
'
).
insert
({
id
:
role_id
,
team_id
:
team_id
,
name
:
'
Default
'
,
});
await
transaction
(
'
team_members
'
).
insert
({
user_id
:
req
.
body
.
token
.
id
,
team_id
:
team_id
,
role_id
:
role_id
,
});
});
res
.
status
(
200
).
json
({
status
:
'
success
'
,
id
:
team_id
,
});
}
catch
(
e
)
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
failed create team
'
,
});
}
}
else
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
missing request fields
'
,
});
}
});
interface
UpdateTeamBody
{
name
:
string
;
token
:
Token
;
}
team
.
put
(
'
/:uuid
'
,
async
(
req
,
res
)
=>
{
if
(
isOfType
<
UpdateTeamBody
>
(
req
.
body
,
[[
'
name
'
,
'
string
'
]]))
{
const
team_id
=
req
.
params
.
uuid
;
if
(
validate
(
team_id
))
{
const
team_name
=
req
.
body
.
name
;
try
{
await
database
.
transaction
(
async
transaction
=>
{
await
transaction
(
'
teams
'
).
insert
({
id
:
team_id
,
name
:
team_name
,
const
team
=
await
database
(
'
teams
'
)
.
leftJoin
(
'
team_members
'
,
'
teams.id
'
,
'
team_members.team_id
'
)
.
select
({
id
:
'
teams.id
'
})
.
where
({
'
team_members.user_id
'
:
req
.
body
.
token
.
id
,
'
teams.id
'
:
team_id
,
});
await
transaction
(
'
roles
'
).
insert
({
id
:
role_id
,
team_id
:
team_id
,
name
:
'
Default
'
,
if
(
team
.
length
>=
1
)
{
await
database
(
'
teams
'
)
.
update
({
name
:
team_name
,
})
.
where
({
'
teams.id
'
:
team_id
,
})
res
.
status
(
200
).
json
({
status
:
'
success
'
,
});
await
transaction
(
'
team_members
'
).
insert
(
{
user_id
:
req
.
body
.
token
.
id
,
team_id
:
team_id
,
role_id
:
role_id
,
}
else
{
res
.
status
(
404
).
json
({
status
:
'
error
'
,
message
:
'
team not found
'
,
});
});
res
.
status
(
200
).
json
({
status
:
'
success
'
,
id
:
team_id
,
});
}
}
catch
(
e
)
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
failed
cre
ate team
'
,
message
:
'
failed
upd
ate team
'
,
});
}
}
else
{
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
team names must be four letters or longer
'
,
message
:
'
malformed uuid
'
,
});
}
}
else
{
...
...
@@ -105,7 +153,7 @@ team.get('/:uuid/', async (req, res) => {
'
team_members.user_id
'
:
null
,
'
teams.id
'
:
id
,
})
if
(
team
.
length
==
=
1
)
{
if
(
team
.
length
>
=
1
)
{
res
.
status
(
200
).
json
({
status
:
'
success
'
,
team
:
team
[
0
],
...
...
@@ -196,7 +244,7 @@ team.delete('/:teamid/members/:userid', async (req, res) => {
'
team_members.user_id
'
:
req
.
body
.
token
.
id
,
'
team_members.team_id
'
:
team_id
,
});
if
(
team
.
length
==
=
1
)
{
if
(
team
.
length
>
=
1
)
{
const
deleted
=
await
database
(
'
team_members
'
)
.
delete
()
.
where
({
...
...
@@ -233,7 +281,6 @@ team.delete('/:teamid/members/:userid', async (req, res) => {
}
});
team
.
get
(
'
/:uuid/roles
'
,
async
(
req
,
res
)
=>
{
try
{
const
id
=
req
.
params
.
uuid
;
...
...
@@ -366,7 +413,7 @@ team.post('/:uuid/roles', async (req, res) => {
'
team_members.user_id
'
:
req
.
body
.
token
.
id
,
'
team_members.team_id
'
:
team_id
,
});
if
(
team
.
length
==
=
1
)
{
if
(
team
.
length
>
=
1
)
{
const
role_id
=
uuid
();
const
role_name
=
req
.
body
.
name
;
await
database
(
'
roles
'
).
insert
({
...
...
@@ -418,7 +465,7 @@ team.delete('/:teamid/roles/:roleid', async (req, res) => {
'
team_members.user_id
'
:
req
.
body
.
token
.
id
,
'
team_members.team_id
'
:
team_id
,
});
if
(
team
.
length
==
=
1
)
{
if
(
team
.
length
>
=
1
)
{
const
deleted
=
await
database
(
'
roles
'
)
.
delete
()
.
where
({
...
...
@@ -476,7 +523,7 @@ team.post('/:uuid/members', async (req, res) => {
'
team_members.team_id
'
:
team_id
,
'
roles.id
'
:
role_id
,
});
if
(
role
.
length
==
=
1
)
{
if
(
role
.
length
>
=
1
)
{
await
database
(
'
team_members
'
).
insert
({
user_id
:
user_id
,
team_id
:
team_id
,
...
...
@@ -532,7 +579,7 @@ team.put('/:uuid/members', async (req, res) => {
'
team_members.team_id
'
:
team_id
,
'
roles.id
'
:
role_id
,
});
if
(
role
.
length
==
=
1
)
{
if
(
role
.
length
>
=
1
)
{
await
database
(
'
team_members
'
)
.
update
({
role_id
:
role_id
})
.
where
({
...
...
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