Last active
September 3, 2021 08:09
-
-
Save ktmihs/61608c8f71adf3ccb78624a74f713b85 to your computer and use it in GitHub Desktop.
[node.js/Koa][React] 배열 항목 하나 추가
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Router from "koa-router" | |
import { updateTime } from "./hospitals.ctrl" | |
const hospitals = new Router() | |
hospitals.put('/:_id/:reservationTime', updateTime) | |
export default hospitals |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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