MEAN-application with Scheduler

hi! i'm building a MEAN-application with Schedule. Trying the documentation codes i got every time a empty list when GetData and only the id when i save with BatchData

iam using angular 14 with expressjs, mongodb and mongoose


Server.js

constapp = require('./backend/app');
app.listen(3000, ()=>{
console.log('App listening on port 3000');
});


back app.js

// import express module
constexpress = require('express');
// import multer module
constmulter = require('multer');
// import path module
constpath = require('path');
// import body-parser module
constbodyParser = require('body-parser');
// import Bcrypt module
constbcrypt = require('bcrypt');
// import mongoose module
constmongoose = require('mongoose');

// connect app to DB server
mongoose.connect('mongodb://localhost:27017/crud-project');

constRoom = require('./models/room');
constBook = require('./models/book');

//create express application
constapp = express();

constappRouter = express.Router();

// Security configuration
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Headers",
"Origin, Accept, Content-Type, X-Requested-with, Authorization"
);
res.setHeader(
"Access-Control-Allow-Methods",
"GET, POST, DELETE, OPTIONS, PATCH, PUT"
);
next();
});
// Prepare Response to JSON Object to send to FE
app.use(bodyParser.json());
// Parse getted Body from FE to JSON Object
app.use(bodyParser.urlencoded({ extended:true }));

app.get('/rooms/:id', (req, res) => {
console.log('Here into get room by id', req.params.id);
Room.findOne({ _id:req.params.id }).then(
(result) => {
console.log('Result here', result);
if (result) {
res.status(200).json({
room:result
});
}
}
)
});

app.post('/rooms', (req, res) => {
console.log('here into add room', req.body);
//url = req.protocol + '://' + req.get('host');
letroom = newRoom({
office:req.body.office,
name:req.body.name
});
room.save((err, result) => {
console.log('Result after save', result);
if (err) {
console.log('here error', err);
} else {
res.status(200).json({
message:'Added with success'
});
}
});
});

app.delete('/rooms/:id', (req, res) => {
console.log('here into delete room', req.params.id);
Room.deleteOne({ _id:req.params.id }).then(
(result) => {
console.log('Result after delete', result);
if (result) {
res.status(200).json({
message:'Deleted with success'
});
}
}
)
});

app.put('/rooms/:id', (req, res) => {
console.log('update room body', req.body);
console.log('update room id', req.params.id);
Room.updateOne({ _id:req.params.id }, req.body).then(
(result) => {
if (result) {
res.status(200).json({
message:'Updated with success'
});
}
}
)
});
//Scheduler
app.get("/GetData", (req, res) => {
Book.collection('book').find({}).toArray((err, cus) => {
res.send(cus);
});
});

app.post("/BatchData", (req, res) => {
vardbo = db.db("mydb");
vareventData = [];
if (req.body.action == "insert" || (req.body.action == "batch" && req.body.added.length > 0)) {
(req.body.action == "insert") ? eventData.push(req.body.value) : eventData = req.body.added;
for (vari = 0; i < eventData.length; i++) {
varsdate = newDate(eventData[i].StartTime);
varedate = newDate(eventData[i].EndTime);
eventData[i].StartTime = (newDate(+sdate - (sdate.getTimezoneOffset() * 60000)));
eventData[i].EndTime = (newDate(+edate - (edate.getTimezoneOffset() * 60000)));
eventData[i].Subject = eventData[i].Subject;
dbo.create(eventData[i]);
console.log(eventData[i]);
}
}
if (req.body.action == "update" || (req.body.action == "batch" && req.body.changed.length > 0)) {
(req.body.action == "update") ? eventData.push(req.body.value) : eventData = req.body.changed;
for (vari = 0; i < eventData.length; i++) {
deleteeventData[i]._id;
varsdate = newDate(eventData[i].StartTime);
varedate = newDate(eventData[i].EndTime);
eventData[i].StartTime = (newDate(+sdate - (sdate.getTimezoneOffset() * 60000)));
eventData[i].EndTime = (newDate(+edate - (edate.getTimezoneOffset() * 60000)));
dbo.collection('book').updateOne({ "Id":eventData[i].Id }, { $set:eventData[i] });
}
}
if (req.body.action == "remove" || (req.body.action == "batch" && req.body.deleted.length > 0)) {
(req.body.action == "remove") ? eventData.push({ Id:req.body.key }) : eventData = req.body.deleted;
for (vari = 0; i < eventData.length; i++) {
dbo.collection('book').deleteOne({ "Id":eventData[i].Id });
}
}
res.send(req.body);
});

module.exports = app;


book.js

constmongoose = require('mongoose');
constbookSchema = mongoose.Schema({
// roomId:String,
subject:String,
startTime:Date,
endTime:Date,
isAllDay:String,
});
constbook = mongoose.model('Book', bookSchema);
module.exports = book;


component.ts

import { Component, OnInit, ViewChild } from'@angular/core';
import { ScheduleComponent, EventSettingsModel, DayService, WeekService, WorkWeekService, MonthService, View, AgendaService, ActionEventArgs } from'@syncfusion/ej2-angular-schedule';
import { Ajax } from'@syncfusion/ej2-base';
import { DataManager, UrlAdaptor } from'@syncfusion/ej2-data';

@Component({
selector:'app-book-room',
templateUrl:'./book-room.component.html',
providers: [DayService, WeekService, WorkWeekService, MonthService, AgendaService],
styleUrls: ['./book-room.component.scss']
})
exportclassBookRoomComponentimplementsOnInit {

// bookURL:string = 'http://localhost:3000/rooms/book';
// public temp = true;

privatedataManager: DataManager = newDataManager({
url:'http://localhost:3000/GetData',
crudUrl:'http://localhost:3000/BatchData',
adaptor:newUrlAdaptor,
crossDomain:true
});

  @ViewChild("scheduleObj")
publicscheduleObj: ScheduleComponent;
publicselectedDate: Date = newDate();
publicallowResizing: Boolean = false;
publicallowDragDrop: Boolean = false;
publicscheduleViews: View[] = ['Day', 'Week', 'WorkWeek', 'Month'];

publiceventSettings: EventSettingsModel = { dataSource:this.dataManager };

ngOnInit(): void {
this.selectedDate = newDate();
}


}

screen-2022-09-07--16-09-04.png


1 Reply

RM Ruksar Moosa Sait Syncfusion Team September 12, 2022 01:49 PM UTC

Hi Adel,


Greetings from Syncfusion support.


We have validated your query at our end. We suggest you refer to the below forums for binding data with the Schedule using MongoDB. If you still having a problem with binding data with the schedule let us know.


https://www.syncfusion.com/forums/148981/why-isnt-scheduler-populated-with-appointments-from-my-mongodb-server-using-mongoose

https://www.syncfusion.com/forums/150433/how-to-use-nodejs-postgresql-mysql-to-crud-schedules

https://www.syncfusion.com/forums/152620/how-do-i-retrieve-the-newly-added-appointment-from-the-mongodb-immediately-after-completion

https://www.syncfusion.com/forums/157730/crud-events-with-express-js


Regards,

Ruksar Moosa Sait


Loader.
Up arrow icon