diff --git a/index.ts b/index.ts index df09d60..dbbafaf 100644 --- a/index.ts +++ b/index.ts @@ -1,26 +1,25 @@ -import express from 'express'; -import cors from 'cors'; import * as path from 'path'; -import apiRouter from './src/api'; + import bodyParser from 'body-parser'; +import cors from 'cors'; +import express from 'express'; + +import apiRouter from './src/api'; const app = express(); const port = 5000; -app.use(cors()) -app.use('/static', express.static(path.join(__dirname, 'static'))) -// app.use(express.static(path.join(__dirname, 'static'))) -// @ts-ignore +app.use(cors()); +app.use('/static', express.static(path.join(__dirname, 'static'))); + app.use(bodyParser.raw({ type: 'application/soap+xml' })); app.use(bodyParser.json({ limit: '20mb' })); -// app.use(express.urlencoded({ extended: false })); -// @ts-ignore + app.use(express.json()); -app.use('/api', apiRouter) - +app.use('/api', apiRouter); app.listen(port, () => { + // eslint-disable-next-line no-console console.log(`Arkids backend app start on port ${port}`); }); - diff --git a/package.json b/package.json index 74c6a0b..5c84a63 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "body-parser": "1.20.2", "cors": "2.8.5", "express": "4.18.2", + "nodemailer": "^6.9.3", "nodemon": "2.0.22", "ts-node": "10.9.1", "typescript": "5.0.4", diff --git a/src/api/index.ts b/src/api/index.ts index 223c460..cfbf983 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -13,6 +13,7 @@ import servicesRouter from './routes/services'; import statisticsRouter from './routes/statistic'; import storiesRouter from './routes/stories'; import textRouter from './routes/text'; +import orderRouter from './routes/order'; const apiRouter = express.Router(); @@ -27,5 +28,6 @@ apiRouter.use(ApiRoute.STORIES, storiesRouter); apiRouter.use(ApiRoute.STATISTIC_INFO, statisticsRouter); apiRouter.use(ApiRoute.QUESTS, questRouter); apiRouter.use(ApiRoute.IMAGE, imageRouter); +apiRouter.use(ApiRoute.ORDER, orderRouter); export default apiRouter; diff --git a/src/api/routes/order/controller.ts b/src/api/routes/order/controller.ts new file mode 100644 index 0000000..7783735 --- /dev/null +++ b/src/api/routes/order/controller.ts @@ -0,0 +1,93 @@ +import { Request, Response } from 'express'; + +import mailer from '../../../services/mailer'; +import { formatter } from '../../../utils'; + +export const getNewOrder = async (req: Request, res: Response) => { + // @ts-ignore + const { + name, + page, + phoneNumber, + rate, + type, + } = req.body; + + const getSubject = () => { + switch (type) { + case 'callback': + return 'Заявка на звонок'; + + case 'newRate': + return 'Заявка на комбо'; + + default: + return 'Нужно связаться'; + } + }; + + const getHtml = () => { + const getPageTitle = () => { + if (page === 'birthday') { + return 'День рождения'; + } + + if (page === 'graduation') { + return 'Выпускной'; + } + + return 'Выездной праздник'; + }; + switch (type) { + case 'callback': + return ` +
Имя: ${name}
+Телефон: ${phoneNumber}
+ `; + + case 'newRate': + return ` +Имя: ${name}
+Телефон: ${phoneNumber}
+Страница: ${getPageTitle()}
+Пакет: ${rate.title}
+Цена пакета: ${formatter.format(rate.price || rate.pricePerPerson)}
+ `; + + default: + return 'ошибка'; + } + }; + + async function main() { + const info = await mailer.sendMail({ + from: '"Arkids Test"