Skip to content

Instantly share code, notes, and snippets.

@ktmihs
Last active September 3, 2021 08:09
Show Gist options
  • Save ktmihs/52efe01f4cb9627cb6d699d49ec5e092 to your computer and use it in GitHub Desktop.
Save ktmihs/52efe01f4cb9627cb6d699d49ec5e092 to your computer and use it in GitHub Desktop.
[node.js/Koa][React] 배열 항목 하나 삭제
import Hospital from "../../models/hospital"
// 병원에서 예약된 시간 삭제
export const removeTime = async (ctx) => {
const { _id, reservationTime } = ctx.params
let hospital
try {
hospital = await Hospital.findOneAndUpdate(
{ _id: _id }, // id로 검색해서
{
$pull: {
reservationTime: reservationTime // 해당 id에 해당하는 reservationTime 업데이트 (칼럼 삭제)
}
}
)
} catch (e) {
ctx.throw(500, e)
}
ctx.body = hospital
}
import Router from "koa-router"
import { removeTime } from "./hospitals.ctrl"
const hospitals = new Router()
hospitals.delete('/:_id/:reservationTime',removeTime)
export default hospitals
import axios from 'axios'
import swal from 'sweetalert'
const cancelReserve=async()=>{
axios.delete('/api/hospitals/'+hsp+'/'+dateDay)
swal({ // alert과 같은 기능
text:'예약이 취소되었습니다.',
icon:'success',
confirm:{
text:'확인',
value:true
}
}).then(
props.history.push({
pathname:'/reservation',
})
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment