Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
eue
Commits
779dc0af
Commit
779dc0af
authored
Jul 30, 2021
by
KangMin An
Browse files
Update: DB 모델 변수명 수정 및 모델 추가.사용자 정보 추가 반환.
parent
1919dcb1
Changes
9
Hide whitespace changes
Inline
Side-by-side
server/src/controllers/dataController.js
View file @
779dc0af
...
...
@@ -17,7 +17,7 @@ const handleOutData = async (locCode, date, lat, lng) => {
const
press
=
json
[
"
main
"
][
"
pressure
"
];
const
wind_speed
=
json
[
"
wind
"
][
"
speed
"
];
await
db
.
Weather_
o
ut
.
create
(
await
db
.
Weather_
O
ut
.
create
(
{
loc_code
:
Number
(
locCode
),
collected_at
:
date
,
...
...
@@ -34,7 +34,7 @@ const handleOutData = async (locCode, date, lat, lng) => {
// 내부 수집기로 부터 들어온 정보 처리
const
handleInData
=
async
(
email
,
date
,
temp
,
humi
,
lights
)
=>
{
await
db
.
Weather_
i
n
.
create
(
await
db
.
Weather_
I
n
.
create
(
{
host
:
email
,
collected_at
:
date
,
...
...
@@ -92,12 +92,12 @@ export const getUserWeatherData = (req, res) => {
try
{
/* 사용자 email에 따른 사용자 날씨 데이터 가져오기 */
const
decoded
=
jwt
.
decode
(
acs_token
);
const
result
=
db
.
Weather_
i
n
.
findAll
({
const
result
=
db
.
Weather_
I
n
.
findAll
({
where
:
{
host
:
decoded
.
email
},
logging
:
false
,
});
res
.
json
({
msg
:
resForm
.
msg
.
ok
,
contents
:
{
weather_
user
:
result
}
});
res
.
json
({
msg
:
resForm
.
msg
.
ok
,
contents
:
{
weather_
in
:
result
}
});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
msg
:
resForm
.
msg
.
err
,
contents
:
{
error
:
err
}
});
...
...
@@ -111,7 +111,7 @@ export const getOutWeatherData = (req, res) => {
}
=
req
;
try
{
// 실외 지역 번호를 통해 날씨 데이터 전송.
const
result
=
db
.
Weather_
o
ut
.
findAll
({
const
result
=
db
.
Weather_
O
ut
.
findAll
({
where
:
{
loc_code
:
loc_code
},
logging
:
false
,
});
...
...
server/src/controllers/userController.js
View file @
779dc0af
...
...
@@ -150,9 +150,10 @@ export const getConfirm = async (req, res) => {
subject
:
"
userInfo
"
,
});
res
.
cookie
(
"
acs_token
"
,
accessT
)
.
redirect
(
`
${
envs
.
client
.
host
}
:
${
envs
.
client
.
port
}
`
);
res
.
cookie
(
"
acs_token
"
,
accessT
).
redirect
(
"
/api
"
);
// .redirect(
// `${envs.client.protocol}://${envs.client.host}:${envs.client.port}`
// );
}
catch
(
err
)
{
res
.
json
({
msg
:
resForm
.
msg
.
err
,
contents
:
{
error
:
err
}
});
}
...
...
@@ -164,11 +165,56 @@ export const getUserInfo = async (req, res) => {
cookies
:
{
acs_token
},
}
=
req
;
const
decoded
=
jwt
.
decode
(
acs_token
);
try
{
const
decoded
=
jwt
.
decode
(
acs_token
);
const
result_user
=
await
db
.
User
.
findAll
({
where
:
{
email
:
decoded
.
email
},
logging
:
false
,
});
let
user
=
{
email
:
result_user
[
0
].
email
,
nick_name
:
result_user
[
0
].
nick_name
,
using_aircon
:
result_user
[
0
].
using_aircon
,
created_at
:
result_user
[
0
].
created_at
,
loc_code
:
result_user
[
0
].
loc_code
,
};
if
(
user
.
loc_code
)
{
let
loc_name
=
{};
const
result_emd
=
await
db
.
Emd
.
findAll
({
where
:
{
code_emd
:
user
.
loc_code
,
},
logging
:
false
,
});
const
result
=
await
db
.
User
.
findAll
({
where
:
{
email
:
decoded
.
email
}
});
const
result_doe
=
await
db
.
Doe
.
findAll
({
where
:
{
code_doe
:
result_emd
[
0
].
code_doe
,
},
logging
:
false
,
});
res
.
status
(
resForm
.
code
.
ok
).
json
({
user_info
:
result
});
const
result_sgg
=
await
db
.
Sgg
.
findAll
({
where
:
{
code_sgg
:
result_emd
[
0
].
code_sgg
,
},
logging
:
false
,
});
loc_name
.
doe
=
result_doe
[
0
].
name_doe
;
loc_name
.
sgg
=
result_sgg
[
0
].
name_sgg
;
loc_name
.
emd
=
result_emd
[
0
].
name_emd
;
user
.
loc_name
=
loc_name
;
}
res
.
json
({
msg
:
resForm
.
msg
.
ok
,
contents
:
{
user_info
:
[
user
]
}
});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
msg
:
resForm
.
msg
.
err
,
contents
:
{
error
:
err
}
});
}
};
// 사용자 정보 수정 요청 처리
...
...
@@ -178,14 +224,40 @@ export const postEditProfile = async (req, res) => {
body
:
{
nick_name
,
loc_code
,
using_aircon
},
}
=
req
;
const
decoded
=
jwt
.
decode
(
acs_token
);
try
{
const
decoded
=
jwt
.
decode
(
acs_token
);
await
db
.
User
.
update
(
{
nick_name
:
nick_name
,
loc_code
:
loc_code
,
using_aircon
},
{
where
:
{
email
:
decoded
.
email
}
}
);
const
result_preuser
=
await
db
.
User
.
findAll
({
where
:
{
email
:
decoded
.
email
},
logging
:
false
,
});
const
user
=
result_preuser
[
0
];
const
result
=
await
db
.
User
.
findAll
({
where
:
{
email
:
decoded
.
email
}
});
let
new_nick_name
=
nick_name
?
nick_name
:
user
.
nick_name
;
let
new_loc_code
=
loc_code
?
Number
(
loc_code
)
:
Number
(
user
.
loc_code
);
let
new_using_aircon
=
using_aircon
?
using_aircon
===
"
true
"
:
user
.
using_aircon
;
res
.
json
({
msg
:
resForm
.
msg
.
ok
,
contents
:
{
user_info
:
result
}
});
await
db
.
User
.
update
(
{
nick_name
:
new_nick_name
,
loc_code
:
new_loc_code
,
using_aircon
:
new_using_aircon
,
},
{
where
:
{
email
:
decoded
.
email
}
}
);
const
result_after_user
=
await
db
.
User
.
findAll
({
where
:
{
email
:
decoded
.
email
},
});
res
.
json
({
msg
:
resForm
.
msg
.
ok
,
contents
:
{
user_info
:
result_after_user
},
});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
msg
:
resForm
.
msg
.
err
,
contents
:
{
error
:
err
}
});
}
};
server/src/db/index.js
View file @
779dc0af
...
...
@@ -4,8 +4,9 @@ import Doe from "../models/doe";
import
Sgg
from
"
../models/sgg
"
;
import
Emd
from
"
../models/emd
"
;
import
User
from
"
../models/user
"
;
import
Weather_in
from
"
../models/weather_in
"
;
import
Weather_out
from
"
../models/weather_out
"
;
import
Weather_In
from
"
../models/weather_in
"
;
import
Weather_Out
from
"
../models/weather_out
"
;
import
Data_Processing
from
"
../models/data_processing
"
;
// DB의 정보를 모두 담고 있는 객체 생성
const
db
=
{};
...
...
@@ -37,19 +38,23 @@ Emd.init(sequelize);
db
.
User
=
User
;
User
.
init
(
sequelize
);
db
.
Weather_
i
n
=
Weather_
i
n
;
Weather_
i
n
.
init
(
sequelize
);
db
.
Weather_
I
n
=
Weather_
I
n
;
Weather_
I
n
.
init
(
sequelize
);
db
.
Weather_out
=
Weather_out
;
Weather_out
.
init
(
sequelize
);
db
.
Weather_Out
=
Weather_Out
;
Weather_Out
.
init
(
sequelize
);
db
.
Data_Processing
=
Data_Processing
;
Data_Processing
.
init
(
sequelize
);
// model들 간에 Association 생성
Doe
.
associate
(
db
);
Sgg
.
associate
(
db
);
Emd
.
associate
(
db
);
User
.
associate
(
db
);
Weather_in
.
associate
(
db
);
Weather_out
.
associate
(
db
);
Weather_In
.
associate
(
db
);
Weather_Out
.
associate
(
db
);
Data_Processing
.
associate
(
db
);
// Messages for Data Base.
const
msg
=
{
...
...
server/src/models/data_processing.js
0 → 100644
View file @
779dc0af
import
{
DataTypes
,
Model
}
from
"
sequelize
"
;
import
User
from
"
./user
"
;
export
class
Data_Processing
extends
Model
{
static
init
(
sequelize
)
{
return
super
.
init
(
{
host
:
{
type
:
DataTypes
.
STRING
(
320
),
primaryKey
:
true
,
references
:
{
model
:
User
,
key
:
"
email
"
,
},
},
collected_at
:
{
type
:
DataTypes
.
DATE
,
primaryKey
:
true
,
defaultValue
:
Date
.
now
(),
},
params
:
{
type
:
DataTypes
.
JSON
,
},
},
{
sequelize
,
timestamps
:
false
,
paranoid
:
false
,
}
);
}
static
associate
(
db
)
{
db
.
Data_Processing
.
belongsTo
(
db
.
User
,
{
foreignKey
:
"
host
"
,
targetKey
:
"
email
"
,
});
}
}
export
default
Data_Processing
;
server/src/models/emd.js
View file @
779dc0af
...
...
@@ -49,7 +49,7 @@ export class Emd extends Model {
onDelete
:
"
CASCADE
"
,
onUpdate
:
"
CASCADE
"
,
});
db
.
Emd
.
hasMany
(
db
.
Weather_
o
ut
,
{
db
.
Emd
.
hasMany
(
db
.
Weather_
O
ut
,
{
foreignKey
:
"
loc_code
"
,
sourceKey
:
"
code_emd
"
,
onDelete
:
"
CASCADE
"
,
...
...
server/src/models/user.js
View file @
779dc0af
...
...
@@ -47,9 +47,15 @@ export class User extends Model {
});
// User 모델을 참조하는 테이블에 대한 외래키 설정.
db
.
User
.
hasMany
(
db
.
Weather_
i
n
,
{
db
.
User
.
hasMany
(
db
.
Weather_
I
n
,
{
foreignKey
:
"
host
"
,
sourveKey
:
"
email
"
,
sourceKey
:
"
email
"
,
onDelete
:
"
CASCADE
"
,
onUpdate
:
"
CASCADE
"
,
});
db
.
User
.
hasMany
(
db
.
Data_Processing
,
{
foreignKey
:
"
host
"
,
sourceKey
:
"
email
"
,
onDelete
:
"
CASCADE
"
,
onUpdate
:
"
CASCADE
"
,
});
...
...
server/src/models/weather_in.js
View file @
779dc0af
...
...
@@ -40,7 +40,7 @@ export class Weather_In extends Model {
static
associate
(
db
)
{
// weather_in 모델이 참조하는 테이블에 대한 외래키 설정.
db
.
Weather_
i
n
.
belongsTo
(
db
.
User
,
{
db
.
Weather_
I
n
.
belongsTo
(
db
.
User
,
{
foreignKey
:
"
host
"
,
targetKey
:
"
email
"
,
});
...
...
server/src/models/weather_out.js
View file @
779dc0af
...
...
@@ -44,7 +44,7 @@ export class Weather_Out extends Model {
static
associate
(
db
)
{
// weather_out 모델이 참조하는 테이블에 대한 외래키 설정.
db
.
Weather_
o
ut
.
belongsTo
(
db
.
Emd
,
{
db
.
Weather_
O
ut
.
belongsTo
(
db
.
Emd
,
{
foreignKey
:
"
loc_code
"
,
targetKey
:
"
code_emd
"
,
});
...
...
server/src/views/edit-profile.pug
View file @
779dc0af
block content
.signup-form_container
form(action = routes.base + routes.editProfile, method = "post")
input(type="text", name="nick_name", require=true, placeholder="Nick Name")
input(type="number", name="loc_code", require=true, placeholder="Local Code.")
input(type="text", name="nick_name", placeholder="Nick Name")
input(type="text", name="using_aircon", placeholder="Using Aircon? true or false" )
input(type="number", name="loc_code", placeholder="Local Code.")
input(type="submit", value="Submit")
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment