This file contains 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
diff --git a/docker-compose.yml b/docker-compose.yml | |
index 94302ff..19dff7a 100644 | |
--- a/docker-compose.yml | |
+++ b/docker-compose.yml | |
@@ -1,7 +1,7 @@ | |
version: '3.9' | |
services: | |
api: | |
- build: . | |
+ build: node:latest |
This file contains 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
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const jwt = require('jsonwebtoken'); | |
const router = express.Router(); | |
const config = require('./config'); | |
const utils = require('./utils'); | |
const tokenList = {}; | |
const app = express(); | |
router.get('/', (req, res) => { |
This file contains 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
// src/app.ts | |
import express, { Router } from 'express'; | |
import callStateController from './controllers/call.state.controller'; | |
import * as path from 'path'; | |
const app = express(); | |
app.use(express.json()); | |
app.get('/', (req, res) => { | |
res.sendFile(path.join(process.env.PUBLIC_DIR as string, 'index.html')); |
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Tiny CRM</title> | |
<style> | |
body { | |
padding: 10px; | |
font-size: 18px; | |
} |
This file contains 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
// src/call-state.controller.ts | |
import { Request, Response } from 'express'; | |
import CustomerModel from '../models/customer.model'; | |
import CallStateModel from '../models/call.state.model'; | |
import { emitCallStateChange } from '../socket'; | |
import moment from 'moment'; | |
const callStateController = { | |
handleNewCallState: async (req: Request, res: Response) => { | |
try { |
This file contains 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
// src/server.ts | |
import * as http from 'http'; | |
import dotenv from 'dotenv'; | |
import app from './app'; | |
import mongoose from 'mongoose'; | |
import { initSocketIo } from './socket'; | |
(async () => { | |
dotenv.config(); |
This file contains 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
// src/socket.ts | |
import { Server } from 'socket.io'; | |
import * as http from 'http'; | |
let io: Server; | |
export function initSocketIo(server: http.Server) { | |
if (io) { | |
return; | |
} |
This file contains 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
// src/controllers/call-state.controller.ts | |
import { Request, Response } from 'express'; | |
import CustomerModel from '../models/customer.model'; | |
import CallStateModel from '../models/call.state.model'; | |
const callStateController = { | |
handleNewCallState: async (req: Request, res: Response) => { | |
try { | |
const { phone_number: phoneNumber, state, timestamp } = req.body; |
This file contains 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
// src/models/call-state.model.ts | |
import { Schema, Model, model, ObjectId } from 'mongoose'; | |
import CustomerModel from './customer.model'; | |
export enum CallState { | |
RINGING = 'RINGING', | |
OFFHOOK = 'OFFHOOK', | |
IDLE = 'IDLE', | |
} |
This file contains 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
// src/models/customer.model.ts | |
import { Schema, Model, model } from 'mongoose'; | |
export interface ICustomer { | |
name: string; | |
phoneNumber: string; | |
} | |
const CustomerSchema = new Schema<ICustomer, Model<ICustomer>, ICustomer>({ | |
name: { |