import express from 'express';
import cors from 'cors';

import getResultName from './getResultName';
import canonize from './canonize';

const app = express();
app.use(cors());
app.get('/', (req, res) => {
  res.json({
    hello: 'JS World',
  });
});

app.get('/2A', (req, res) => {
  const sum = (+req.query.a || 0) + (+req.query.b || 0);
  res.send(sum.toString());
});

app.get('/2B', (req, res) => {
  const fullname = req.query.fullname;
  res.send(getResultName(fullname.toString()));
});

app.get('/2C', (req, res) => {
  const username = req.query.username;
  res.send(canonize(username.toString()));
});

app.listen(3000, () => {
  console.log('Your app listening on port 3000!');
});
