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
butter-studio
Commits
931380b0
Commit
931380b0
authored
Aug 07, 2021
by
Kim, Subin
Browse files
timetableCtrl 수정 완료
parent
002ed01f
Changes
1
Hide whitespace changes
Inline
Side-by-side
server/controllers/timetable.controller.js
View file @
931380b0
import
{
TimeTable
,
Theater
}
from
"
../db/index.js
"
;
import
{
TimeTable
,
Theater
,
TheaterType
}
from
"
../db/index.js
"
;
import
moment
from
'
moment
'
;
import
sequelize
from
'
sequelize
'
const
{
Op
}
=
sequelize
...
...
@@ -8,21 +8,18 @@ const getAll = async (req, res) => {
const
{
when
}
=
req
.
query
const
selectDate
=
new
Date
(
when
)
const
theaterArr
=
[]
// const timeTableArr = []
const
findAll
=
await
TimeTable
.
findAll
({
where
:
{
date
:
selectDate
},
attributes
:
{
exclude
:
[
'
createdAt
'
,
'
updatedAt
'
]
},
order
:
[[
"
theater
"
,
"
ASC
"
],
[
"
start_time
"
,
"
ASC
"
]]
})
findAll
.
forEach
(
element
=>
{
if
(
!
theaterArr
.
includes
(
element
.
theater
))
theaterArr
.
push
(
element
.
theater
)
})
const
findTheater
=
await
Theater
.
findAll
({
where
:
{
id
:
theaterArr
},
attributes
:
{
exclude
:
[
'
createdAt
'
,
'
updatedAt
'
]
},
order
:
[[
'
theaterName
'
]]
})
const
findTheater
=
await
Theater
.
findAll
({
where
:
{
id
:
theaterArr
},
attributes
:
{
exclude
:
[
'
createdAt
'
,
'
updatedAt
'
]
},
include
:
[
TheaterType
],
order
:
[[
'
theaterName
'
]]
})
findTheater
.
forEach
(
el
=>
{
const
arr
=
findAll
.
filter
(
timetable
=>
{
if
(
el
.
id
===
timetable
.
theater
)
return
timetable
.
dataValues
})
el
.
dataValues
.
timetable
=
arr
// timeTableArr.push({ id: el.id, info: arr })
})
return
res
.
json
(
findTheater
)
// return res.json({findTheater, timeTableArr})
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영시간표 정보 가져오는 중 에러 발생
"
)
}
...
...
@@ -62,7 +59,7 @@ const submit = async (req, res) => {
await
Promise
.
all
(
theater
.
map
(
async
(
theater
)
=>
{
let
partTime
=
""
if
(
'
06:00
'
<=
theater
.
start
<
'
10:00
'
)
partTime
=
"
morning
"
if
(
'
06:00
'
<=
theater
.
start
&&
theater
.
start
<
'
10:00
'
)
partTime
=
"
morning
"
else
if
(
'
00:00
'
<=
theater
.
start
<
'
06:00
'
)
partTime
=
"
night
"
else
partTime
=
"
day
"
await
TimeTable
.
create
({
theater
:
theater
.
theater
,
movieId
,
title
,
release_date
,
date
:
curDate
,
start_time
:
getTime
(
theater
.
start
),
end_time
:
getTime
(
theater
.
start
,
runtime
),
partTime
:
partTime
,
week
:
(
day
===
0
||
day
===
6
)
?
"
weekend
"
:
"
weekdays
"
})
...
...
@@ -85,7 +82,7 @@ const getTime = (string, runtime = 0) => {
const
remove
=
async
(
req
,
res
)
=>
{
try
{
const
{
timeId
}
=
req
.
params
const
delNum
=
await
TimeTable
.
destroy
({
where
:
{}
})
const
delNum
=
await
TimeTable
.
destroy
({
where
:
{
id
:
timeId
}
})
if
(
delNum
)
res
.
json
(
delNum
)
else
throw
new
Error
(
"
해당 정보를 서버에서 삭제하는데 실패했습니다.
"
)
}
catch
(
error
)
{
...
...
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