const express = require('express');
const router = express.Router();
const db = require('../models');
const ContactInfo = db.ContactInfo;

// GET current phone number
router.get('/', async (req, res) => {
  const info = await ContactInfo.findOne();
  res.json(info);
});

// UPDATE phone number
router.put('/:id', async (req, res) => {
  const { phone } = req.body;
  const info = await ContactInfo.findByPk(req.params.id);
  if (!info) return res.status(404).json({ message: 'Not found' });
  info.phone = phone;
  await info.save();
  res.json(info);
});

module.exports = router;
