Skip to content

Instantly share code, notes, and snippets.

@ktmihs
Last active September 3, 2021 08:09
Show Gist options
  • Save ktmihs/61608c8f71adf3ccb78624a74f713b85 to your computer and use it in GitHub Desktop.
Save ktmihs/61608c8f71adf3ccb78624a74f713b85 to your computer and use it in GitHub Desktop.
[node.js/Koa][React] 배열 항목 하나 추가
import Hospital from "../../models/hospital"
// 병원에서 예약된 시간 추가
export const updateTime = async (ctx) => {
const { _id, reservationTime } = ctx.params
let hospital
try {
hospital = await Hospital.findOneAndUpdate(
{ _id: _id }, // id로 찾아서
{
$addToSet: {
reservationTime: reservationTime, // 해당 id의 reservationTime만 업데이트(칼럼 추가)
}
}
).exec()
} catch (e) {
ctx.throw(500, e)
}
ctx.body = hospital
}
import Router from "koa-router"
import { updateTime } from "./hospitals.ctrl"
const hospitals = new Router()
hospitals.put('/:_id/:reservationTime', updateTime)
export default hospitals
import axios from 'axios'
const handleSubmit=()=>{
axios.put("/api/hospitals/"+hsp.id+'/'+reserve.dateDay) // 병원에 예약 시간 정보 저장
.then((response) => {
console.log('reservationTime:',response)
})
.catch((error) => {
console.log(error)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment