Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
lr-service
Commits
c55e0c0e
Commit
c55e0c0e
authored
2 years ago
by
tushar5526
Browse files
Options
Download
Patches
Plain Diff
feat: Implemented search user in RC
parent
db2ff718
main
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app.service.ts
+42
-2
src/app.service.ts
util/entityHelper.ts
+72
-0
util/entityHelper.ts
with
114 additions
and
2 deletions
+114
-2
src/app.service.ts
+
42
−
2
View file @
c55e0c0e
...
...
@@ -3,6 +3,7 @@ import { lastValueFrom, map } from 'rxjs';
import
*
as
qs
from
'
qs
'
;
import
{
HttpService
}
from
'
@nestjs/axios
'
;
import
{
fetchDataFromAcessToken
}
from
'
util/fetchData
'
;
import
{
searchEntity
,
updateEntity
}
from
'
util/entityHelper
'
;
@
Injectable
()
export
class
AppService
{
...
...
@@ -17,7 +18,7 @@ export class AppService {
username
:
username
,
password
:
password
,
grant_type
:
'
password
'
,
scope
:
'
openid
address
phone email
'
,
scope
:
'
openid phone email
address
'
,
});
const
config
:
any
=
{
url
:
process
.
env
.
ACCESS_TOKEN_URI
,
...
...
@@ -27,6 +28,7 @@ export class AppService {
},
data
:
data
,
};
let
instituteData
;
try
{
const
res
=
await
lastValueFrom
(
this
.
httpService
...
...
@@ -34,13 +36,51 @@ export class AppService {
.
pipe
(
map
((
item
)
=>
item
.
data
)),
);
const
access_token
=
res
.
access_token
;
return
fetchDataFromAcessToken
(
instituteData
=
await
fetchDataFromAcessToken
(
access_token
,
process
.
env
.
INFO_URI_CASA
,
this
.
httpService
,
);
// search in RC using institute's username
}
catch
(
e
)
{
throw
new
HttpException
(
'
Get registered on CASA
'
,
HttpStatus
.
NOT_FOUND
);
}
console
.
log
(
instituteData
);
const
searchRes
:
Array
<
any
>
=
await
searchEntity
(
this
.
httpService
,
process
.
env
.
BASE_URI_RC
+
'
Institute/search
'
,
{
filters
:
{
username
:
{
eq
:
'
unik-new
'
,
},
},
limit
:
1
,
offset
:
0
,
},
);
console
.
log
(
searchRes
);
if
(
searchRes
.
length
)
{
{
const
updatedData
=
{
name
:
instituteData
.
name
,
phoneNumber
:
instituteData
.
phone
?
instituteData
.
phone
:
'
123456
'
,
email
:
instituteData
.
email
,
username
:
instituteData
.
preferred_username
,
address
:
instituteData
.
address
.
address
?
instituteData
.
address
:
'
GHAR
'
,
};
const
updateActionRes
=
await
updateEntity
(
this
.
httpService
,
updatedData
,
process
.
env
.
BASE_URI_RC
+
`Institue/
${
searchRes
[
0
].
osid
}
`
,
);
return
updateActionRes
;
}
}
else
{
// TODO: call register user helper
return
'
register User
'
;
}
}
}
This diff is collapsed.
Click to expand it.
util/entityHelper.ts
0 → 100644
+
72
−
0
View file @
c55e0c0e
import
{
HttpService
}
from
'
@nestjs/axios
'
;
import
{
HttpException
,
HttpStatus
}
from
'
@nestjs/common
'
;
import
{
lastValueFrom
,
map
}
from
'
rxjs
'
;
export
const
createEntity
=
async
(
httpService
:
HttpService
,
entityData
:
any
,
endpointUri
:
string
,
)
=>
{
const
res
=
await
lastValueFrom
(
httpService
.
post
(
endpointUri
,
entityData
,
{
headers
:
{
'
Content-type
'
:
'
application/json
'
},
})
.
pipe
(
map
((
item
)
=>
item
.
data
)),
);
return
res
;
};
export
const
searchEntity
=
async
(
httpService
:
HttpService
,
endpointUri
:
string
,
entityFilterData
:
any
,
)
=>
{
try
{
const
res
=
await
lastValueFrom
(
httpService
.
post
(
endpointUri
,
entityFilterData
)
.
pipe
(
map
((
item
)
=>
item
.
data
)),
);
return
res
;
}
catch
(
e
)
{
console
.
log
(
e
);
throw
new
HttpException
(
'
500 Internal
'
,
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
};
export
const
getEntityByID
=
async
(
httpService
:
HttpService
,
endpointUri
:
string
,
)
=>
{
const
res
=
await
lastValueFrom
(
httpService
.
get
(
endpointUri
,
{
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
})
.
pipe
(
map
((
item
)
=>
item
.
data
)),
);
return
res
;
};
export
const
updateEntity
=
async
(
httpService
:
HttpService
,
entityData
:
any
,
endpointUri
:
string
,
)
=>
{
console
.
log
(
endpointUri
,
entityData
);
try
{
const
res
=
await
lastValueFrom
(
httpService
.
put
(
endpointUri
,
JSON
.
stringify
(
entityData
),
{
headers
:
{
'
Content-type
'
:
'
application/json
'
},
})
.
pipe
(
map
((
item
)
=>
item
.
data
)),
);
return
res
;
}
catch
(
e
)
{
console
.
log
(
e
);
throw
new
HttpException
(
'
500 Internal while Updating Entity
'
,
HttpStatus
.
INTERNAL_SERVER_ERROR
,
);
}
};
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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
Menu
Explore
Projects
Groups
Topics
Snippets