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
21da546d
Commit
21da546d
authored
Aug 04, 2021
by
Kim, Subin
Browse files
TimeTable Model&Ctrl 수정
parent
843ffe8f
Changes
2
Show whitespace changes
Inline
Side-by-side
server/controllers/timetable.controller.js
View file @
21da546d
...
@@ -5,38 +5,56 @@ const { Op } = sequelize
...
@@ -5,38 +5,56 @@ const { Op } = sequelize
const
submit
=
async
(
req
,
res
)
=>
{
const
submit
=
async
(
req
,
res
)
=>
{
try
{
try
{
console
.
log
(
"
req.body==
"
,
req
.
body
)
console
.
log
(
"
req.body==
"
,
req
.
body
)
const
{
theater
,
runtime
}
=
req
.
body
const
{
movieId
,
title
,
theater
,
runtime
,
release_date
,
date
}
=
req
.
body
const
result
=
theater
.
filter
(
async
(
theater
)
=>
{
const
result
=
await
Promise
.
all
(
const
startDate
=
getDate
(
theater
.
start
)
theater
.
map
(
async
(
theater
)
=>
{
const
endDate
=
getDate
(
theater
.
start
,
runtime
)
const
startTime
=
getTime
(
theater
.
start
)
// const isTimeTable = await TimeTable.findAll({
const
endTime
=
getTime
(
theater
.
start
,
runtime
)
// where: {
const
isTimeTable
=
await
TimeTable
.
findAll
({
// [Op.and]: [
where
:
{
// { theater: theater.theater },
[
Op
.
and
]:
[
// {
{
theater
:
theater
.
theater
},
// [Op.and]: [
{
// { start_date: { [Op.lte]: endDate } },
[
Op
.
or
]:
[
// { end_date: { [Op.gte]: startDate } }
{
[
Op
.
and
]:
[{
start_time
:
{
[
Op
.
gt
]:
startTime
}
},
{
end_time
:
{
[
Op
.
lte
]:
endTime
}
}]
},
// ]
{
start_time
:
{
[
Op
.
between
]:
[
startTime
,
endTime
]
}
}
// }
]
// ]
}
// }
]
// })
}
// [Op.or]: [{ [Op.and]: [{ start_date: { [Op.gt]: startDate } }, { start_date: { [Op.gt]: endDate } }] },
})
// { [Op.and]: [{ end_date: { [Op.lt]: startDate } }, { end_date: { [Op.lt]: endDate } }] }]
if
(
isTimeTable
.
length
!==
0
)
return
"
unvalid
"
console
.
log
(
"
isTimeTable==
"
,
isTimeTable
)
else
return
"
valid
"
return
isTimeTable
})
)
result
.
map
((
el
,
index
)
=>
{
console
.
log
(
"
idx==
"
,
index
)
if
(
el
!==
"
valid
"
)
throw
new
Error
(
"
유효하지 않은 데이터입니다. 다시 등록해주시길 바랍니다.
"
)
})
let
curDate
=
new
Date
(
release_date
)
const
endDate
=
new
Date
(
date
)
do
{
let
day
=
curDate
.
getDay
()
await
Promise
.
all
(
theater
.
map
(
async
(
theater
)
=>
{
let
partTime
=
""
if
(
'
06:00
'
<=
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
"
})
})
})
console
.
log
(
"
result==
"
,
result
)
)
curDate
.
setDate
(
curDate
.
getDate
()
+
1
)
}
while
(
curDate
<=
endDate
)
res
.
send
(
"
success!
"
)
}
catch
(
error
)
{
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영시간표 저장 중 에러 발생
"
)
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영시간표 저장 중 에러 발생
"
)
}
}
}
}
const
get
Dat
e
=
(
string
,
runtime
=
0
)
=>
{
const
get
Tim
e
=
(
string
,
runtime
=
0
)
=>
{
const
arr
=
string
.
split
(
'
:
'
)
const
arr
=
string
.
split
(
'
:
'
)
const
date
=
new
Date
(
0
,
0
,
0
,
Number
(
arr
[
0
]),
Number
(
arr
[
1
])
+
runtime
)
const
date
=
new
Date
(
0
,
0
,
0
,
Number
(
arr
[
0
]),
Number
(
arr
[
1
])
+
runtime
)
// console.log("custom==", date.toString())
return
date
return
date
}
}
...
...
server/models/timetable.model.js
View file @
21da546d
...
@@ -20,23 +20,26 @@ const TimeTableModel = (sequelize) => {
...
@@ -20,23 +20,26 @@ const TimeTableModel = (sequelize) => {
title
:
{
title
:
{
type
:
DataTypes
.
STRING
,
type
:
DataTypes
.
STRING
,
},
},
runtime
:
{
type
:
DataTypes
.
INTEGER
,
},
release_date
:
{
release_date
:
{
type
:
DataTypes
.
STRING
type
:
DataTypes
.
STRING
},
},
start_date
:
{
date
:
{
type
:
DataTypes
.
DATE
,
},
start_time
:
{
type
:
DataTypes
.
DATE
,
type
:
DataTypes
.
DATE
,
defaultValue
:
new
Date
(
0
)
defaultValue
:
new
Date
(
0
)
},
},
end_
dat
e
:
{
end_
tim
e
:
{
type
:
DataTypes
.
DATE
,
type
:
DataTypes
.
DATE
,
defaultValue
:
new
Date
(
0
)
defaultValue
:
new
Date
(
0
)
},
},
t
ime
:
{
partT
ime
:
{
type
:
DataTypes
.
TIME
,
type
:
DataTypes
.
STRING
,
},
},
week
:
{
type
:
DataTypes
.
STRING
}
},
},
{
{
// timestamps: true,
// timestamps: true,
...
...
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