Skip to content

Commit f6c4e43

Browse files
ui changes and added color pallate
1 parent 761a392 commit f6c4e43

File tree

9 files changed

+762
-37
lines changed

9 files changed

+762
-37
lines changed

app/controllers/noteController.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Note = require('../models/note')
2+
const io = require('../../index')
23

34

45
module.exports.listItem = (req,res)=>{
@@ -25,9 +26,10 @@ module.exports.getItem = (req,res)=>{
2526

2627
module.exports.postItem = (req,res)=>{
2728
const body = req.body
28-
const note = new Note({title:body.title,body:body.body})
29+
const note = new Note({title:body.title,body:body.body,color:body.color})
2930
note.save()
3031
.then((note)=>{
32+
global.io.emit("added",note)
3133
res.json(note)
3234
})
3335
.catch(err =>{
@@ -41,6 +43,7 @@ module.exports.updateItem = (req,res)=>{
4143
Note.findByIdAndUpdate(id,body,{new:true})
4244
.then(note =>{
4345
if(note){
46+
global.io.emit("updated",note)
4447
res.json(note)
4548
}
4649
else{
@@ -58,6 +61,7 @@ module.exports.deleteItem = (req,res)=>{
5861
Note.findByIdAndDelete(id)
5962
.then(note=>{
6063
if(note){
64+
global.io.emit("deleted",note)
6165
res.json(note)
6266
}else{
6367
res.json({})

app/models/note.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const Schema = mongoose.Schema
33
const noteSchema = new Schema({
44
title:{type:String},
55
body:{type:String},
6+
color:{type:Object,default:{r:0,g:0,b:0,a:0}},
67
createdAt:{type:Date,default:Date.now()}
78
})
89

index.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
const express = require('express')
2+
const path = require('path')
23
const route = require('./config/routes')
3-
const port = 3010
4-
const app = express()
5-
app.use(express.json())
64
const connectDB = require('./config/database')
75
const cors = require('cors')
6+
const http = require('http')
7+
const socketIo = require('socket.io')
88

9+
10+
const publicPath = path.join(__dirname,'/ui/public')
11+
const port = 3010
12+
const app = express()
13+
let server = http.createServer(app);
14+
let io = socketIo(server);
15+
global.io = io;
16+
17+
18+
app.use(express.json())
19+
app.use(express.static(publicPath));
920
app.use(cors())
21+
22+
1023
connectDB()
1124
app.use('/',route)
1225

26+
io.on('connection', (socket)=>{
27+
console.log('client Connected')
28+
socket.on('disconnect',() => console.log('client is disconnected'))
29+
})
1330

14-
app.listen(port,()=>{
31+
server.listen(port,()=>{
1532
console.log('listening to port',port)
1633
})

0 commit comments

Comments
 (0)