Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박권수
2021-09-18 04:11:00 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
151da4090810711077a72045a68c1bd824e870dd
151da409
1 parent
6f4d55c9
feat. Google Cloud Storage Refactoring
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
36 deletions
server/src/api/auth/auth.ctrl.js
server/src/api/manage/manage.ctrl.js
server/src/util/DataProcess.js
server/src/util/GoogleCloudStorage.js
server/src/api/auth/auth.ctrl.js
View file @
151da40
...
...
@@ -3,12 +3,11 @@
const
User
=
require
(
'../../models/user'
);
const
Profile
=
require
(
'../../models/profile'
);
const
DoctorInfo
=
require
(
'../../models/doctorInfo'
);
const
{
uploadDoctorLicense
}
=
require
(
'../../util/GoogleCloudStorage'
);
const
Joi
=
require
(
'joi'
);
const
jwt
=
require
(
'jsonwebtoken'
);
const
axios
=
require
(
'axios'
);
const
{
Storage
}
=
require
(
'@google-cloud/storage'
);
const
GoogleStorageUrl
=
'https://storage.googleapis.com/'
;
exports
.
register
=
async
(
ctx
)
=>
{
const
{
...
...
@@ -107,14 +106,6 @@ exports.doctorRegister = async ctx => {
const
{
doctorInfoFile
}
=
ctx
.
request
.
files
;
const
info
=
{
contact
,
hospitalAddr
,
hospitalNm
,
doctorType
,
doctorNm
,
doctorLicense
:
''
,
};
const
schema
=
Joi
.
object
().
keys
({
userId
:
Joi
.
string
().
email
().
max
(
50
).
required
(),
...
...
@@ -161,6 +152,24 @@ exports.doctorRegister = async ctx => {
return
;
}
const
[
fileName
,
filePath
]
=
[
doctorInfoFile
.
name
,
doctorInfoFile
.
path
];
const
doctorLicense
=
await
uploadDoctorLicense
({
userId
,
fileName
,
filePath
,
});
const
info
=
{
contact
,
hospitalAddr
,
hospitalNm
,
doctorType
,
doctorNm
,
doctorLicense
,
};
const
doctor
=
new
User
({
userId
,
userTypeCd
:
'DOCTOR'
,
...
...
@@ -168,19 +177,6 @@ exports.doctorRegister = async ctx => {
});
await
doctor
.
setPassword
(
password
);
doctor
.
save
();
const
destination
=
userId
+
'_'
+
doctorInfoFile
.
name
;
const
storage
=
new
Storage
();
storage
.
bucket
(
'doctor-info'
).
upload
(
doctorInfoFile
.
path
,
{
destination
,
},
(
err
,
file
,
res
)
=>
{
if
(
err
)
console
.
log
(
'Fail to upload Doctor License'
);
else
{
info
.
doctorLicense
=
GoogleStorageUrl
+
`
${
res
.
bucket
}
/
${
res
.
name
}
`
;
console
.
log
(
'Success to Upload Doctor License!'
);
}
const
doctorInfo
=
new
DoctorInfo
({
doctorId
:
userId
,
...
...
@@ -188,8 +184,8 @@ exports.doctorRegister = async ctx => {
useYn
:
'W'
,
});
doctor
.
save
();
doctorInfo
.
save
();
});
ctx
.
status
=
201
;
...
...
server/src/api/manage/manage.ctrl.js
View file @
151da40
const
User
=
require
(
'../../models/user'
);
const
DoctorInfo
=
require
(
'../../models/doctorInfo'
);
const
jwt
=
require
(
'jsonwebtoken'
);
const
{
Storage
}
=
require
(
'@google-cloud/storage'
);
const
{
viewDoctorLicense
}
=
require
(
'../../util/GoogleCloudStorage'
);
/**
...
...
@@ -110,15 +109,10 @@ exports.getDoctorRegReqDetail = async ctx => {
return
;
}
const
fileName
=
doctorInfo
.
info
.
doctorLicense
.
split
(
'/'
).
pop
();
const
file
=
new
Storage
().
bucket
(
'doctor-info'
).
file
(
fileName
);
const
option
=
{
version
:
'v4'
,
expires
:
Date
.
now
()
+
1000
*
60
*
15
,
action
:
'read'
,
};
const
[
signedUrl
]
=
file
?
await
file
.
getSignedUrl
(
option
)
:
[
''
];
const
doctorLicense
=
await
viewDoctorLicense
({
doctorInfo
});
ctx
.
status
=
200
;
ctx
.
body
=
{
...
...
@@ -126,7 +120,7 @@ exports.getDoctorRegReqDetail = async ctx => {
...
doctorInfo
.
_doc
,
info
:
{
...
doctorInfo
.
info
,
doctorLicense
:
signedUrl
,
doctorLicense
,
},
},
};
...
...
server/src/util/DataProcess.js
View file @
151da40
const
Bottle
=
require
(
'../models/bottle'
);
const
BottleMedicine
=
require
(
'../models/bottleMedicine'
);
const
TakeMedicineHist
=
require
(
'../models/takeMedicineHistory'
);
...
...
server/src/util/GoogleCloudStorage.js
0 → 100644
View file @
151da40
const
{
Storage
}
=
require
(
'@google-cloud/storage'
);
const
storage
=
new
Storage
();
const
GoogleStorageUrl
=
'https://storage.googleapis.com/'
;
//의사 아이디, 업로드할 파일명, 업로드할 파일 경로를 인자로 받아, File을 GCS에 업로드 후 GCS 주소를 반환
exports
.
uploadDoctorLicense
=
async
({
userId
,
fileName
,
filePath
})
=>
{
const
destination
=
userId
+
'_'
+
fileName
;
const
result
=
await
storage
.
bucket
(
'doctor-info'
).
upload
(
filePath
,
{
destination
,
});
const
doctorLicenseUrl
=
GoogleStorageUrl
+
`
${
result
[
0
].
bucket
.
id
}
/
${
result
[
0
].
name
}
`
;
return
doctorLicenseUrl
;
};
//의사 정보를 인자로 받아 해당 Doctor License의 Signed URL을 반환
exports
.
viewDoctorLicense
=
async
({
doctorInfo
})
=>
{
const
fileName
=
doctorInfo
.
info
.
doctorLicense
.
split
(
'/'
).
pop
();
const
file
=
new
Storage
().
bucket
(
'doctor-info'
).
file
(
fileName
);
const
option
=
{
version
:
'v4'
,
expires
:
Date
.
now
()
+
1000
*
60
*
15
,
action
:
'read'
,
};
const
[
signedUrl
]
=
file
?
await
file
.
getSignedUrl
(
option
)
:
[
null
];
return
signedUrl
;
};
//의사 ID, 약 ID, 복용량을 인자로 받아, QR Code를 생성
exports
.
prescribeMedicine
=
async
({
doctorId
,
medicineId
,
dosage
})
=>
{
//toDo
};
\ No newline at end of file
Please
register
or
login
to post a comment