Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
repp_backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Julieta Dubra Raimunde
repp_backend
Commits
10520c30
Commit
10520c30
authored
3 years ago
by
Ignacio Otero
Browse files
Options
Downloads
Patches
Plain Diff
Funcionalidad de busqueda en autorización de usuarios
parent
ddadafc9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Controllers/UserCotroller.ts
+31
-3
31 additions, 3 deletions
src/Controllers/UserCotroller.ts
src/Services/UserService.ts
+80
-3
80 additions, 3 deletions
src/Services/UserService.ts
with
111 additions
and
6 deletions
src/Controllers/UserCotroller.ts
+
31
−
3
View file @
10520c30
...
...
@@ -5,10 +5,32 @@ import UserService from '../Services/UserService';
const
router
=
Router
();
const
list
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
const
list
All
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
try
{
const
users
:
Paginator
<
User
>
=
await
UserService
.
list
(
Number
(
req
.
query
.
limit
),
Number
(
req
.
query
.
offset
));
.
listAll
(
Number
(
req
.
query
.
limit
),
Number
(
req
.
query
.
offset
));
return
res
.
status
(
200
).
send
(
users
);
}
catch
(
error
)
{
const
e
=
error
as
Error
;
return
res
.
status
(
400
).
json
({
error
:
e
.
message
});
}
};
const
listPending
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
try
{
const
users
:
Paginator
<
User
>
=
await
UserService
.
listPending
(
Number
(
req
.
query
.
limit
),
Number
(
req
.
query
.
offset
),
String
(
req
.
query
.
search
));
return
res
.
status
(
200
).
send
(
users
);
}
catch
(
error
)
{
const
e
=
error
as
Error
;
return
res
.
status
(
400
).
json
({
error
:
e
.
message
});
}
};
const
listApproved
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
try
{
const
users
:
Paginator
<
User
>
=
await
UserService
.
listApproved
(
Number
(
req
.
query
.
limit
),
Number
(
req
.
query
.
offset
),
String
(
req
.
query
.
search
));
return
res
.
status
(
200
).
send
(
users
);
}
catch
(
error
)
{
const
e
=
error
as
Error
;
...
...
@@ -77,9 +99,15 @@ const active = async (req: Request, res: Response): Promise<Response> => {
};
router
.
route
(
'
/
'
)
.
get
(
list
)
.
get
(
list
All
)
.
post
(
create
);
router
.
route
(
'
/pending
'
)
.
get
(
listPending
);
router
.
route
(
'
/approved
'
)
.
get
(
listApproved
);
router
.
route
(
'
/:id
'
)
.
put
(
update
)
.
patch
(
active
);
...
...
This diff is collapsed.
Click to expand it.
src/Services/UserService.ts
+
80
−
3
View file @
10520c30
import
bcrypt
from
'
bcrypt
'
;
import
{
Op
}
from
'
sequelize
'
;
import
{
profiles
,
status
}
from
'
../enums/index.enum
'
;
import
Paginator
from
'
../interfaces/paginator.interface
'
;
import
{
User
}
from
'
../models/users.model
'
;
import
{
UserCreateDTO
,
UserDTO
}
from
'
../DTOs/UserDTO
'
;
const
list
=
async
(
limit
:
number
,
offset
:
number
):
Promise
<
Paginator
<
User
>>
=>
{
const
listPending
=
async
(
limit
:
number
,
offset
:
number
,
search
:
string
):
Promise
<
Paginator
<
User
>>
=>
{
let
options
=
{};
if
(
limit
&&
offset
)
{
if
(
limit
>=
1
&&
offset
>=
0
)
{
if
(
search
&&
search
!==
''
)
{
options
=
{
where
:
{
status
:
status
.
pending
,
[
Op
.
or
]:
[
{
name
:
{
[
Op
.
substring
]:
search
}
},
{
email
:
{
[
Op
.
substring
]:
search
}
},
],
},
limit
,
offset
,
};
}
else
{
options
=
{
where
:
{
status
:
status
.
pending
,
},
limit
,
offset
,
};
}
}
return
User
.
findAndCountAll
({
attributes
:
[
'
id
'
,
'
name
'
,
'
email
'
,
'
organization
'
,
'
type
'
,
'
status
'
,
'
active
'
,
'
createdAt
'
,
],
order
:
[
[
'
createdAt
'
,
'
ASC
'
],
],
...
options
,
});
};
const
listApproved
=
async
(
limit
:
number
,
offset
:
number
,
search
:
string
):
Promise
<
Paginator
<
User
>>
=>
{
let
options
=
{};
if
(
limit
>=
1
&&
offset
>=
0
)
{
if
(
search
&&
search
!==
''
)
{
options
=
{
where
:
{
status
:
status
.
approved
,
[
Op
.
or
]:
[
{
name
:
{
[
Op
.
substring
]:
search
}
},
{
email
:
{
[
Op
.
substring
]:
search
}
},
],
},
limit
,
offset
,
};
}
else
{
options
=
{
where
:
{
status
:
status
.
approved
,
},
limit
,
offset
,
};
}
}
return
User
.
findAndCountAll
({
attributes
:
[
'
id
'
,
'
name
'
,
'
email
'
,
'
organization
'
,
'
type
'
,
'
status
'
,
'
active
'
,
'
createdAt
'
,
],
order
:
[
[
'
createdAt
'
,
'
ASC
'
],
],
...
options
,
});
};
const
listAll
=
async
(
limit
:
number
,
offset
:
number
):
Promise
<
Paginator
<
User
>>
=>
{
let
options
=
{};
if
(
limit
>=
1
&&
offset
>=
0
)
{
options
=
{
limit
,
offset
,
...
...
@@ -188,7 +263,9 @@ const active = async (userId: number): Promise<User> => User.findOne({
});
export
default
{
list
,
listAll
,
listPending
,
listApproved
,
create
,
update
,
password
,
...
...
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