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-10-07 22:22:17 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6e21c4d92d504cd881d3015e54a34b508e34afa8
6e21c4d9
1 parent
b6415e29
feat. 회원탈퇴 api 구현, 관리자 승인 api 필요
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
4 deletions
server/src/api/auth/auth.ctrl.js
server/src/api/bottle/bottle.ctrl.js
server/src/api/hub/hub.ctrl.js
server/src/models/profile.js
server/src/api/auth/auth.ctrl.js
View file @
6e21c4d
/* eslint-disable no-undef */
//회원가입, 로그인 및 로그아웃에 관한 api
const
User
=
require
(
'../../models/user'
);
const
Profile
=
require
(
'../../models/profile'
);
const
DoctorInfo
=
require
(
'../../models/doctorInfo'
);
const
Hub
=
require
(
'../../models/hub'
);
const
Bottle
=
require
(
'../../models/bottle'
);
const
{
uploadDoctorLicense
}
=
require
(
'../../util/GoogleCloudStorage'
);
const
Joi
=
require
(
'joi'
);
const
jwt
=
require
(
'jsonwebtoken'
);
...
...
@@ -80,6 +81,7 @@ exports.searchHospital = async ctx => {
const
pageSlice
=
5
;
const
url
=
'http://apis.data.go.kr/B551182/hospInfoService1/getHospBasisList1'
;
// eslint-disable-next-line no-undef
let
queryParams
=
'?'
+
encodeURIComponent
(
'ServiceKey'
)
+
'='
+
process
.
env
.
SERVICE_KEY
;
queryParams
+=
'&'
+
encodeURIComponent
(
'pageNo'
)
+
'='
+
encodeURIComponent
(
page
);
queryParams
+=
'&'
+
encodeURIComponent
(
'numOfRows'
)
+
'='
+
encodeURIComponent
(
pageSlice
);
...
...
@@ -195,7 +197,12 @@ exports.doctorRegister = async ctx => {
}
//로컬 로그인
/**
* 로컬 로그인
* @param {*} ctx
* @returns token
* http methods : POST
*/
exports
.
login
=
async
(
ctx
)
=>
{
const
{
userId
,
password
,
deviceToken
}
=
ctx
.
request
.
body
;
...
...
@@ -437,6 +444,11 @@ exports.socialLogin = async ctx => {
};
/**
* 로그아웃
* @param {*} ctx
* httm methods : POST
*/
exports
.
logout
=
async
(
ctx
)
=>
{
ctx
.
cookies
.
set
(
'access_token'
,
null
,
{
httpOnly
:
true
,
...
...
@@ -446,6 +458,67 @@ exports.logout = async(ctx) => {
ctx
.
status
=
204
;
};
/**
* 회원 탈퇴
* @param {*} ctx
* http methods : delete
*/
exports
.
secession
=
async
ctx
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
if
(
!
token
||
!
token
.
length
)
{
ctx
.
status
=
401
;
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
user
.
useYn
!==
'Y'
)
{
ctx
.
status
=
403
;
return
;
}
const
{
password
}
=
ctx
.
query
;
const
isPasswordTrue
=
await
user
.
checkPassword
(
password
);
if
(
!
isPasswordTrue
)
{
ctx
.
status
=
401
;
ctx
.
body
=
{
error
:
'비밀번호가 틀렸습니다.'
,
};
return
;
}
if
(
user
.
userTypeCd
===
'NORMAL'
)
{
const
profile
=
await
Profile
.
findOne
({
userId
});
profile
.
setUseYn
(
'N'
);
profile
.
save
();
const
hubList
=
await
Hub
.
find
({
userId
});
await
Promise
.
all
(
hubList
.
forEach
(
async
hub
=>
{
await
Bottle
.
deleteMany
({
hubId
:
hub
.
hubId
});
}));
await
Hub
.
deleteMany
({
userId
});
user
.
setUseYn
(
'N'
);
user
.
save
();
}
else
if
(
user
.
userTypeCd
===
'DOCTOR'
)
{
const
doctorInfo
=
await
DoctorInfo
.
findOne
({
doctorId
:
userId
});
doctorInfo
.
setUseYn
(
'WS'
);
doctorInfo
.
save
();
user
.
setUseYn
(
'WS'
);
user
.
save
();
}
ctx
.
status
=
200
;
};
exports
.
verifyToken
=
async
(
ctx
)
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
if
(
!
token
||
!
token
.
length
)
{
...
...
@@ -458,6 +531,7 @@ exports.verifyToken = async(ctx) => {
return
;
}
// eslint-disable-next-line no-undef
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
,
(
err
,
decoded
)
=>
{
if
(
err
)
{
ctx
.
status
=
400
;
...
...
server/src/api/bottle/bottle.ctrl.js
View file @
6e21c4d
...
...
@@ -4,6 +4,7 @@ const Bottle = require('../../models/bottle');
const
Hub
=
require
(
'../../models/hub'
);
const
Medicine
=
require
(
'../../models/medicine'
);
const
User
=
require
(
'../../models/user'
);
const
DoctorInfo
=
require
(
'../../models/doctorInfo'
);
const
PatientInfo
=
require
(
'../../models/patientInfo'
);
const
TakeMedicineHist
=
require
(
'../../models/takeMedicineHistory'
);
const
BottleMedicine
=
require
(
'../../models/bottleMedicine'
);
...
...
@@ -146,14 +147,19 @@ exports.getBottleInfo = async(ctx) => {
const
bottleMedicine
=
await
BottleMedicine
.
findOne
({
bottleId
,
useYn
:
'Y'
});
if
(
bottleMedicine
)
{
const
medicine
=
await
Medicine
.
findOne
({
medicineId
:
bottleMedicine
.
medicineId
});
const
doctorInfo
=
await
DoctorInfo
.
findOne
({
doctorId
:
bottleMedicine
.
doctorId
});
const
takeMedicineHist
=
await
TakeMedicineHist
.
find
({
bmId
:
bottleMedicine
.
_id
})
.
sort
({
takeDate
:
'desc'
})
.
populate
(
'bmId'
);
.
sort
({
takeDate
:
'desc'
});
ctx
.
status
=
200
;
ctx
.
body
=
{
bottle
,
medicine
,
doctorInfo
,
dosage
:
bottleMedicine
.
dosage
,
takeMedicineHist
,
};
...
...
@@ -161,6 +167,9 @@ exports.getBottleInfo = async(ctx) => {
ctx
.
status
=
200
;
ctx
.
body
=
{
bottle
,
medicine
:
null
,
doctorInfo
:
null
,
dosage
:
null
,
takeMedicineHist
:
[],
}
}
...
...
server/src/api/hub/hub.ctrl.js
View file @
6e21c4d
//허브(Mqtt Broker)등록 및 삭제
const
Hub
=
require
(
'../../models/hub'
);
const
Bottle
=
require
(
'../../models/bottle'
);
const
User
=
require
(
'../../models/user'
);
const
Mqtt
=
require
(
'../../util/MqttModule'
);
const
DataProcess
=
require
(
'../../util/DataProcess'
);
...
...
@@ -104,6 +105,7 @@ exports.hubDisconnect = async(ctx) => {
const
hosting
=
await
hub
.
getHubHost
();
Mqtt
.
mqttOff
(
hosting
);
await
Bottle
.
deleteMany
({
hubId
});
await
Hub
.
deleteOne
({
hubId
});
ctx
.
status
=
204
;
...
...
server/src/models/profile.js
View file @
6e21c4d
...
...
@@ -7,6 +7,7 @@ const ProfileSchema = new Schema({
userNm
:
{
type
:
String
,
required
:
true
,
},
birth
:
{
type
:
String
,
required
:
true
,
},
contact
:
{
type
:
String
,
required
:
true
,
},
useYn
:
{
type
:
String
,
default
:
'Y'
,
},
deviceToken
:
{
type
:
String
,
default
:
null
,
},
});
...
...
@@ -14,6 +15,10 @@ ProfileSchema.statics.findByUserId = function(userId) {
return
this
.
findOne
({
userId
});
};
ProfileSchema
.
statics
.
setUseYn
=
function
(
useYn
)
{
this
.
useYn
=
useYn
;
};
ProfileSchema
.
methods
.
updateUserContact
=
function
(
contact
)
{
this
.
contact
=
contact
;
};
...
...
Please
register
or
login
to post a comment