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
uphrh-casa-user-data-service
Commits
907ca0b1
Commit
907ca0b1
authored
2 years ago
by
tushar5526
Browse files
Options
Download
Patches
Plain Diff
feat: added env vars
parent
56702eee
main
getStudentByRollnumber
No related merge requests found
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
.gitignore
+2
-0
.gitignore
sample.env
+5
-0
sample.env
src/app.module.ts
+2
-2
src/app.module.ts
src/app.service.ts
+19
-9
src/app.service.ts
src/db/db.module.ts
+27
-2
src/db/db.module.ts
src/main.ts
+3
-2
src/main.ts
with
58 additions
and
15 deletions
+58
-15
.gitignore
+
2
−
0
View file @
907ca0b1
.env
# compiled output
# compiled output
/dist
/dist
/node_modules
/node_modules
...
...
This diff is collapsed.
Click to expand it.
sample.env
0 → 100644
+
5
−
0
View file @
907ca0b1
MSSQL_USER=sa
MSSQL_SERVER=localhost
MSSQL_DATABASE=test
MSSQL_PASSWORD=Pass@word
MSSQL_PORT=1433
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/app.module.ts
+
2
−
2
View file @
907ca0b1
import
{
Module
}
from
'
@nestjs/common
'
;
import
{
Module
}
from
'
@nestjs/common
'
;
import
{
AppController
}
from
'
./app.controller
'
;
import
{
AppController
}
from
'
./app.controller
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
DbModule
}
from
'
./db/db.module
'
;
import
{
dbConnector
,
DbModule
}
from
'
./db/db.module
'
;
@
Module
({
@
Module
({
imports
:
[
DbModule
],
imports
:
[
DbModule
],
controllers
:
[
AppController
],
controllers
:
[
AppController
],
providers
:
[
AppService
],
providers
:
[
AppService
,
dbConnector
],
})
})
export
class
AppModule
{}
export
class
AppModule
{}
This diff is collapsed.
Click to expand it.
src/app.service.ts
+
19
−
9
View file @
907ca0b1
import
{
Injectable
,
Inject
}
from
'
@nestjs/common
'
;
import
{
Injectable
,
Inject
}
from
'
@nestjs/common
'
;
import
{
MSSQL_CONNECTION
}
from
'
./constants
'
;
import
{
MSSQL_CONNECTION
}
from
'
./constants
'
;
import
*
as
CryptoJS
from
'
crypto
'
;
import
*
as
CryptoJS
from
'
crypto
'
;
import
{
dbConnector
}
from
'
./db/db.module
'
;
import
{
ConnectionPool
}
from
'
mssql
'
;
@
Injectable
()
@
Injectable
()
export
class
AppService
{
export
class
AppService
{
constructor
(@
Inject
(
MSSQL_CONNECTION
)
private
conn
:
any
)
{}
dbConnection
:
ConnectionPool
=
null
;
constructor
(
private
conn
:
dbConnector
)
{
this
.
dbConnection
=
conn
.
getConnectionPool
(
process
.
env
.
MSSQL_USER
,
process
.
env
.
MSSQL_SERVER
,
process
.
env
.
MSSQL_DATABASE
,
process
.
env
.
MSSQL_PASSWORD
,
parseInt
(
process
.
env
.
MSSQL_PORT
),
);
}
// async mysqlCallStoredProcedure(msg: string) {
// async mysqlCallStoredProcedure(msg: string) {
//returns a promise that resolves to a result set on success
//returns a promise that resolves to a result set on success
...
@@ -23,7 +33,7 @@ export class AppService {
...
@@ -23,7 +33,7 @@ export class AppService {
async
mssqlCallStoredProcedure
(
username
:
string
)
{
async
mssqlCallStoredProcedure
(
username
:
string
)
{
//returns a promise that resolves to a result set on success
//returns a promise that resolves to a result set on success
const
db
=
await
this
.
con
n
.
connect
();
const
db
=
await
this
.
dbConnectio
n
.
connect
();
const
res
=
await
db
.
query
(
`EXEC get_user @Username = N'
${
username
}
'`
);
const
res
=
await
db
.
query
(
`EXEC get_user @Username = N'
${
username
}
'`
);
console
.
log
(
res
);
console
.
log
(
res
);
return
{
pass
:
res
[
'
recordset
'
][
0
][
'
Password
'
]
};
return
{
pass
:
res
[
'
recordset
'
][
0
][
'
Password
'
]
};
...
@@ -58,7 +68,7 @@ export class AppService {
...
@@ -58,7 +68,7 @@ export class AppService {
}
}
async
getUsers
(
search
:
string
,
first
:
number
,
max
:
number
)
{
async
getUsers
(
search
:
string
,
first
:
number
,
max
:
number
)
{
const
db
=
await
this
.
con
n
.
connect
();
const
db
=
await
this
.
dbConnectio
n
.
connect
();
const
res
=
this
.
parseQueryResponse
(
const
res
=
this
.
parseQueryResponse
(
await
db
.
query
(
`SELECT * FROM Master_user`
),
await
db
.
query
(
`SELECT * FROM Master_user`
),
);
);
...
@@ -66,7 +76,7 @@ export class AppService {
...
@@ -66,7 +76,7 @@ export class AppService {
}
}
async
getUsersCount
()
{
async
getUsersCount
()
{
const
db
=
await
this
.
con
n
.
connect
();
const
db
=
await
this
.
dbConnectio
n
.
connect
();
const
res
=
await
db
.
query
(
const
res
=
await
db
.
query
(
`SELECT COUNT(UserKey) as count FROM Master_user`
,
`SELECT COUNT(UserKey) as count FROM Master_user`
,
);
);
...
@@ -74,7 +84,7 @@ export class AppService {
...
@@ -74,7 +84,7 @@ export class AppService {
}
}
async
getUserById
(
username
:
string
)
{
async
getUserById
(
username
:
string
)
{
const
db
=
await
this
.
con
n
.
connect
();
const
db
=
await
this
.
dbConnectio
n
.
connect
();
const
res
=
this
.
parseQueryResponse
(
const
res
=
this
.
parseQueryResponse
(
await
db
.
query
(
`EXEC get_user @Username = N'
${
username
}
'`
),
await
db
.
query
(
`EXEC get_user @Username = N'
${
username
}
'`
),
);
);
...
@@ -82,7 +92,7 @@ export class AppService {
...
@@ -82,7 +92,7 @@ export class AppService {
}
}
async
getUserCredentials
(
username
:
string
)
{
async
getUserCredentials
(
username
:
string
)
{
const
db
=
await
this
.
con
n
.
connect
();
const
db
=
await
this
.
dbConnectio
n
.
connect
();
const
res
=
await
db
.
query
(
`EXEC get_user @Username = N'
${
username
}
'`
);
const
res
=
await
db
.
query
(
`EXEC get_user @Username = N'
${
username
}
'`
);
const
saltRounds
=
1000
;
const
saltRounds
=
1000
;
const
cred_res
=
[];
const
cred_res
=
[];
...
@@ -109,7 +119,7 @@ export class AppService {
...
@@ -109,7 +119,7 @@ export class AppService {
}
}
async
getTutorById
(
id
:
string
)
{
async
getTutorById
(
id
:
string
)
{
const
db
=
await
this
.
con
n
.
connect
();
const
db
=
await
this
.
dbConnectio
n
.
connect
();
const
res
=
await
db
.
query
(
const
res
=
await
db
.
query
(
`Select * from test.dbo.Master_Tutor_Basic_Info where TutorKey='
${
id
}
'`
,
`Select * from test.dbo.Master_Tutor_Basic_Info where TutorKey='
${
id
}
'`
,
);
);
...
@@ -117,7 +127,7 @@ export class AppService {
...
@@ -117,7 +127,7 @@ export class AppService {
}
}
async
getStudentById
(
id
:
string
)
{
async
getStudentById
(
id
:
string
)
{
const
db
=
await
this
.
con
n
.
connect
();
const
db
=
await
this
.
dbConnectio
n
.
connect
();
const
res
=
await
db
.
query
(
const
res
=
await
db
.
query
(
`Select * from test.dbo.Master_StudentProfile where StudentProfileKey='
${
id
}
'`
,
`Select * from test.dbo.Master_StudentProfile where StudentProfileKey='
${
id
}
'`
,
);
);
...
...
This diff is collapsed.
Click to expand it.
src/db/db.module.ts
+
27
−
2
View file @
907ca0b1
import
{
Module
}
from
'
@nestjs/common
'
;
import
{
Injectable
,
Module
}
from
'
@nestjs/common
'
;
import
{
Pool
}
from
'
pg
'
;
import
{
Pool
}
from
'
pg
'
;
import
{
createPool
}
from
'
mysql
'
;
import
{
createPool
}
from
'
mysql
'
;
import
{
ConnectionPool
}
from
'
mssql
'
;
import
{
ConnectionPool
}
from
'
mssql
'
;
...
@@ -48,8 +48,33 @@ const mssqlProvider = {
...
@@ -48,8 +48,33 @@ const mssqlProvider = {
}),
}),
};
};
@
Injectable
()
export
class
dbConnector
{
getConnectionPool
(
user
:
string
,
server
:
string
,
database
:
string
,
password
:
string
,
port
:
number
,
)
{
return
new
ConnectionPool
({
user
:
user
,
server
:
server
,
database
:
database
,
password
:
password
,
port
:
port
,
options
:
{
trustedConnection
:
true
,
encrypt
:
true
,
enableArithAbort
:
true
,
trustServerCertificate
:
true
,
},
});
}
}
@
Module
({
@
Module
({
providers
:
[
pgProvider
,
mysqlProvider
,
mssqlProvider
],
providers
:
[
pgProvider
,
mysqlProvider
,
mssqlProvider
,
dbConnector
],
exports
:
[
pgProvider
,
mysqlProvider
,
mssqlProvider
],
exports
:
[
pgProvider
,
mysqlProvider
,
mssqlProvider
],
})
})
export
class
DbModule
{}
export
class
DbModule
{}
This diff is collapsed.
Click to expand it.
src/main.ts
+
3
−
2
View file @
907ca0b1
import
{
NestFactory
}
from
'
@nestjs/core
'
;
import
{
NestFactory
}
from
'
@nestjs/core
'
;
import
{
AppModule
}
from
'
./app.module
'
;
import
{
AppModule
}
from
'
./app.module
'
;
import
{
config
}
from
'
dotenv
'
;
config
();
async
function
bootstrap
()
{
async
function
bootstrap
()
{
const
app
=
await
NestFactory
.
create
(
AppModule
);
const
app
=
await
NestFactory
.
create
(
AppModule
);
await
app
.
listen
(
3000
);
await
app
.
listen
(
3000
);
}
}
bootstrap
();
bootstrap
();
\ No newline at end of file
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