First Commit
BIN
app/.DS_Store
vendored
Normal file
BIN
app/config/.DS_Store
vendored
Normal file
3
app/config/auth.config.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
secret: "worldshine-secret-key"
|
||||
}
|
||||
15
app/config/db.config.js
Normal file
@ -0,0 +1,15 @@
|
||||
const devUri = "mongodb://localhost:27017/worldshine";
|
||||
const localUri = "mongodb+srv://new-user-test:Testing123@cluster0.qkzim.mongodb.net/leapbase?retryWrites=true&w=majority";
|
||||
module.exports = {
|
||||
baseUrl: "mongodb://localhost:27017/",
|
||||
fileUrl: "https://worldshine.mayo.llc/files/",
|
||||
database: "worldshine",
|
||||
url: devUri,
|
||||
|
||||
// on local enable this
|
||||
// url: localUri,
|
||||
// baseUrl: "mongodb+srv://new-user-test:Testing123@cluster0.qkzim.mongodb.net/",
|
||||
// database: "leapbase",
|
||||
// fileUrl: "http://localhost:8080/files/",
|
||||
// imgBucket: "photos",
|
||||
};
|
||||
60
app/controllers/auth.controller.js
Normal file
@ -0,0 +1,60 @@
|
||||
const db = require("../models");
|
||||
const Employee = db.employee;
|
||||
const config = require("../config/auth.config");
|
||||
|
||||
var jwt = require("jsonwebtoken");
|
||||
var bcrypt = require("bcryptjs");
|
||||
const { splitSite } = require("../middlewares");
|
||||
|
||||
// Create and Save a new User
|
||||
exports.login = (req, res) => {
|
||||
var condition = {};
|
||||
const emailUsername = req.body.emailUsername;
|
||||
console.log('emailUsername', emailUsername);
|
||||
if (emailUsername) {
|
||||
condition = { $or: [
|
||||
{ email: emailUsername },
|
||||
{ username: emailUsername }
|
||||
]};
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
|
||||
Employee.find(condition)
|
||||
.then(data => {
|
||||
if (data && data.length > 0) {
|
||||
if (data.length === 1 && bcrypt.compareSync(
|
||||
req.body.password,
|
||||
data[0].password
|
||||
) && data[0]?.status === 'active') {
|
||||
var token = jwt.sign({id: data[0].id}, config.secret, {
|
||||
expiresIn: 86400 // 24 hours
|
||||
});
|
||||
res.send({
|
||||
accessToken: token,
|
||||
username: data[0].username,
|
||||
email: data[0].email,
|
||||
roles: data[0].roles,
|
||||
id: data[0].id,
|
||||
name: data[0].name,
|
||||
name_cn: data[0].name_cn
|
||||
} );
|
||||
} else {
|
||||
if (data[0].status !== 'active') {
|
||||
throw(Error('User is not activated'));
|
||||
} else {
|
||||
throw(Error('Email or Password Is Invalid'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw(Error('Email or Password Is Invalid'));
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Email Or Password Invalid"
|
||||
});
|
||||
});
|
||||
} else {
|
||||
throw(Error('email or username is required'));
|
||||
}
|
||||
}
|
||||
119
app/controllers/breakfast.controller.js
Normal file
@ -0,0 +1,119 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const Breakfast = db.breakfast;
|
||||
|
||||
// Create a new Breakfast Item
|
||||
exports.createNewBreakfast = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.customer_id) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create an Breakfast Item
|
||||
const breakfast = new Breakfast({
|
||||
customer_id: req.body.customer_id,
|
||||
customer_name: req.body.customer_name,
|
||||
has_breakfast: req.body.has_breakfast,
|
||||
create_by: req.body.create_by,
|
||||
create_date: req.body.create_date,
|
||||
edit_history: req.body.edit_history,
|
||||
date: req.body.date,
|
||||
site
|
||||
});
|
||||
// Save breakfast Item in the database
|
||||
breakfast
|
||||
.save(breakfast)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Breakfast Record."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Retrive all Breakfast Records from database.
|
||||
exports.getAllBreakfasts = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
if (params.date) {
|
||||
condition.date = params.date;
|
||||
}
|
||||
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
Breakfast.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Breakfasts."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Get One Event by Id
|
||||
// exports.getEvent = (req, res) => {
|
||||
// const id = req.params.id;
|
||||
// CalendarEvent.findById(id)
|
||||
// .then(data => {
|
||||
// if (!data)
|
||||
// res.status(404).send({ message: "Not found Event with id " + id });
|
||||
// else res.send(data);
|
||||
// })
|
||||
// .catch(err => {
|
||||
// res
|
||||
// .status(500)
|
||||
// .send({ message: "Error retrieving Event with id=" + id });
|
||||
// });
|
||||
// };
|
||||
|
||||
// Update a Breakfast by the id in the request
|
||||
exports.updateBreakfast = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
Breakfast.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Breakfast with id=${id}. Maybe Breakfast was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Breakfast was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Breakfast with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Delete a Breakfast by id
|
||||
exports.deleteBreakfast= (req, res) => {
|
||||
const id = req.params.id;
|
||||
Breakfast.findByIdAndRemove(id)
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot delete Breakfast with id=${id}. Maybe Breakfast was not found!`
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
message: "Breakfast was deleted successfully!"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message: "Could not delete Breakfast with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
234
app/controllers/calendar-event.controller.js
Normal file
@ -0,0 +1,234 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const CalendarEvent = db.calendar_event;
|
||||
const moment = require("moment-timezone");
|
||||
|
||||
// Create a new Event
|
||||
exports.createCalendarEvent = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.start_time) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create an Event
|
||||
const calendarEvent = new CalendarEvent({
|
||||
title: req.body.title,
|
||||
type: req.body.type,
|
||||
description: req.body.description,
|
||||
department: req.body.department,
|
||||
notes: req.body.notes,
|
||||
start_time: req.body.start_time,
|
||||
stop_time: req.body.stop_time,
|
||||
source_type: req.body.source_type,
|
||||
source_uuid: req.body.source_uuid,
|
||||
source_name: req.body.source_name,
|
||||
target_type: req.body.target_type,
|
||||
target_uuid: req.body.target_uuid,
|
||||
target_name: req.body.target_name,
|
||||
link_event_uuid: req.body.link_event_uuid,
|
||||
link_event_name: req.body.link_event_name,
|
||||
data: req.body.data,
|
||||
color: req.body.color,
|
||||
confirmed: req.body.confirmed || false,
|
||||
files: req.body.files,
|
||||
status: req.body.status || 'active',
|
||||
signup_start_date: req.body.signup_start_date,
|
||||
member_col: req.body.member_col,
|
||||
new_patient: req.body.new_patient,
|
||||
tags: req.body.tags,
|
||||
create_by: req.body.create_by,
|
||||
create_date: req.body.create_date,
|
||||
edit_by: req.body.create_by,
|
||||
edit_date: req.body.create_date,
|
||||
youtube_video_id: req.body.youtube_video_id,
|
||||
edit_history: req.body.edit_history,
|
||||
site
|
||||
});
|
||||
// Save event in the database
|
||||
calendarEvent
|
||||
.save(calendarEvent)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Calendar Event."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Retrive all events from database.
|
||||
exports.getAllEvents = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
if (params.date) {
|
||||
condition['start_time'] = {
|
||||
$gte: moment(params.date + ' 00:00:00:000').toDate(),
|
||||
$lt: moment(params.date + ' 23:59:59.999').toDate()
|
||||
};
|
||||
}
|
||||
if (params.from && params.to) {
|
||||
condition['start_time'] = {
|
||||
$gte: moment(params.from + ' 00:00:00.000').toDate(),
|
||||
$lt: moment(params.to+ ' 23:59:59.999').toDate()
|
||||
};
|
||||
}
|
||||
if (params.start_date && params.end_date) {
|
||||
// for FullCalendar, if has start_date and end_date, format: YYYY-MM-DD
|
||||
// FullCalendar gives start_date and end_date, end_date is day+1 of current view
|
||||
condition['start_time'] = {
|
||||
$gte: moment(parameter.start_date + 'T00:00:00:00', "America/New_York").toDate()
|
||||
};
|
||||
condition['stop_time'] = {
|
||||
$lt: moment(parameter.end_date + 'T00:00:00:00', "America/New_York").toDate()
|
||||
};
|
||||
}
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
CalendarEvent.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Events."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.getEventsByCustomer = (req, res) => {
|
||||
var params = req.query;
|
||||
const name_cn = params.namecn || '';
|
||||
const name = params.name;
|
||||
const id = params.id;
|
||||
if (id && name) {
|
||||
var ObjectId = require('mongoose').Types.ObjectId;
|
||||
var objId = new ObjectId(id);
|
||||
const regex = new RegExp(name_cn, 'i') // i for case insensitive
|
||||
CalendarEvent.find( { $or:[ { data: {'customer':objId}}, {data: {'customer':id}}, {'target_name': name }, {'target_name': {$regex: regex}} ]}).then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Events for customers."
|
||||
});
|
||||
});
|
||||
} else {
|
||||
res.send({data: []});
|
||||
}
|
||||
};
|
||||
|
||||
// Get One Event by Id
|
||||
exports.getEvent = (req, res) => {
|
||||
const id = req.params.id;
|
||||
CalendarEvent.findById(id)
|
||||
.then(data => {
|
||||
if (!data)
|
||||
res.status(404).send({ message: "Not found Event with id " + id });
|
||||
else res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res
|
||||
.status(500)
|
||||
.send({ message: "Error retrieving Event with id=" + id });
|
||||
});
|
||||
};
|
||||
|
||||
// Update a Event by the id in the request
|
||||
exports.updateEvent = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
CalendarEvent.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Event with id=${id}. Maybe Event was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Event was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Event with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// assign driver to the transportation Event
|
||||
exports.assignTransportationToEvents = (req, res) => {
|
||||
var ids = req.body.eventIds || [];
|
||||
var transportationId = req.body.transportationId;
|
||||
var transportationName = req.body.transportationName;
|
||||
// ids.forEach(id => {
|
||||
// CalendarEvent.findByIdAndUpdate(id, {link_event_uuid: transportationId,
|
||||
// link_event_name: transportationName}, { useFindAndModify: false })
|
||||
// .then(data => {
|
||||
// if (!data) {
|
||||
// res.status(404).send({
|
||||
// message: `Cannot update Event with id=${id}. Maybe Event was not found!`
|
||||
// });
|
||||
// } else res.send({ success: true, message: "Event was updated successfully." });
|
||||
// })
|
||||
// .catch(err => {
|
||||
// res.status(500).send({
|
||||
// success: false,
|
||||
// message: "Error updating Event with id=" + id
|
||||
// });
|
||||
// });
|
||||
// })
|
||||
Promise.all(ids.map((id) => CalendarEvent.findByIdAndUpdate(id, {link_event_uuid: transportationId,
|
||||
link_event_name: transportationName}, { useFindAndModify: false }))).then((data) => {
|
||||
if (data) {
|
||||
res.send({ success: true, message: "Event was updated successfully." });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Disable an Event by the id in the request
|
||||
exports.disableEvent = (req, res) => {
|
||||
const id = req.params.id;
|
||||
CalendarEvent.findByIdAndUpdate(id, { ...req.body, status: 'inactive'}, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Event with id=${id}. Maybe Event was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Event was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Event with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Delete a Event by id
|
||||
exports.deleteEvent= (req, res) => {
|
||||
const id = req.params.id;
|
||||
CalendarEvent.findByIdAndRemove(id)
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot delete Event with id=${id}. Maybe Event was not found!`
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
message: "Event was deleted successfully!"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message: "Could not delete Event with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
87
app/controllers/center-phone.controller.js
Normal file
@ -0,0 +1,87 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const CenterPhone = db.center_phone;
|
||||
// Create and Save a new Center Phone
|
||||
exports.createCenterPhone = (req, res) => {
|
||||
// Create a Center Phone
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
const centerPhone = new CenterPhone({
|
||||
activated: true,
|
||||
phone_title: req.body.phone_title || '',
|
||||
phone_number: req.body.phone_number || '',
|
||||
site
|
||||
});
|
||||
|
||||
// Save centerPhone in the database
|
||||
centerPhone
|
||||
.save(centerPhone)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Center phone."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Phones from the database.
|
||||
exports.getAllCenterPhones = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
if (params) {
|
||||
condition = splitSite.splitSiteGet(req, params);
|
||||
if (params.activated) {
|
||||
condition.activated = params.activated;
|
||||
}
|
||||
}
|
||||
CenterPhone.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving phones."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Get One Phone by Id
|
||||
exports.getCenterPhone = (req, res) => {
|
||||
const id = req.params.id;
|
||||
CenterPhone.findById(id)
|
||||
.then(data => {
|
||||
if (!data)
|
||||
res.status(404).send({ message: "Not found Center Phone with id " + id });
|
||||
else res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res
|
||||
.status(500)
|
||||
.send({ message: "Error retrieving Center Phone with id=" + id });
|
||||
});
|
||||
};
|
||||
// Update a CenterPhone by the id in the request
|
||||
exports.updateCenterPhone = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
CenterPhone.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Center Phone with id=${id}. Maybe Center Phone was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Center Phone was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error" + (err.message || "") + "updating Center Phone with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
132
app/controllers/client.controller.js
Normal file
@ -0,0 +1,132 @@
|
||||
const db = require("../models");
|
||||
const Client = db.client;
|
||||
var bcrypt = require("bcryptjs");
|
||||
// Create and Save a new Client
|
||||
exports.createClient = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.name) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
// Create a Client
|
||||
const client = new Client({
|
||||
username: req.body.username || req.body.email || '',
|
||||
name: req.body.name || '',
|
||||
name_cn: req.body.name_cn || '',
|
||||
email: req.body.email || '',
|
||||
password: req.body.password ? bcrypt.hashSync(req.body.password, 8) : '',
|
||||
mobile_phone: req.body.mobile_phone || '',
|
||||
home_phone: req.body.home_phone || '',
|
||||
phone: req.body.phone || '',
|
||||
language: req.body.language || '',
|
||||
status: 'active',
|
||||
address: req.body.address1 || '',
|
||||
address1: req.body.address2 || '',
|
||||
firstname: req.body.firstname || '',
|
||||
lastname: req.body.lastname || '',
|
||||
birth_date: req.body.birth_date || null,
|
||||
create_by: req.body.create_by || '',
|
||||
create_date: new Date(),
|
||||
edit_by: req.body.edit_by || '',
|
||||
edit_date: new Date(),
|
||||
note: req.body.note || '',
|
||||
care_provider: req.body.care_provider || '',
|
||||
emergency_contact: req.body.emergency_contact || '',
|
||||
medicare_number: req.body.medicare_number || '',
|
||||
medicaid_number: req.body.medicaid_number || '',
|
||||
pharmacy: req.body.pharmacy || '',
|
||||
type: req.body.type || '',
|
||||
pharmacy_id: req.body.pharmacy_id || '',
|
||||
pin: req.body.pin || '',
|
||||
admission_date: req.body.admission_date || null,
|
||||
seating: req.body.seating || '',
|
||||
vehicle_no: req.body.vehicle_no || '',
|
||||
caller: req.body.caller || '',
|
||||
discharge_date: req.body.discharge_date || null,
|
||||
placement: req.body.placement || '',
|
||||
nickname: req.body.nickname || '',
|
||||
groups: req.body.groups || null,
|
||||
tags: req.body.tags || null,
|
||||
roles: req.body.roles || null,
|
||||
private_note: req.body.private_note || '',
|
||||
parent_id: '5eee3552b02fac3d4acfd5ea'
|
||||
});
|
||||
// Save Client in the database
|
||||
client
|
||||
.save(client)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Client."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.getClient = (req, res) => {
|
||||
const id = req.params.id;
|
||||
Client.findById(id)
|
||||
.then(data => {
|
||||
if (!data)
|
||||
res.status(404).send({ message: "Not found client with id " + id });
|
||||
else res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res
|
||||
.status(500)
|
||||
.send({ message: "Error retrieving client with id=" + id });
|
||||
});
|
||||
}
|
||||
|
||||
// Update a Client by the id in the request
|
||||
exports.updateClient = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
if (req.body.password) {
|
||||
req.body.password = bcrypt.hashSync(req.body.password, 8);
|
||||
}
|
||||
Client.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update client with id=${id}. Maybe Client was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Client was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Client with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Get Client with username or email
|
||||
exports.getClientsWithNameOrEmail = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
const nameOrEmail = params?.nameOrEmail;
|
||||
if (nameOrEmail) {
|
||||
condition = { $or: [
|
||||
{ email: nameOrEmail },
|
||||
{ name: nameOrEmail }
|
||||
]};
|
||||
}
|
||||
Client.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving clients."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
184
app/controllers/customer.controller.js
Normal file
@ -0,0 +1,184 @@
|
||||
const db = require("../models");
|
||||
const Customer = db.customer;
|
||||
var bcrypt = require("bcryptjs");
|
||||
const { splitSite } = require("../middlewares");
|
||||
// Create and Save a new Customer
|
||||
exports.createCustomer = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.name) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create a Customer
|
||||
const customer = new Customer({
|
||||
username: req.body.username || req.body.email || '',
|
||||
name: req.body.name || '',
|
||||
name_cn: req.body.name_cn || '',
|
||||
email: req.body.email || '',
|
||||
password: req.body.password ? bcrypt.hashSync(req.body.password, 8) : '',
|
||||
mobile_phone: req.body.mobile_phone || '',
|
||||
home_phone: req.body.home_phone || '',
|
||||
phone: req.body.phone || '',
|
||||
language: req.body.language || '',
|
||||
status: 'active',
|
||||
address1: req.body.address1 || '',
|
||||
address2: req.body.address2 || '',
|
||||
address3: req.body.address3 || '',
|
||||
address4: req.body.address4 || '',
|
||||
address5: req.body.address5 || '',
|
||||
firstname: req.body.firstname || '',
|
||||
lastname: req.body.lastname || '',
|
||||
birth_date: req.body.birth_date || null,
|
||||
create_by: req.body.create_by || '',
|
||||
create_date: new Date(),
|
||||
edit_by: req.body.edit_by || '',
|
||||
edit_date: new Date(),
|
||||
note: req.body.note || '',
|
||||
care_provider: req.body.care_provider || '',
|
||||
emergency_contact: req.body.emergency_contact || '',
|
||||
medicare_number: req.body.medicare_number || '',
|
||||
medicaid_number: req.body.medicaid_number || '',
|
||||
pharmacy: req.body.pharmacy || '',
|
||||
type: req.body.type || '',
|
||||
avatar: req.body.avatar || '',
|
||||
special_needs: req.body.special_needs || '',
|
||||
pickup_status: req.body.pickup_status || '',
|
||||
pharmacy_id: req.body.pharmacy_id || '',
|
||||
pin: req.body.pin || '',
|
||||
admission_date: req.body.admission_date || null,
|
||||
seating: req.body.seating || '',
|
||||
vehicle_no: req.body.vehicle_no || '',
|
||||
caller: req.body.caller || '',
|
||||
discharge_date: req.body.discharge_date || null,
|
||||
placement: req.body.placement || '',
|
||||
nickname: req.body.nickname || '',
|
||||
table_id: req.body.table_id || '',
|
||||
groups: req.body.groups || null,
|
||||
tags: req.body.tags || null,
|
||||
roles: req.body.roles || null,
|
||||
apartment: req.body.apartment || '',
|
||||
private_note: req.body.private_note || '',
|
||||
parent_id: '5eee3552b02fac3d4acfd5ea',
|
||||
site,
|
||||
disability: req.body.disability || false,
|
||||
weight: req.body.weight || '',
|
||||
height: req.body.height || '',
|
||||
gender: req.body.gender || '',
|
||||
text_msg_enabled: req.body.text_msg_enabled || false
|
||||
});
|
||||
// Save Customer in the database
|
||||
customer
|
||||
.save(customer)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Customer."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Customers from the database.
|
||||
exports.getAllCustomers = (req, res) => {
|
||||
var condition = {};
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
Customer.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving customers."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Active Customer from the database.
|
||||
exports.getAllActiveCustomers = (req, res) => {
|
||||
var condition = { status: 'active' };
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
Customer.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Customers."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Get One Customer by Id
|
||||
exports.getCustomer = (req, res) => {
|
||||
const id = req.params.id;
|
||||
Customer.findById(id)
|
||||
.then(data => {
|
||||
if (!data)
|
||||
res.status(404).send({ message: "Not found Customer with id " + id });
|
||||
else res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res
|
||||
.status(500)
|
||||
.send({ message: "Error retrieving Customer with id=" + id });
|
||||
});
|
||||
};
|
||||
// Update a Customer by the id in the request
|
||||
exports.updateCustomer = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
if (req.body.password) {
|
||||
req.body.password = bcrypt.hashSync(req.body.password, 8);
|
||||
}
|
||||
Customer.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update customer with id=${id}. Maybe Customer was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Customer was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Customer with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
// Soft Delete a Customer with the specified id in the request
|
||||
exports.deactivateCustomer = (req, res) => {
|
||||
|
||||
};
|
||||
// Delete a Customer by id
|
||||
exports.deleteCustomer = (req, res) => {
|
||||
|
||||
};
|
||||
// Get Customer with username or email
|
||||
exports.getCustomersWithNameOrEmail = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
const nameOrEmail = params?.nameOrEmail;
|
||||
if (nameOrEmail) {
|
||||
condition = { $or: [
|
||||
{ email: nameOrEmail },
|
||||
{ name: nameOrEmail }
|
||||
]};
|
||||
}
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
Customer.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving customers."
|
||||
});
|
||||
});
|
||||
};
|
||||
470
app/controllers/doctemplate.controller.js
Normal file
@ -0,0 +1,470 @@
|
||||
// const axios = require("axios");
|
||||
// const { splitSite } = require("../middlewares");
|
||||
// const db = require("../models");
|
||||
// const DocTemplate = db.doctemplate
|
||||
// var multer = require('multer');
|
||||
// var PizZip = require('pizzip');
|
||||
// var Docxtemplater = require('docxtemplater');
|
||||
// var fs = require('fs');
|
||||
// const path = require('path');
|
||||
// // const docxConverter = require('docx-pdf');
|
||||
// var libre = require('libreoffice-convert');
|
||||
|
||||
|
||||
// exports.createPDFFromDocTemplateName = (req, res) => {
|
||||
// console.log('what', __dirname.replace('/controllers', ''));
|
||||
// var inputData = req.query.inputData;
|
||||
// var docTemplateName = req.query.docTemplateName;
|
||||
// // var transportationId = req.body.transportationId;d
|
||||
// // var transportationName = req.body.transportationName;
|
||||
// DocTemplate.find({name: docTemplateName}).then((data) => {
|
||||
// try {
|
||||
// if (data && data.length > 0) {
|
||||
// var docTemplate = data[0] || {};
|
||||
// var templateDoc = `${__dirname.replace('/controllers', '')}${docTemplate?.file[0]?.url}`;
|
||||
// var outputFileRandom = Math.ceil(Math.random() * 100000000);
|
||||
// var outputFile = `/tmp/${docTemplate.name}_${outputFileRandom}.docx`;
|
||||
// var content = fs.readFileSync(templateDoc, 'binary');
|
||||
// var zip = new PizZip(content);
|
||||
// var doc = new Docxtemplater(zip, {
|
||||
// paragraphLoop: true,
|
||||
// linebreaks: true,
|
||||
// });
|
||||
|
||||
|
||||
|
||||
// try {
|
||||
// // render the document (replace all occurences of {first_name} by John, {last_name} by Doe, ...)
|
||||
// doc.render(JSON.parse(inputData));
|
||||
// } catch (error) {
|
||||
// // The error thrown here contains additional information when logged with JSON.stringify (it contains a properties object containing all suberrors).
|
||||
// function replaceErrors(key, value) {
|
||||
// if (value instanceof Error) {
|
||||
// return Object.getOwnPropertyNames(value).reduce(function(error, key) {
|
||||
// error[key] = value[key];
|
||||
// return error;
|
||||
// }, {});
|
||||
// }
|
||||
// return value;
|
||||
// }
|
||||
// console.log(JSON.stringify({error: error}, replaceErrors));
|
||||
// if (error.properties && error.properties.errors instanceof Array) {
|
||||
// const errorMessages = error.properties.errors.map(function (error) {
|
||||
// return error.properties.explanation;
|
||||
// }).join("\n");
|
||||
// console.log('errorMessages', errorMessages);
|
||||
// // errorMessages is a humanly readable message looking like this :
|
||||
// // 'The tag beginning with "foobar" is unopened'
|
||||
// }
|
||||
// // callback && callback(error, null, { message:'error in creating doc from template' });
|
||||
// }
|
||||
// // save doc to output file
|
||||
// var buf = doc.getZip().generate({type: 'nodebuffer'});
|
||||
// // buf is a nodejs buffer, you can either write it to a file or do anything else with it.
|
||||
// fs.writeFileSync(outputFile, buf);
|
||||
// var outputFilename = outputFile || {};
|
||||
// var outputPdfPath = outputFilename.substr(0, outputFilename.length - 5) + '.pdf';
|
||||
// console.log('outputPDF:', outputPdfPath);
|
||||
// var extend = 'pdf';
|
||||
// // Read file
|
||||
// // var outputFilename = outputFile || {};
|
||||
// // console.log('filename', `/tmp/${docTemplate.name}_${outputFileRandom}.docx`)
|
||||
// // docxConverter(path.resolve(`/tmp/${docTemplate.name}_${outputFileRandom}.docx`), path.resolve(`/tmp/${docTemplate.name}_${outputFileRandom}.pdf`), (err, result) => {
|
||||
// // if (err) console.log(err);
|
||||
// // else {
|
||||
// // console.log('res', res);
|
||||
// // res.download(result, (error) => {
|
||||
// // console.log('Download PDF error')
|
||||
// // })
|
||||
// // }
|
||||
// // });
|
||||
|
||||
// var infile = fs.readFileSync(outputFile);
|
||||
// // Convert it to pdf format with undefined filter (see Libreoffice doc about filter)
|
||||
// try {
|
||||
// libre.convert(infile, extend, undefined, (err, done) => {
|
||||
// if (err) {
|
||||
// console.log('Error converting file:', err);
|
||||
// }
|
||||
// // Here in done you have pdf file which you can save or transfer in another stream
|
||||
// fs.writeFileSync(outputPdfPath, done);
|
||||
// console.log('Conver docx to pdf, Done.');
|
||||
// res.download(outputPdfPath, function(error) {
|
||||
// if (error) {
|
||||
// console.log('Error in sending download file ${outputPdfPath}');
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// } catch (e) {
|
||||
// console.log(e);
|
||||
// }
|
||||
|
||||
// } else {
|
||||
// res.status(404).send({
|
||||
// success: false,
|
||||
// message: "Docs Template doesn't exist"
|
||||
// })
|
||||
// }
|
||||
// } catch(e) {
|
||||
// console.log(e);
|
||||
// }
|
||||
// }).catch(err => {
|
||||
// res.status(500).send({
|
||||
// success: false,
|
||||
// message: "Error Geting docs"
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
// exports.createDocFromDocTemplateName = (req, res) => {
|
||||
// console.log('what', __dirname.replace('/controllers', ''));
|
||||
// // var inputData = req.query.inputData;
|
||||
// var inputData = req.body.inputData;
|
||||
// var docTemplateName = req.body.docTemplateName;
|
||||
// DocTemplate.find({name: docTemplateName}).then((data) => {
|
||||
// console.log(data);
|
||||
// try {
|
||||
// if (data && data.length > 0) {
|
||||
// var docTemplate = data[0] || {};
|
||||
// var templateDoc = `${__dirname.replace('/controllers', '')}${docTemplate?.file[0]?.url}`;
|
||||
// var outputFileRandom = Math.ceil(Math.random() * 100000000);
|
||||
// var outputFile = `/tmp/${docTemplate.name}_${outputFileRandom}.docx`;
|
||||
// var content = fs.readFileSync(templateDoc, 'binary');
|
||||
// var zip = new PizZip(content);
|
||||
// var doc = new Docxtemplater(zip, {
|
||||
// paragraphLoop: true,
|
||||
// linebreaks: true,
|
||||
// });
|
||||
|
||||
// try {
|
||||
// // render the document (replace all occurences of {first_name} by John, {last_name} by Doe, ...)
|
||||
// doc.render(JSON.parse(inputData));
|
||||
// } catch (error) {
|
||||
// // The error thrown here contains additional information when logged with JSON.stringify (it contains a properties object containing all suberrors).
|
||||
// function replaceErrors(key, value) {
|
||||
// if (value instanceof Error) {
|
||||
// return Object.getOwnPropertyNames(value).reduce(function(error, key) {
|
||||
// error[key] = value[key];
|
||||
// return error;
|
||||
// }, {});
|
||||
// }
|
||||
// return value;
|
||||
// }
|
||||
// console.log(JSON.stringify({error: error}, replaceErrors));
|
||||
// if (error.properties && error.properties.errors instanceof Array) {
|
||||
// const errorMessages = error.properties.errors.map(function (error) {
|
||||
// return error.properties.explanation;
|
||||
// }).join("\n");
|
||||
// console.log('errorMessages', errorMessages);
|
||||
// // errorMessages is a humanly readable message looking like this :
|
||||
// // 'The tag beginning with "foobar" is unopened'
|
||||
// }
|
||||
// // callback && callback(error, null, { message:'error in creating doc from template' });
|
||||
// }
|
||||
// // save doc to output file
|
||||
// var buf = doc.getZip().generate({type: 'nodebuffer'});
|
||||
// // buf is a nodejs buffer, you can either write it to a file or do anything else with it.
|
||||
// fs.writeFileSync(outputFile, buf);
|
||||
// var outputFilename = outputFile || {};
|
||||
|
||||
// res.send(outputFilename, (error) => {
|
||||
// if (error) {
|
||||
// console.log('Error in downloading excel')
|
||||
// }
|
||||
// });
|
||||
|
||||
// console.log('Doc Download Completes')
|
||||
|
||||
// } else {
|
||||
// res.status(404).send({
|
||||
// success: false,
|
||||
// message: "Docs Template doesn't exist"
|
||||
// })
|
||||
// }
|
||||
// } catch(e) {
|
||||
// console.log(e);
|
||||
// }
|
||||
// }).catch(err => {
|
||||
// res.status(500).send({
|
||||
// success: false,
|
||||
// message: "Error Geting docs"
|
||||
// });
|
||||
// });
|
||||
// // ids.forEach(id => {
|
||||
// // CalendarEvent.findByIdAndUpdate(id, {link_event_uuid: transportationId,
|
||||
// // link_event_name: transportationName}, { useFindAndModify: false })
|
||||
// // .then(data => {
|
||||
// // if (!data) {
|
||||
// // res.status(404).send({
|
||||
// // message: `Cannot update Event with id=${id}. Maybe Event was not found!`
|
||||
// // });
|
||||
// // } else res.send({ success: true, message: "Event was updated successfully." });
|
||||
// // })
|
||||
// // .catch(err => {
|
||||
// // res.status(500).send({
|
||||
// // success: false,
|
||||
// // message: "Error updating Event with id=" + id
|
||||
// // });
|
||||
// // });
|
||||
// // })
|
||||
// }
|
||||
|
||||
|
||||
|
||||
const axios = require("axios");
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const DocTemplate = db.doctemplate;
|
||||
const Event = db.calendar_event;
|
||||
var multer = require('multer');
|
||||
var PizZip = require('pizzip');
|
||||
var Docxtemplater = require('docxtemplater');
|
||||
var fs = require('fs');
|
||||
const path = require('path');
|
||||
// const docxConverter = require('docx-pdf');
|
||||
var libre = require('libreoffice-convert');
|
||||
const moment = require("moment-timezone");
|
||||
|
||||
|
||||
exports.createPDFFromDocTemplateName = (req, res) => {
|
||||
console.log('what', __dirname.replace('/controllers', ''));
|
||||
var inputData = JSON.parse(req.query.inputData);
|
||||
var docTemplateName = req.query.docTemplateName;
|
||||
const eventIds =inputData?.eventIds;
|
||||
Event.find({ '_id': { $in: eventIds } }).then((events) => {
|
||||
const docData = {
|
||||
events: []
|
||||
};
|
||||
events.forEach((event) => {
|
||||
docData.events.push({
|
||||
event_time: moment(event.start_time).format('hh:mm A MM/DD/YYYY dddd'),
|
||||
client_name: event.data.client_name || '',
|
||||
client_status: '会员',
|
||||
//client_dob: event.data.client_birth_date || '',
|
||||
//client_pcp: event.data.client_pcp || '',
|
||||
//client_pharmacy: event.data.client_pharmacy || '',
|
||||
client_seating: event.data.client_seating || '',
|
||||
doctor_name: event.data.resource_name || '',
|
||||
//doctor_phone: event.data.resource_phone || '',
|
||||
doctor_contact: event.data.resource_contact || '',
|
||||
doctor_address: event.data.resource_address || '',
|
||||
//title: event.title || '',
|
||||
description: event.description || '',
|
||||
interpreter: event.data.interpreter || '',
|
||||
//fasting: event.data.fasting || '',
|
||||
//confirmed: event.data.confirmed,
|
||||
//new_patient: event.data.new_patient,
|
||||
//doc_order: event.data.doc_order,
|
||||
//need_id: event.data.need_id,
|
||||
//need_med_list: event.data.need_med_list,
|
||||
reason: event.data.reason || '',
|
||||
other: event.data.other || ''
|
||||
});
|
||||
});
|
||||
// var transportationId = req.body.transportationId;d
|
||||
// var transportationName = req.body.transportationName;
|
||||
DocTemplate.find({name: docTemplateName}).then((data) => {
|
||||
try {
|
||||
if (data && data.length > 0) {
|
||||
var docTemplate = data[0] || {};
|
||||
var templateDoc = `${__dirname.replace('/controllers', '')}${docTemplate?.file[0]?.url}`;
|
||||
var outputFileRandom = Math.ceil(Math.random() * 100000000);
|
||||
var outputFile = `/tmp/${docTemplate.name}_${outputFileRandom}.docx`;
|
||||
var content = fs.readFileSync(templateDoc, 'binary');
|
||||
var zip = new PizZip(content);
|
||||
var doc = new Docxtemplater(zip, {
|
||||
paragraphLoop: true,
|
||||
linebreaks: true,
|
||||
});
|
||||
|
||||
try {
|
||||
// render the document (replace all occurences of {first_name} by John, {last_name} by Doe, ...)
|
||||
doc.render(docData);
|
||||
} catch (error) {
|
||||
// The error thrown here contains additional information when logged with JSON.stringify (it contains a properties object containing all suberrors).
|
||||
function replaceErrors(key, value) {
|
||||
if (value instanceof Error) {
|
||||
return Object.getOwnPropertyNames(value).reduce(function(error, key) {
|
||||
error[key] = value[key];
|
||||
return error;
|
||||
}, {});
|
||||
}
|
||||
return value;
|
||||
}
|
||||
console.log(JSON.stringify({error: error}, replaceErrors));
|
||||
if (error.properties && error.properties.errors instanceof Array) {
|
||||
const errorMessages = error.properties.errors.map(function (error) {
|
||||
return error.properties.explanation;
|
||||
}).join("\n");
|
||||
console.log('errorMessages', errorMessages);
|
||||
// errorMessages is a humanly readable message looking like this :
|
||||
// 'The tag beginning with "foobar" is unopened'
|
||||
}
|
||||
// callback && callback(error, null, { message:'error in creating doc from template' });
|
||||
}
|
||||
// save doc to output file
|
||||
var buf = doc.getZip().generate({type: 'nodebuffer'});
|
||||
// buf is a nodejs buffer, you can either write it to a file or do anything else with it.
|
||||
fs.writeFileSync(outputFile, buf);
|
||||
var outputFilename = outputFile || {};
|
||||
var outputPdfPath = outputFilename.substr(0, outputFilename.length - 5) + '.pdf';
|
||||
console.log('outputPDF:', outputPdfPath);
|
||||
var extend = 'pdf';
|
||||
// Read file
|
||||
// var outputFilename = outputFile || {};
|
||||
// console.log('filename', `/tmp/${docTemplate.name}_${outputFileRandom}.docx`)
|
||||
// docxConverter(path.resolve(`/tmp/${docTemplate.name}_${outputFileRandom}.docx`), path.resolve(`/tmp/${docTemplate.name}_${outputFileRandom}.pdf`), (err, result) => {
|
||||
// if (err) console.log(err);
|
||||
// else {
|
||||
// console.log('res', res);
|
||||
// res.download(result, (error) => {
|
||||
// console.log('Download PDF error')
|
||||
// })
|
||||
// }
|
||||
// });
|
||||
|
||||
var infile = fs.readFileSync(outputFile);
|
||||
// Convert it to pdf format with undefined filter (see Libreoffice doc about filter)
|
||||
try {
|
||||
libre.convert(infile, extend, undefined, (err, done) => {
|
||||
if (err) {
|
||||
console.log('Error converting file:', err);
|
||||
}
|
||||
// Here in done you have pdf file which you can save or transfer in another stream
|
||||
fs.writeFileSync(outputPdfPath, done);
|
||||
console.log('Conver docx to pdf, Done.');
|
||||
res.download(outputPdfPath, function(error) {
|
||||
if (error) {
|
||||
console.log('Error in sending download file ${outputPdfPath}');
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
} else {
|
||||
res.status(404).send({
|
||||
success: false,
|
||||
message: "Docs Template doesn't exist"
|
||||
})
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
}).catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error Geting docs"
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
exports.createDocFromDocTemplateName = (req, res) => {
|
||||
console.log('what', __dirname.replace('/controllers', ''));
|
||||
var inputData = JSON.parse(req.query.inputData);
|
||||
const eventIds = inputData?.eventIds;
|
||||
var docTemplateName = req.query.docTemplateName;
|
||||
Event.find({ '_id': { $in: eventIds } }).then((events) => {
|
||||
const docData = {
|
||||
events: []
|
||||
};
|
||||
events.forEach((event) => {
|
||||
docData.events.push({
|
||||
event_time: moment(event.start_time).format('hh:mm A MM/DD/YYYY dddd'),
|
||||
client_name: event.data.client_name || '',
|
||||
client_status: '会员',
|
||||
//client_dob: event.data.client_birth_date || '',
|
||||
//client_pcp: event.data.client_pcp || '',
|
||||
//client_pharmacy: event.data.client_pharmacy || '',
|
||||
client_seating: event.data.client_seating || '',
|
||||
doctor_name: event.data.resource_name || '',
|
||||
//doctor_phone: event.data.resource_phone || '',
|
||||
doctor_contact: event.data.resource_contact || '',
|
||||
doctor_address: event.data.resource_address || '',
|
||||
//title: event.title || '',
|
||||
description: event.description || '',
|
||||
interpreter: event.data.interpreter || '',
|
||||
//fasting: event.data.fasting || '',
|
||||
//confirmed: event.data.confirmed,
|
||||
//new_patient: event.data.new_patient,
|
||||
//doc_order: event.data.doc_order,
|
||||
//need_id: event.data.need_id,
|
||||
//need_med_list: event.data.need_med_list,
|
||||
reason: event.data.reason || '',
|
||||
other: event.data.other || ''
|
||||
});
|
||||
});
|
||||
|
||||
DocTemplate.find({name: docTemplateName}).then((data) => {
|
||||
try {
|
||||
if (data && data.length > 0) {
|
||||
var docTemplate = data[0] || {};
|
||||
var templateDoc = `${__dirname.replace('/controllers', '')}${docTemplate?.file[0]?.url}`;
|
||||
var outputFileRandom = Math.ceil(Math.random() * 100000000);
|
||||
var outputFile = `/tmp/${docTemplate.name}_${outputFileRandom}.docx`;
|
||||
var content = fs.readFileSync(templateDoc, 'binary');
|
||||
var zip = new PizZip(content);
|
||||
var doc = new Docxtemplater(zip, {
|
||||
paragraphLoop: true,
|
||||
linebreaks: true,
|
||||
});
|
||||
|
||||
try {
|
||||
// render the document (replace all occurences of {first_name} by John, {last_name} by Doe, ...)
|
||||
doc.render(docData);
|
||||
} catch (error) {
|
||||
// The error thrown here contains additional information when logged with JSON.stringify (it contains a properties object containing all suberrors).
|
||||
function replaceErrors(key, value) {
|
||||
if (value instanceof Error) {
|
||||
return Object.getOwnPropertyNames(value).reduce(function(error, key) {
|
||||
error[key] = value[key];
|
||||
return error;
|
||||
}, {});
|
||||
}
|
||||
return value;
|
||||
}
|
||||
console.log(JSON.stringify({error: error}, replaceErrors));
|
||||
if (error.properties && error.properties.errors instanceof Array) {
|
||||
const errorMessages = error.properties.errors.map(function (error) {
|
||||
return error.properties.explanation;
|
||||
}).join("\n");
|
||||
console.log('errorMessages', errorMessages);
|
||||
// errorMessages is a humanly readable message looking like this :
|
||||
// 'The tag beginning with "foobar" is unopened'
|
||||
}
|
||||
// callback && callback(error, null, { message:'error in creating doc from template' });
|
||||
}
|
||||
// save doc to output file
|
||||
var buf = doc.getZip().generate({type: 'nodebuffer'});
|
||||
// buf is a nodejs buffer, you can either write it to a file or do anything else with it.
|
||||
fs.writeFileSync(outputFile, buf);
|
||||
var outputFilename = outputFile || {};
|
||||
|
||||
res.download(outputFilename, (error) => {
|
||||
if (error) {
|
||||
console.log('Error in downloading excel')
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Doc Download Completes')
|
||||
|
||||
} else {
|
||||
res.status(404).send({
|
||||
success: false,
|
||||
message: "Docs Template doesn't exist"
|
||||
})
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
}).catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error Geting docs"
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
152
app/controllers/employee.controller.js
Normal file
@ -0,0 +1,152 @@
|
||||
const db = require("../models");
|
||||
const Employee = db.employee;
|
||||
|
||||
var bcrypt = require("bcryptjs");
|
||||
const { splitSite } = require("../middlewares");
|
||||
// Create and Save a new Employee (driver, distributor, admin)
|
||||
exports.createEmployee = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.username) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create a Employee
|
||||
const employee = new Employee({
|
||||
username: req.body.username || req.body.email || '',
|
||||
name: req.body.name || '',
|
||||
name_cn: req.body.name_cn || '',
|
||||
email: req.body.email || '',
|
||||
password: req.body.password ? bcrypt.hashSync(req.body.password, 8) : '',
|
||||
roles: req.body.roles || [],
|
||||
mobile_phone: req.body.mobile_phone || '',
|
||||
phone: req.body.phone || '',
|
||||
home_phone: req.body.home_phone || '',
|
||||
language: req.body.language || '',
|
||||
employment_status: req.body.employment_status || '',
|
||||
status: req.body.status || 'active',
|
||||
address: req.body.address || '',
|
||||
title: req.body.title || '',
|
||||
title_cn: req.body.title_cn || '',
|
||||
firstname: req.body.firstname || '',
|
||||
lastname: req.body.lastname || '',
|
||||
department: req.body.department || '',
|
||||
birth_date: req.body.birth_date || null,
|
||||
driver_capacity: req.body.driver_capacity || null,
|
||||
date_hired: req.body.date_hired || null,
|
||||
create_by: req.body.create_by || '',
|
||||
create_date: new Date(),
|
||||
edit_by: req.body.edit_by || '',
|
||||
edit_date: new Date(),
|
||||
note: req.body.note || '',
|
||||
tags: req.body.tags || [],
|
||||
fetch_route_time: req.body.fetch_route_time || null,
|
||||
site
|
||||
});
|
||||
// Save Employee in the database
|
||||
employee
|
||||
.save(employee)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Employee."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Employee from the database.
|
||||
exports.getAllEmployees = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
if (params.status) {
|
||||
condition.status = params.status;
|
||||
}
|
||||
if (params.role) {
|
||||
condition.roles = params.role;
|
||||
}
|
||||
Employee.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving employees."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Active Employee from the database.
|
||||
exports.getAllActiveEmployees = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = { status: 'active' };
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
if (params.roles) {
|
||||
condition.roles = params.roles;
|
||||
}
|
||||
Employee.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving employees."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Get One Employee by Id
|
||||
exports.getEmployee = (req, res) => {
|
||||
const id = req.params.id;
|
||||
Employee.findById(id)
|
||||
.then(data => {
|
||||
if (!data)
|
||||
res.status(404).send({ message: "Not found Employee with id " + id });
|
||||
else res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res
|
||||
.status(500)
|
||||
.send({ message: "Error retrieving Employee with id=" + id });
|
||||
});
|
||||
};
|
||||
// Update a Employee by the id in the request
|
||||
exports.updateEmployee = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
if (req.body.password) {
|
||||
req.body.password = bcrypt.hashSync(req.body.password, 8);
|
||||
}
|
||||
Employee.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update employee with id=${id}. Maybe Employee was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Employee was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Employee with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
// Soft Delete a Employee with the specified id in the request
|
||||
exports.deactivateEmployee = (req, res) => {
|
||||
|
||||
};
|
||||
// Delete a Employee by id
|
||||
exports.deleteEmployee = (req, res) => {
|
||||
|
||||
};
|
||||
// Get Employees with username or email
|
||||
exports.getEmployeesWithUsernameOrEmail = (req, res) => {
|
||||
|
||||
};
|
||||
109
app/controllers/event-request.controller.js
Normal file
@ -0,0 +1,109 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const EventRequest = db.event_request;
|
||||
|
||||
// Create a new Event Request Item
|
||||
exports.createEventRequest = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.customer_id) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create an eventRequest Item
|
||||
const eventRequest = new EventRequest({
|
||||
customer_id: req.body.customer_id,
|
||||
customer_display: req.body.customer_display,
|
||||
upload: req.body.upload,
|
||||
resource: req.body.resource,
|
||||
resource_display: req.body.resource_display,
|
||||
source: req.body.source,
|
||||
type: req.body.type,
|
||||
status: req.body.status || 'active',
|
||||
symptom: req.body.symptom,
|
||||
transportation: req.body.transportation,
|
||||
np: req.body.np,
|
||||
notes: req.body.notes || [],
|
||||
create_by: req.body.create_by,
|
||||
create_date: req.body.create_date,
|
||||
edit_history: req.body.edit_history,
|
||||
site
|
||||
});
|
||||
// Save eventRequest Item in the database
|
||||
eventRequest
|
||||
.save(eventRequest)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the event request Record."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Retrive all eventRequest Records from database.
|
||||
exports.getAllEventRequests = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
EventRequest.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Event Requests."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// Update an Event Request Item by the id in the request
|
||||
exports.updateRequestItem = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
EventRequest.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Event Request with id=${id}. Maybe Event Request was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Event Request was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Event Request with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Delete an Event Request by id
|
||||
exports.deleteEventRequest = (req, res) => {
|
||||
const id = req.params.id;
|
||||
EventRequest.findByIdAndRemove(id)
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot delete Event Request with id=${id}. Maybe Event Request was not found!`
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
message: "Event Request was deleted successfully!"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message: "Could not delete Event Request with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
119
app/controllers/lunch.controller.js
Normal file
@ -0,0 +1,119 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const Lunch = db.lunch;
|
||||
|
||||
// Create a new Lunch Item
|
||||
exports.createNewLunch = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.customer_id) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create an Lunch Item
|
||||
const lunch = new Lunch({
|
||||
customer_id: req.body.customer_id,
|
||||
customer_name: req.body.customer_name,
|
||||
has_lunch: req.body.has_lunch,
|
||||
create_by: req.body.create_by,
|
||||
create_date: req.body.create_date,
|
||||
edit_history: req.body.edit_history,
|
||||
date: req.body.date,
|
||||
site
|
||||
});
|
||||
// Save lunch Item in the database
|
||||
lunch
|
||||
.save(lunch)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Lunch Record."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Retrive all Lunch Records from database.
|
||||
exports.getAllLunches = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
if (params.date) {
|
||||
condition.date = params.date;
|
||||
}
|
||||
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
Lunch.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Lunches."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Get One Event by Id
|
||||
// exports.getEvent = (req, res) => {
|
||||
// const id = req.params.id;
|
||||
// CalendarEvent.findById(id)
|
||||
// .then(data => {
|
||||
// if (!data)
|
||||
// res.status(404).send({ message: "Not found Event with id " + id });
|
||||
// else res.send(data);
|
||||
// })
|
||||
// .catch(err => {
|
||||
// res
|
||||
// .status(500)
|
||||
// .send({ message: "Error retrieving Event with id=" + id });
|
||||
// });
|
||||
// };
|
||||
|
||||
// Update a Lunch by the id in the request
|
||||
exports.updateLunch = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
Lunch.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Lunch with id=${id}. Maybe Lunch was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Lunch was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Lunch with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Delete a Lunch by id
|
||||
exports.deleteLunch= (req, res) => {
|
||||
const id = req.params.id;
|
||||
Lunch.findByIdAndRemove(id)
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot delete Lunch with id=${id}. Maybe Lunch was not found!`
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
message: "Lunch was deleted successfully!"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message: "Could not delete Lunch with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
63
app/controllers/message-token.controller.js
Normal file
@ -0,0 +1,63 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const MessageToken = db.message_token;
|
||||
exports.createMessageToken = (req, res) => {
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create a MessageToken
|
||||
const messageToken = new MessageToken({
|
||||
message_token: req.body.message_token || '',
|
||||
site
|
||||
});
|
||||
|
||||
// Save MessageToken in the database
|
||||
messageToken
|
||||
.save(messageToken)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Message Token."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all MessageTokens from the database.
|
||||
exports.getAllMessageTokens = (req, res) => {
|
||||
var condition = {};
|
||||
MessageToken.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving messageTokens."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Update a MessageTOken by the id in the request
|
||||
exports.updateMessageToken = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
MessageToken.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update MessageToken with id=${id}. Maybe MessageToken was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "MessageToken was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating MessageToken with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
191
app/controllers/message.controller.js
Normal file
@ -0,0 +1,191 @@
|
||||
const axios = require("axios");
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const Message = db.message;
|
||||
const MessageToken = db.message_token;
|
||||
const SentMessage = db.sent_message;
|
||||
|
||||
exports.createMessage = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.message_group) {
|
||||
res.status(400).send({ message: "Message Group can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create a Message
|
||||
const message = new Message({
|
||||
message_group: req.body.message_group || 0,
|
||||
message_name: req.body.message_name || '',
|
||||
message_title: req.body.message_title || '',
|
||||
message_body: req.body.message_body || '',
|
||||
language: req.body.language || '',
|
||||
site
|
||||
});
|
||||
|
||||
// Save Message in the database
|
||||
message
|
||||
.save(message)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Message."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Messages from the database.
|
||||
exports.getAllMessages = (req, res) => {
|
||||
var condition = {};
|
||||
Message.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving messages."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Retrieve messages By group and language
|
||||
exports.getMessagesByGroupAndLanguage= (req, res) => {
|
||||
const params = req.query;
|
||||
const message_group = params?.message_group;
|
||||
const language = params?.language;
|
||||
var condition = { message_group, language };
|
||||
Message.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Messages with Date and Type."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Get One Message by Id
|
||||
exports.getMessage = (req, res) => {
|
||||
const id = req.params.id;
|
||||
Message.findById(id)
|
||||
.then(data => {
|
||||
if (!data)
|
||||
res.status(404).send({ message: "Not found Message with id " + id });
|
||||
else res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res
|
||||
.status(500)
|
||||
.send({ message: "Error retrieving Message with id=" + id });
|
||||
});
|
||||
};
|
||||
// Update a Message by the id in the request
|
||||
exports.updateMessage = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
Message.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Message with id=${id}. Maybe Message was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Message was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Message with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// exports.sendMessage = async (req, res) => {
|
||||
// console.log(req.body);
|
||||
// if (!req.body) {
|
||||
// return res.status(400).send({
|
||||
// message: "Data to update can not be empty!"
|
||||
// });
|
||||
// }
|
||||
// const authToken = await MessageToken.find({});
|
||||
// if (authToken && authToken.length > 0) {
|
||||
// const token = authToken[0]?.message_token;
|
||||
// console.log('token', token);
|
||||
// await axios.post('https://api-app2.simpletexting.com/v2/api/messages', req.body, {
|
||||
// headers: {
|
||||
// "Authorization": `Bearer ${token}`,
|
||||
// "Content-Type": "application/json",
|
||||
// },
|
||||
// }).then(() => {
|
||||
// res.send({success: true, message: "Message Sent Correctly"})
|
||||
// }).catch(err => console.log(err));
|
||||
// }
|
||||
// }
|
||||
|
||||
// Retrieve all Sent Messages from the database.
|
||||
exports.getAllSentMessages = (req, res) => {
|
||||
var condition = {};
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
SentMessage.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving sent messages."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.sendMessage = async (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const messages = req.body.messages;
|
||||
|
||||
for(const message of messages) {
|
||||
try {
|
||||
await axios.post('https://rest.textmagic.com/api/v2/messages', {
|
||||
text: message?.text,
|
||||
phones: message?.contactPhone
|
||||
}, {
|
||||
headers: {
|
||||
"X-TM-Username": "oauthyhma",
|
||||
"X-TM-Key": "Rin866o0cMMAJXkCiIyYd2pw9HSeGo"
|
||||
}
|
||||
})
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
const sentMessage = new SentMessage({
|
||||
from_type: 'center',
|
||||
from: message.from || 'center',
|
||||
to_type: 'client',
|
||||
to: message.contactPhone || '',
|
||||
department: message.department || '',
|
||||
content: message.text || '',
|
||||
status: 'active',
|
||||
create_by: 'admin',
|
||||
create_date: new Date(),
|
||||
site
|
||||
});
|
||||
await sentMessage.save(sentMessage);
|
||||
await sleep(200);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
}
|
||||
res.send({success: true, message: "Message Sent Correctly"});
|
||||
}
|
||||
|
||||
118
app/controllers/report.controller.js
Normal file
@ -0,0 +1,118 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const Report = db.report;
|
||||
exports.createReport = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.data) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create a Report
|
||||
const report = new Report({
|
||||
date: req.body.date || '',
|
||||
type: req.body.type || '',
|
||||
route_id: req.body.route_id || '',
|
||||
driver_name: req.body.driver_name || '',
|
||||
route_name: req.body.route_name || '',
|
||||
data: req.body.data || [],
|
||||
head: req.body.head || [],
|
||||
chinese_head: req.body.chinese_head || [],
|
||||
checklist_result: req.body.checklist_result || [],
|
||||
vehicle_number: req.body.vehicle_number || null,
|
||||
site
|
||||
});
|
||||
|
||||
// Save Report in the database
|
||||
report
|
||||
.save(report)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Report."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Reports from the database.
|
||||
exports.getAllReports = (req, res) => {
|
||||
var condition = {};
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
Report.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving reports."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Active Reports By Date and Type (Admin Reports).
|
||||
exports.getReportsByDateAndType = (req, res) => {
|
||||
const params = req.query;
|
||||
const date = params?.date;
|
||||
const type = params?.type;
|
||||
var condition = { date, type };
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
Report.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Reports with Date and Type."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve reports By RouteId and Type (Senior Route report)
|
||||
exports.getReportsByRouteIdAndType = (req, res) => {
|
||||
const params = req.query;
|
||||
const route_id = params?.route_id;
|
||||
const type = params?.type;
|
||||
var condition = { route_id, type };
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
Report.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Reports with Date and Type."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Get One Report by Id
|
||||
exports.getReport = (req, res) => {
|
||||
|
||||
};
|
||||
// Update a Report by the id in the request
|
||||
exports.updateReport = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
Report.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Report with id=${id}. Maybe Report was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Report was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Report with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
152
app/controllers/resource.controller.js
Normal file
@ -0,0 +1,152 @@
|
||||
const db = require("../models");
|
||||
const Resource = db.resource;
|
||||
const { splitSite } = require("../middlewares");
|
||||
// Create and Save a new Resource
|
||||
exports.createResource = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.name) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
const resource = new Resource({
|
||||
name: req.body.name,
|
||||
name_original: req.body.name_original,
|
||||
name_branch: req.body.name_branch,
|
||||
specialty: req.body.specialty,
|
||||
type: req.body.type, // value may be ['doctor', 'pharmacy' or 'other']
|
||||
color: req.body.color,
|
||||
address: req.body.address,
|
||||
city: req.body.city,
|
||||
state: req.body.state,
|
||||
zipcode: req.body.zipcode,
|
||||
phone: req.body.phone,
|
||||
status: req.body.status || 'active', // value might be ['active', 'inactive']
|
||||
create_by: req.body.create_by,
|
||||
create_date: req.body.create_date || new Date(),
|
||||
parent_id: req.body.parent_id,
|
||||
ext_id: req.body.ext_id,
|
||||
category: req.body.category,
|
||||
description: req.body.description,
|
||||
contact: req.body.contact,
|
||||
fax: req.body.fax,
|
||||
note: req.body.note,
|
||||
data: req.body.data,
|
||||
edit_by: req.body.edit_by,
|
||||
edit_date: req.body.edit_date || new Date(),
|
||||
images: req.body.images,
|
||||
edit_history: req.body.edit_history,
|
||||
site
|
||||
});
|
||||
// Save Resource in the database
|
||||
resource
|
||||
.save(resource)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Resource"
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Resources from the database.
|
||||
exports.getAllResources = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
if (params) {
|
||||
if (params.type) {
|
||||
condition.type = params.type;
|
||||
}
|
||||
}
|
||||
Resource.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving resources."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Get One Resource by Id
|
||||
exports.getResource = (req, res) => {
|
||||
const id = req.params.id;
|
||||
Resource.findById(id)
|
||||
.then(data => {
|
||||
if (!data)
|
||||
res.status(404).send({ message: "Not found Resource with id " + id });
|
||||
else res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res
|
||||
.status(500)
|
||||
.send({ message: "Error retrieving Resource with id=" + id });
|
||||
});
|
||||
};
|
||||
|
||||
// Update a Resource by the id in the request
|
||||
exports.updateResource = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
Resource.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Resource with id=${id}. Maybe Resource was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Resource was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Resource with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
// Disable an Resource by the id in the request
|
||||
exports.disableResource = (req, res) => {
|
||||
const id = req.params.id;
|
||||
Resource.findByIdAndUpdate(id, { ...req.body, status: 'inactive'}, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Resource with id=${id}. Maybe Resource was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Resource was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Resource with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Delete a Resource by id
|
||||
exports.deleteResource= (req, res) => {
|
||||
const id = req.params.id;
|
||||
Resource.findByIdAndRemove(id)
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot delete Resource with id=${id}. Maybe Resource was not found!`
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
message: "Resource was deleted successfully!"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message: "Could not delete Resource with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
99
app/controllers/route-path-template.controller.js
Normal file
@ -0,0 +1,99 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const RoutePathTemplate = db.route_path_template;
|
||||
exports.createRoutePathTemplate = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.name) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create a Route Template
|
||||
const routePathTemplate = new RoutePathTemplate({
|
||||
name: req.body.name,
|
||||
vehicle: req.body.vehicle,
|
||||
driver: req.body.driver,
|
||||
type: req.body.type,
|
||||
route_customer_list: req.body.route_customer_list || [],
|
||||
status: req.body.status || 'active',
|
||||
site
|
||||
});
|
||||
// Save Route Template in the database
|
||||
routePathTemplate
|
||||
.save(routePathTemplate)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Route Template."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Routes Templates from the database.
|
||||
exports.getAllRoutesTemplates = (req, res) => {
|
||||
var condition = {};
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
RoutePathTemplate.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Routes."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Get One Route Template by Id
|
||||
exports.getRouteTemplate = (req, res) => {
|
||||
|
||||
};
|
||||
|
||||
// Update a Route Template by the id in the request
|
||||
exports.updateRouteTemplate = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
RoutePathTemplate.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Route Template with id=${id}. Maybe Route Template was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Route Template was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Route Template with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Delete a Route Template by id
|
||||
exports.deleteRouteTemplate= (req, res) => {
|
||||
const id = req.params.id;
|
||||
RoutePathTemplate.findByIdAndRemove(id)
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot delete Route Template with id=${id}. Maybe Route Template was not found!`
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
message: "Route Template was deleted successfully!"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message: "Could not delete Route Template with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
249
app/controllers/route-path.controller.js
Normal file
@ -0,0 +1,249 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const RoutePath = db.route_path;
|
||||
const CenterPhone = db.center_phone;
|
||||
const Employee = db.employee;
|
||||
exports.createRoutePath = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.name) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create a Route
|
||||
const routePath = new RoutePath({
|
||||
name: req.body.name,
|
||||
schedule_date: req.body.schedule_date,
|
||||
vehicle: req.body.vehicle,
|
||||
status: req.body.status,
|
||||
driver: req.body.driver,
|
||||
type: req.body.type,
|
||||
start_mileage: req.body.start_mileage,
|
||||
end_mileage: req.body.end_mileage,
|
||||
start_time: req.body.start_time || null,
|
||||
end_time: req.body.end_time || null,
|
||||
estimated_start_time: req.body.estimated_start_time || null,
|
||||
route_customer_list: req.body.route_customer_list || [],
|
||||
checklist_result: req.body.checklist_result || [],
|
||||
site
|
||||
});
|
||||
// Save Route in the database
|
||||
routePath
|
||||
.save(routePath)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Route."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Routes from the database.
|
||||
exports.getAllRoutes = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
if (params) {
|
||||
if (params.scheduleDate) {
|
||||
condition.schedule_date = params.scheduleDate;
|
||||
}
|
||||
if (params.driverId) {
|
||||
condition.driver = params.driverId;
|
||||
}
|
||||
}
|
||||
condition.status = { "$ne": 'disabled' };
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
RoutePath.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Routes."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Retrieve all Routes with phones from the database.
|
||||
exports.getAllRoutesWithPhones = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
var condition2 = {};
|
||||
if (params) {
|
||||
if (params.scheduleDate) {
|
||||
condition.schedule_date = params.scheduleDate;
|
||||
}
|
||||
if (params.driverId) {
|
||||
condition.driver = params.driverId;
|
||||
}
|
||||
if (params.activated) {
|
||||
condition2.activated = params.activated
|
||||
}
|
||||
}
|
||||
condition.status = { "$ne": 'disabled' };
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
condition2 = splitSite.splitSiteGet(req, condition2);
|
||||
Promise.all(
|
||||
[RoutePath.find(condition), CenterPhone.find(condition2)]
|
||||
).then(([transRoutes, phones]) => res.send({
|
||||
transRoutes: transRoutes,
|
||||
centerPhones: phones
|
||||
})).catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Routes or phones."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Get One Route by Id
|
||||
exports.getRoute = (req, res) => {
|
||||
const id = req.params.id;
|
||||
RoutePath.findById(id)
|
||||
.then(data => {
|
||||
if (!data)
|
||||
res.status(404).send({ message: "Not found Route with id " + id });
|
||||
else {
|
||||
// console.log('where is driver', data?.driver);
|
||||
// Employee.findByIdAndUpdate(driver, {fetch_route_time: new Date()}).then((rst) => {
|
||||
// console.log('updated result',rst);
|
||||
// }).catch((err) => {
|
||||
// console.log(`employee ${driver} update failure`)
|
||||
// })
|
||||
res.send(data);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res
|
||||
.status(500)
|
||||
.send({ message: "Error retrieving Route with id=" + id });
|
||||
});
|
||||
};
|
||||
|
||||
// Update a Route by the id in the request
|
||||
exports.updateRoute = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
RoutePath.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Route with id=${id}. Maybe Route was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Route was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Route with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// update route from mobile without deleting customers
|
||||
exports.updateRouteInProgress = (req, res) => {
|
||||
if (!req.body) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const routeBody = req.body;
|
||||
RoutePath.findById(routeBody.id)
|
||||
.then(data => {
|
||||
if (!data)
|
||||
res.status(404).send({ message: "Not found Route with id " + id });
|
||||
else {
|
||||
const currentRoute = data;
|
||||
const currentCustomerList = currentRoute.route_customer_list;
|
||||
const customerListSent = routeBody.route_customer_list;
|
||||
const finalCustomerList = [...customerListSent];
|
||||
for (const cust of currentCustomerList) {
|
||||
if (!customerListSent.find((c) => c.id === cust.id )) {
|
||||
finalCustomerList.push(cust);
|
||||
}
|
||||
}
|
||||
const finalBody = Object.assign({}, routeBody, {route_customer_list: finalCustomerList})
|
||||
RoutePath.findByIdAndUpdate(currentRoute.id, finalBody, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
// console.log('success', data.id);
|
||||
// const driver = currentRoute?.driver;
|
||||
// if (driver) {
|
||||
// Employee.findById(driver).then((data) => {
|
||||
// const employeeObj = data;
|
||||
// // console.log('driverOjb', employeeObj)
|
||||
// if (employeeObj) {
|
||||
// const update_route_history = employeeObj?.update_route_history;
|
||||
// const newHistoryItem = {
|
||||
// route_id: currentRoute?.id,
|
||||
// route_name: currentRoute?.name,
|
||||
// route_schedule_date: currentRoute?.schedule_date,
|
||||
// route_update_time: new Date()
|
||||
// };
|
||||
// let result = [];
|
||||
// if (update_route_history?.length >= 20) {
|
||||
// for (let i=1; i < update_route_history.length; i++) {
|
||||
// result.push(update_route_history[i]);
|
||||
// }
|
||||
// result.push(newHistoryItem);
|
||||
// } else {
|
||||
// update_route_history.push(newHistoryItem);
|
||||
// result = update_route_history;
|
||||
// }
|
||||
// // console.log('final', result);
|
||||
// Employee.findByIdAndUpdate(driver, Object.assign({}, employeeObj, {update_route_history: result})).then((rst) => {
|
||||
// console.log('updated result',rst);
|
||||
// }).catch((err) => {
|
||||
// console.log(`employee ${driver} update failure`)
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Route with id=${id}. Maybe Route was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Route was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Route with id=" + id
|
||||
});
|
||||
});
|
||||
|
||||
// res.send({ success: true, message: "Route was found successfully." });
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res
|
||||
.status(500)
|
||||
.send({ message: "Error retrieving Route with id=" + id });
|
||||
});
|
||||
}
|
||||
|
||||
// Delete a Route by id
|
||||
exports.deleteRoute= (req, res) => {
|
||||
const id = req.params.id;
|
||||
RoutePath.findByIdAndRemove(id)
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot delete Route with id=${id}. Maybe Route was not found!`
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
message: "Route was deleted successfully!"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message: "Could not delete Route with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
126
app/controllers/signature-request.controller.js
Normal file
@ -0,0 +1,126 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const SignatureRequest = db.signature_request;
|
||||
|
||||
// Create a new Signature Request
|
||||
exports.createNewSignatureRequest = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.route_id) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create an Signature Request
|
||||
const signatureRequest = new SignatureRequest({
|
||||
driver_id: req.body.driver_id,
|
||||
driver_name: req.body.driver_name,
|
||||
route_id: req.body.route_id,
|
||||
route_date: req.body.route_date,
|
||||
route_name: req.body.route_name,
|
||||
status: req.body.status || 'active',
|
||||
create_by: req.body.create_by,
|
||||
create_date: req.body.create_date,
|
||||
site
|
||||
});
|
||||
// Save Signature Request in the database
|
||||
signatureRequest
|
||||
.save(signatureRequest)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Signature Request Record."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Retrive all SignatureRequest from database.
|
||||
exports.getAllSignatureRequests = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
if (params.route_date) {
|
||||
condition.route_date = params.route_date;
|
||||
}
|
||||
if (params.route_id) {
|
||||
condition.route_id = params.route_id;
|
||||
}
|
||||
if (params.driver_id) {
|
||||
condition.driver_id = params.driver_id;
|
||||
}
|
||||
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
SignatureRequest.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Signature Requests."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Get One Signature Request by Id
|
||||
exports.getSignatureRequest = (req, res) => {
|
||||
const id = req.params.id;
|
||||
SignatureRequest.findById(id)
|
||||
.then(data => {
|
||||
if (!data)
|
||||
res.status(404).send({ message: "Not found Signature Request with id " + id });
|
||||
else res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res
|
||||
.status(500)
|
||||
.send({ message: "Error retrieving Signature Request with id=" + id });
|
||||
});
|
||||
};
|
||||
|
||||
// Update a Signature Request by the id in the request
|
||||
exports.updateSignatureRequest = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
SignatureRequest.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Signature Request with id=${id}. Maybe Signature Request was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Signature Request was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Signature Request with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Delete a Signature Request by id
|
||||
exports.deleteSignatureRequest= (req, res) => {
|
||||
const id = req.params.id;
|
||||
SignatureRequest.findByIdAndRemove(id)
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot delete Signature Request with id=${id}. Maybe Signature Request was not found!`
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
message: "Signature Request was deleted successfully!"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message: "Could not delete Signature Request with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
119
app/controllers/snack.controller.js
Normal file
@ -0,0 +1,119 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const Snack = db.snack;
|
||||
|
||||
// Create a new Snack Item
|
||||
exports.createNewSnack = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.customer_id) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create an Snack Item
|
||||
const snack = new Snack({
|
||||
customer_id: req.body.customer_id,
|
||||
customer_name: req.body.customer_name,
|
||||
has_snack: req.body.has_snack,
|
||||
create_by: req.body.create_by,
|
||||
create_date: req.body.create_date,
|
||||
edit_history: req.body.edit_history,
|
||||
date: req.body.date,
|
||||
site
|
||||
});
|
||||
// Save snack Item in the database
|
||||
snack
|
||||
.save(snack)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Snack Record."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Retrive all Snack Records from database.
|
||||
exports.getAllSnacks = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
if (params.date) {
|
||||
condition.date = params.date;
|
||||
}
|
||||
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
Snack.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Snacks."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Get One Event by Id
|
||||
// exports.getEvent = (req, res) => {
|
||||
// const id = req.params.id;
|
||||
// CalendarEvent.findById(id)
|
||||
// .then(data => {
|
||||
// if (!data)
|
||||
// res.status(404).send({ message: "Not found Event with id " + id });
|
||||
// else res.send(data);
|
||||
// })
|
||||
// .catch(err => {
|
||||
// res
|
||||
// .status(500)
|
||||
// .send({ message: "Error retrieving Event with id=" + id });
|
||||
// });
|
||||
// };
|
||||
|
||||
// Update a Snack by the id in the request
|
||||
exports.updateSnack = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
Snack.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Snack with id=${id}. Maybe Snack was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Snack was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Snack with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Delete a Snack by id
|
||||
exports.deleteSnack= (req, res) => {
|
||||
const id = req.params.id;
|
||||
Snack.findByIdAndRemove(id)
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot delete Snack with id=${id}. Maybe Snack was not found!`
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
message: "Snack was deleted successfully!"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message: "Could not delete Snack with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
114
app/controllers/staff.controller.js
Normal file
@ -0,0 +1,114 @@
|
||||
const db = require("../models");
|
||||
const Staff = db.staff;
|
||||
|
||||
var bcrypt = require("bcryptjs");
|
||||
const { splitSite } = require("../middlewares");
|
||||
// Create and Save a new Staff (driver, distributor, admin)
|
||||
exports.createStaff = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.username) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create a Staff
|
||||
const staff = new Staff({
|
||||
username: req.body.username || req.body.email || '',
|
||||
name: req.body.name || '',
|
||||
name_cn: req.body.name_cn || '',
|
||||
email: req.body.email || '',
|
||||
password: req.body.password ? bcrypt.hashSync(req.body.password, 8) : '',
|
||||
roles: req.body.roles || [],
|
||||
mobile_phone: req.body.mobile_phone || '',
|
||||
phone: req.body.phone || '',
|
||||
home_phone: req.body.home_phone || '',
|
||||
language: req.body.language || '',
|
||||
employment_status: req.body.employment_status || '',
|
||||
status: req.body.status || 'active',
|
||||
title: req.body.title || '',
|
||||
title_cn: req.body.title_cn || '',
|
||||
firstname: req.body.firstname || '',
|
||||
lastname: req.body.lastname || '',
|
||||
department: req.body.department || '',
|
||||
birth_date: req.body.birth_date || null,
|
||||
driver_capacity: req.body.driver_capacity || null,
|
||||
date_hired: req.body.date_hired || null,
|
||||
create_by: req.body.create_by || '',
|
||||
create_date: new Date(),
|
||||
edit_by: req.body.edit_by || '',
|
||||
edit_date: new Date(),
|
||||
salt: req.body.salt || '264897',
|
||||
city: req.body.city || '',
|
||||
state: req.body.state || '',
|
||||
zipcode: req.body.zipcode || '',
|
||||
group: req.body.group || [],
|
||||
tags: req.body.tags || [],
|
||||
parent_id: req.body.parent_id || '5eee3552b02fac3d4acfd5ea',
|
||||
site
|
||||
});
|
||||
// Save Staff in the database
|
||||
staff
|
||||
.save(staff)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Staff."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Update a Staff by the id in the request
|
||||
exports.updateStaff = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
if (req.body.password) {
|
||||
req.body.password = bcrypt.hashSync(req.body.password, 8);
|
||||
}
|
||||
Staff.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update staff with id=${id}. Maybe staff was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Staff was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error updating Staff with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
// Get Staff with username or email
|
||||
exports.getStaffsWithNameOrEmail = (req, res) => {
|
||||
var params = req.query;
|
||||
var condition = {};
|
||||
const nameOrEmail = params?.nameOrEmail;
|
||||
if (nameOrEmail) {
|
||||
condition = { $or: [
|
||||
{ email: nameOrEmail },
|
||||
{ name: nameOrEmail }
|
||||
]};
|
||||
}
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
Staff.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving staffs."
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
25
app/controllers/timedata.controller.js
Normal file
@ -0,0 +1,25 @@
|
||||
const axios = require("axios");
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const Timedata = db.timedata;
|
||||
var moment = require('moment-timezone');
|
||||
|
||||
exports.getDocsByCondition1 = (req, res) => {
|
||||
const params = req.query;
|
||||
const date = params.date;
|
||||
const condition = {};
|
||||
condition['time'] = {
|
||||
//$gte: moment(parameter.date + 'T00:00:00.00').toDate()
|
||||
$gte: moment.tz(date + 'T00:00:00.00', "America/New_York").toDate()
|
||||
};
|
||||
Timedata.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving time data."
|
||||
});
|
||||
});
|
||||
}
|
||||
70
app/controllers/upload.controller.js
Normal file
@ -0,0 +1,70 @@
|
||||
const upload = require("../middlewares/upload");
|
||||
const dbConfig = require("../config/db.config");
|
||||
const MongoClient = require("mongodb").MongoClient;
|
||||
const GridFSBucket = require("mongodb").GridFSBucket;
|
||||
const url = dbConfig.url;
|
||||
const baseUrl = dbConfig.fileUrl;
|
||||
const mongoClient = new MongoClient(url);
|
||||
const uploadFiles = async (req, res) => {
|
||||
try {
|
||||
await upload(req, res);
|
||||
if (req.file == undefined) {
|
||||
return res.send({
|
||||
message: "You must select a file.",
|
||||
});
|
||||
}
|
||||
return res.send({
|
||||
message: "File has been uploaded.",
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return res.send({
|
||||
message: "Error when trying upload image: ${error}",
|
||||
});
|
||||
}
|
||||
};
|
||||
const getFile = async (req, res) => {
|
||||
try {
|
||||
await mongoClient.connect();
|
||||
const database = mongoClient.db(dbConfig.database);
|
||||
const images = database.collection(dbConfig.imgBucket + ".files");
|
||||
const chunks = database.collection(dbConfig.imgBucket + ".chunks");
|
||||
const cursor = await (images.find({filename: req.params.name}).toArray());
|
||||
if (cursor.length === 0) {
|
||||
return res.status(500).send({
|
||||
message: "No files found!",
|
||||
});
|
||||
}
|
||||
const chunkCursor = await(chunks.find({files_id: cursor[cursor.length-1]._id}).toArray());
|
||||
return res.status(200).send(chunkCursor[0].data);
|
||||
} catch (error) {
|
||||
return res.status(500).send({
|
||||
message: error.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const deleteFile = async (req, res) => {
|
||||
try {
|
||||
await mongoClient.connect();
|
||||
const database = mongoClient.db(dbConfig.database);
|
||||
const images = database.collection(dbConfig.imgBucket + ".files");
|
||||
const chunks = database.collection(dbConfig.imgBucket + ".chunks");
|
||||
const cursor = await (images.find({filename: req.body.name}).toArray());
|
||||
if (cursor.length > 0) {
|
||||
await chunks.deleteMany({files_id: cursor[cursor.length-1]._id});
|
||||
await images.deleteMany({filename: req.body.name});
|
||||
}
|
||||
return res.status(200).send({ message: 'Delete Image Succeed'});
|
||||
} catch (error) {
|
||||
return res.status(500).send({
|
||||
message: error.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
uploadFiles,
|
||||
getFile,
|
||||
deleteFile
|
||||
};
|
||||
30
app/controllers/user.controller.js
Normal file
@ -0,0 +1,30 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const User = db.user;
|
||||
// Create and Save a new User
|
||||
exports.createUser = (req, res) => {
|
||||
|
||||
};
|
||||
// Retrieve all Users from the database.
|
||||
exports.getAllUsers = (req, res) => {
|
||||
var condition = {};
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
User.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving users."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Update a User by the id in the request
|
||||
exports.updateUser = (req, res) => {
|
||||
|
||||
};
|
||||
// Delete a User with the specified id in the request
|
||||
exports.delete = (req, res) => {
|
||||
|
||||
};
|
||||
133
app/controllers/vehicle.controller.js
Normal file
@ -0,0 +1,133 @@
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const Vehicle = db.vehicle;
|
||||
exports.createVehicle = (req, res) => {
|
||||
// Validate request
|
||||
if (!req.body.tag) {
|
||||
res.status(400).send({ message: "Content can not be empty!" });
|
||||
return;
|
||||
}
|
||||
const site = splitSite.findSiteNumber(req);
|
||||
// Create a Vehicle
|
||||
const vehicle = new Vehicle({
|
||||
vehicle_number: req.body.vehicle_number,
|
||||
tag: req.body.tag || '',
|
||||
ezpass: req.body.ezpass || '',
|
||||
gps_tag: req.body.gps_tag || '',
|
||||
mileage: req.body.mileage || 0,
|
||||
capacity: req.body.capacity || 0,
|
||||
make: req.body.make || '',
|
||||
vehicle_model: req.body.vehicle_model || '',
|
||||
year: req.body.year || '',
|
||||
checklist: req.body.checklist || '',
|
||||
status: 'active',
|
||||
site
|
||||
});
|
||||
|
||||
// Save Vehicle in the database
|
||||
vehicle
|
||||
.save(vehicle)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while creating the Vehicle."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Vehicles from the database.
|
||||
exports.getAllVehicles = (req, res) => {
|
||||
var condition = {};
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
Vehicle.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Vehicles."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Retrieve all Active Vehicles from the database.
|
||||
exports.getAllActiveVehicles = (req, res) => {
|
||||
var condition = { status: 'active' };
|
||||
condition = splitSite.splitSiteGet(req, condition);
|
||||
Vehicle.find(condition)
|
||||
.then(data => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message:
|
||||
err.message || "Some error occurred while retrieving Vehicles."
|
||||
});
|
||||
});
|
||||
};
|
||||
// Get One Vehicle by Id
|
||||
exports.getVehicle = (req, res) => {
|
||||
const id = req.params.id;
|
||||
Vehicle.findById(id)
|
||||
.then(data => {
|
||||
if (!data)
|
||||
res.status(404).send({ message: "Not found Vehicle with id " + id });
|
||||
else res.send(data);
|
||||
})
|
||||
.catch(err => {
|
||||
res
|
||||
.status(500)
|
||||
.send({ message: "Error retrieving Vehicle with id=" + id });
|
||||
});
|
||||
};
|
||||
// Update a Vehicle by the id in the request
|
||||
exports.updateVehicle = (req, res) => {
|
||||
if (!req.body) {
|
||||
return res.status(400).send({
|
||||
message: "Data to update can not be empty!"
|
||||
});
|
||||
}
|
||||
const id = req.params.id;
|
||||
Vehicle.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot update Vehicle with id=${id}. Maybe Vehicle was not found!`
|
||||
});
|
||||
} else res.send({ success: true, message: "Vehicle was updated successfully." });
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error" + (err.message || "") + "updating Vehicle with id=" + id
|
||||
});
|
||||
});
|
||||
};
|
||||
// Soft Delete a Vehicle
|
||||
exports.deactivateVehicle = (req, res) => {
|
||||
|
||||
};
|
||||
|
||||
// Delete a Vehicle by id
|
||||
exports.deleteVehicle= (req, res) => {
|
||||
const id = req.params.id;
|
||||
Vehicle.findByIdAndRemove(id)
|
||||
.then(data => {
|
||||
if (!data) {
|
||||
res.status(404).send({
|
||||
message: `Cannot delete Vehicle with id=${id}. Maybe Vehicle was not found!`
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
message: "Vehicle was deleted successfully!"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(500).send({
|
||||
message: "Could not delete Vehicle with id=" + id + ": " + err.message || ""
|
||||
});
|
||||
});
|
||||
};
|
||||
413
app/controllers/xlsxtemplate.controller.js
Normal file
@ -0,0 +1,413 @@
|
||||
// const axios = require("axios");
|
||||
// const { splitSite } = require("../middlewares");
|
||||
// const db = require("../models");
|
||||
// const ExcelTemplate = db.exceltemplate;
|
||||
// var XlsxTemplate = require('xlsx-template');
|
||||
// var fs = require('fs');
|
||||
// var multer = require('multer');
|
||||
// const path = require('path');
|
||||
// var libre = require('libreoffice-convert');
|
||||
|
||||
// exports.createPDFFromSheetTemplateName = (req, res) => {
|
||||
// console.log('what', __dirname.replace('/controllers', ''));
|
||||
// var inputData = req.query.inputData;
|
||||
// var excelTemplateName = req.query.excelTemplateName;
|
||||
// // var transportationId = req.body.transportationId;d
|
||||
// // var transportationName = req.body.transportationName;
|
||||
// ExcelTemplate.find({name: excelTemplateName}).then((data) => {
|
||||
// try {
|
||||
// if (data && data.length > 0) {
|
||||
// var excelTemplate = data[0] || {};
|
||||
// var templateExcel = `${__dirname.replace('/controllers', '')}${excelTemplate?.file[0]?.url}`;
|
||||
// var outputFileRandom = Math.ceil(Math.random() * 100000000);
|
||||
// var outputFile = `/tmp/${excelTemplate.name}_${outputFileRandom}.xlsx`;
|
||||
// var data = fs.readFileSync(templateExcel, 'binary');
|
||||
// var template = new XlsxTemplate(data);
|
||||
// var events = JSON.parse(inputData)?.events;
|
||||
// for (var i = 0; i < events.length; i++) {
|
||||
// var pageNumber = i + 2;
|
||||
// var event = events[i];
|
||||
// // template.copySheet(1, pageNumber);
|
||||
// template.copySheet(1, event.client_name);
|
||||
// // console.log('>>> template substitute:', pageNumber, event);
|
||||
// template.substitute(pageNumber, event);
|
||||
// }
|
||||
// template.deleteSheet(1);
|
||||
// var newData = template.generate();
|
||||
// fs.writeFileSync(outputFile, newData, 'binary');
|
||||
// var outputFilename = outputFile || {};
|
||||
// var outputPdfPath = outputFilename.substr(0, outputFilename.length - 5) + '.pdf';
|
||||
// console.log('outputPDF:', outputPdfPath);
|
||||
// var extend = 'pdf';
|
||||
|
||||
// var infile = fs.readFileSync(outputFile);
|
||||
// // Convert it to pdf format with undefined filter (see Libreoffice doc about filter)
|
||||
// try {
|
||||
// libre.convert(infile, extend, undefined, (err, done) => {
|
||||
// if (err) {
|
||||
// console.log('Error converting file:', err);
|
||||
// }
|
||||
// // Here in done you have pdf file which you can save or transfer in another stream
|
||||
// fs.writeFileSync(outputPdfPath, done);
|
||||
// console.log('Conver xlsx to pdf, Done.');
|
||||
// res.download(outputPdfPath, function(error) {
|
||||
// if (error) {
|
||||
// console.log('Error in sending download file ${outputPdfPath}');
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// } catch (e) {
|
||||
// console.log(e);
|
||||
// }
|
||||
|
||||
// } else {
|
||||
// res.status(404).send({
|
||||
// success: false,
|
||||
// message: "Sheet Template doesn't exist"
|
||||
// })
|
||||
// }
|
||||
// } catch(e) {
|
||||
// console.log(e);
|
||||
// }
|
||||
// }).catch(err => {
|
||||
// res.status(500).send({
|
||||
// success: false,
|
||||
// message: "Error Geting docs"
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
// exports.createSheetFromTemplateName = (req, res) => {
|
||||
// console.log('what', __dirname.replace('/controllers', ''));
|
||||
// var inputData = req.query.inputData;
|
||||
// console.log('inputData', inputData);
|
||||
// var excelTemplateName = req.query.excelTemplateName;
|
||||
// // var transportationId = req.body.transportationId;
|
||||
// // var transportationName = req.body.transportationName;
|
||||
// ExcelTemplate.find({name: excelTemplateName}).then((data) => {
|
||||
// try {
|
||||
// if (data && data.length > 0) {
|
||||
// var excelTemplate = data[0] || {};
|
||||
// console.log('template', excelTemplate);
|
||||
// var templateExcel = `${__dirname.replace('/controllers', '')}${excelTemplate?.file[0]?.url}`;
|
||||
// var outputFileRandom = Math.ceil(Math.random() * 100000000);
|
||||
// var outputFile = `/tmp/${excelTemplate.name}_${outputFileRandom}.xlsx`;
|
||||
// var data = fs.readFileSync(templateExcel, 'binary');
|
||||
// var template = new XlsxTemplate(data);
|
||||
// var events = JSON.parse(inputData)?.events;
|
||||
// console.log('events',events)
|
||||
// for (var i = 0; i < events.length; i++) {
|
||||
// var pageNumber = i + 2;
|
||||
// var event = events[i];
|
||||
// // template.copySheet(1, pageNumber);
|
||||
// template.copySheet(1, event.client_name);
|
||||
// // console.log('>>> template substitute:', pageNumber, event);
|
||||
// template.substitute(pageNumber, event);
|
||||
// }
|
||||
// template.deleteSheet(1);
|
||||
// var newData = template.generate();
|
||||
// fs.writeFileSync(outputFile, newData, 'binary');
|
||||
// console.log('test');
|
||||
// res.download(outputFile, (error) => {
|
||||
// if (error) {
|
||||
// console.log('Error in downloading excel')
|
||||
// }
|
||||
// })
|
||||
// console.log('Download finish');
|
||||
// } else {
|
||||
// res.status(404).send({
|
||||
// success: false,
|
||||
// message: "excel Template doesn't exist"
|
||||
// })
|
||||
// }
|
||||
// } catch(e) {
|
||||
// console.log(e);
|
||||
// }
|
||||
// }).catch(err => {
|
||||
// res.status(500).send({
|
||||
// success: false,
|
||||
// message: "Error Geting excels"
|
||||
// });
|
||||
// });
|
||||
// // ids.forEach(id => {
|
||||
// // CalendarEvent.findByIdAndUpdate(id, {link_event_uuid: transportationId,
|
||||
// // link_event_name: transportationName}, { useFindAndModify: false })
|
||||
// // .then(data => {
|
||||
// // if (!data) {
|
||||
// // res.status(404).send({
|
||||
// // message: `Cannot update Event with id=${id}. Maybe Event was not found!`
|
||||
// // });
|
||||
// // } else res.send({ success: true, message: "Event was updated successfully." });
|
||||
// // })
|
||||
// // .catch(err => {
|
||||
// // res.status(500).send({
|
||||
// // success: false,
|
||||
// // message: "Error updating Event with id=" + id
|
||||
// // });
|
||||
// // });
|
||||
// // })
|
||||
// }
|
||||
|
||||
|
||||
|
||||
const axios = require("axios");
|
||||
const { splitSite } = require("../middlewares");
|
||||
const db = require("../models");
|
||||
const ExcelTemplate = db.exceltemplate;
|
||||
const Event = db.calendar_event;
|
||||
const Customer = db.customer;
|
||||
const Client = db.client;
|
||||
const Resource = db.resource;
|
||||
var XlsxTemplate = require('xlsx-template');
|
||||
var fs = require('fs');
|
||||
var multer = require('multer');
|
||||
const path = require('path');
|
||||
var libre = require('libreoffice-convert');
|
||||
const moment = require('moment-timezone');
|
||||
|
||||
exports.createPDFFromSheetTemplateName = (req, res) => {
|
||||
console.log('what', __dirname.replace('/controllers', ''));
|
||||
var inputData = JSON.parse(req.query.inputData);
|
||||
const eventIds = inputData?.eventIds;
|
||||
console.log('eventIds',eventIds);
|
||||
var excelTemplateName = req.query.excelTemplateName;
|
||||
console.log('template', excelTemplateName);
|
||||
|
||||
Event.find({ '_id': { $in: eventIds } }).then((events) => {
|
||||
|
||||
Resource.find({}).then((resources) => {
|
||||
Customer.find({}).then((customers) => {
|
||||
Client.find({}).then((clients) => {
|
||||
const docData = {events: []};
|
||||
for (const event of events) {
|
||||
const customerModels = event?.data?.customer ? customers: clients;
|
||||
const customerId = event?.data?.customer ? event?.data?.customer : event?.target_uuid;
|
||||
const customer = customerModels.find((customerModel) => customerModel?.id === customerId || customerModel?._id === customerId || customerModel?.name === event?.data?.client_name );
|
||||
let pharmacyInfo = 'This patient has no contracted pharmacy.\n' + 'Please give the prescription directly to the patient';
|
||||
const pharmacy = resources.find(r => (r.id === customer?.pharmacy_id)) || resources.find(r => (r.name?.toLowerCase() === event?.data?.client_pharmacy?.toLowerCase()));
|
||||
|
||||
if (pharmacy) {
|
||||
pharmacyInfo = `${pharmacy?.name} @ ${pharmacy?.address} \n` +
|
||||
`phone:${pharmacy?.phone} fax:${pharmacy?.fax}`;
|
||||
} else {
|
||||
if (event?.data?.client_pharmacy) {
|
||||
pharmacyInfo = 'Pharmacy: ' + event?.data?.client_pharmacy;
|
||||
}
|
||||
}
|
||||
|
||||
const nameShow = event?.data?.customer ? `${event?.data?.client_name} ${customer?.name_cn}` : `${customer?.name_cn}`
|
||||
|
||||
const clientName = (!!customer?.name_cn && !!event?.data?.client_name && nameShow) || customer?.name_cn || (customer?.lastname && customer?.firstname && `${customer?.lastname}, ${customer?.firstname}`) || event?.data?.client_name;
|
||||
|
||||
docData.events.push({
|
||||
event_time: moment(event?.start_time).format('MM/DD/YYYY hh:mm A'),
|
||||
client_name: event?.data?.client_name, // event.data.client_name,
|
||||
client_status: '会员',
|
||||
client_dob: event.data.client_birth_date,
|
||||
// client_pcp: event.data.client_pcp,
|
||||
// client_pharmacy: event.data.client_pharmacy,
|
||||
client_seating: event.data.client_seating,
|
||||
doctor_name: event.data.resource_name,
|
||||
doctor_phone: event.data.resource_phone,
|
||||
//doctor_contact: event.data.resource_contact,
|
||||
doctor_address: event.data.resource_address?.replaceAll('\n', ' '),
|
||||
//title: event.title,
|
||||
// description: event.description,
|
||||
interpreter: event.data.interpreter,
|
||||
fasting: event.data.fasting,
|
||||
confirmed: event.data.confirmed,
|
||||
new_patient: event.data.new_patient,
|
||||
doc_order: event.data.doc_order,
|
||||
need_id: event.data.need_id,
|
||||
need_med_list: event.data.need_med_list,
|
||||
reason: event.data.reason,
|
||||
// notes: event.data.notes,
|
||||
other: event.data.other,
|
||||
pharmacy_info: pharmacyInfo,
|
||||
client_preferred_name: customer?.name_cn,
|
||||
member_type: customer?.type,
|
||||
disability: (customer?.disability === true) ? 'Yes' : (event?.data?.disability || 'No')
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// var transportationId = req.body.transportationId;d
|
||||
// var transportationName = req.body.transportationName;
|
||||
ExcelTemplate.find({name: excelTemplateName}).then((data) => {
|
||||
try {
|
||||
if (data && data.length > 0) {
|
||||
var excelTemplate = data[0] || {};
|
||||
var templateExcel = `${__dirname.replace('/controllers', '')}${excelTemplate?.file[0]?.url}`;
|
||||
var outputFileRandom = Math.ceil(Math.random() * 100000000);
|
||||
var outputFile = `/tmp/${excelTemplate.name}_${outputFileRandom}.xlsx`;
|
||||
var data = fs.readFileSync(templateExcel, 'binary');
|
||||
var template = new XlsxTemplate(data);
|
||||
var eventDatas = docData.events;
|
||||
for (var i = 0; i < eventDatas.length; i++) {
|
||||
var pageNumber = i + 2;
|
||||
var eventData = eventDatas[i];
|
||||
// template.copySheet(1, pageNumber);
|
||||
template.copySheet(1, eventData.client_name);
|
||||
// console.log('>>> template substitute:', pageNumber, event);
|
||||
template.substitute(pageNumber, eventData);
|
||||
}
|
||||
template.deleteSheet(1);
|
||||
var newData = template.generate();
|
||||
fs.writeFileSync(outputFile, newData, 'binary');
|
||||
var outputFilename = outputFile || {};
|
||||
var outputPdfPath = outputFilename.substr(0, outputFilename.length - 5) + '.pdf';
|
||||
console.log('outputPDF:', outputPdfPath);
|
||||
var extend = 'pdf';
|
||||
|
||||
var infile = fs.readFileSync(outputFile);
|
||||
// Convert it to pdf format with undefined filter (see Libreoffice doc about filter)
|
||||
try {
|
||||
libre.convert(infile, extend, undefined, (err, done) => {
|
||||
if (err) {
|
||||
console.log('Error converting file:', err);
|
||||
}
|
||||
// Here in done you have pdf file which you can save or transfer in another stream
|
||||
fs.writeFileSync(outputPdfPath, done);
|
||||
console.log('Conver xlsx to pdf, Done.');
|
||||
res.download(outputPdfPath, function(error) {
|
||||
if (error) {
|
||||
console.log('Error in sending download file ${outputPdfPath}');
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
} else {
|
||||
res.status(404).send({
|
||||
success: false,
|
||||
message: "Sheet Template doesn't exist"
|
||||
})
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
}).catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error Geting docs"
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
})
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
exports.createSheetFromTemplateName = (req, res) => {
|
||||
console.log('what', __dirname.replace('/controllers', ''));
|
||||
var inputData = JSON.parse(req.query.inputData);
|
||||
const eventIds = inputData?.eventIds;
|
||||
var excelTemplateName = req.query.excelTemplateName;
|
||||
|
||||
Event.find({ '_id': { $in: eventIds } }).then((events) => {
|
||||
Resource.find({}).then((resources) => {
|
||||
Customer.find({}).then((customers) => {
|
||||
Client.find({}).then((clients) => {
|
||||
const docData = {events: []};
|
||||
for (const event of events) {
|
||||
const customerModels = event?.data?.customer ? customers: clients;
|
||||
const customerId = event?.data?.customer ? event?.data?.customer : event?.target_uuid;
|
||||
const customer = customerModels.find((customerModel) => customerModel?.id === customerId || customerModel?._id === customerId || customerModel?.name === event?.data?.client_name );
|
||||
let pharmacyInfo = 'This patient has no contracted pharmacy.\n' + 'Please give the prescription directly to the patient';
|
||||
const pharmacy = resources.find(r => (r.id === customer?.pharmacy_id)) || resources.find(r => (r.name?.toLowerCase() === event?.data?.client_pharmacy?.toLowerCase()));
|
||||
|
||||
if (pharmacy) {
|
||||
pharmacyInfo = `${pharmacy?.name} @ ${pharmacy?.address} \n` +
|
||||
`phone:${pharmacy?.phone} fax:${pharmacy?.fax}`;
|
||||
} else {
|
||||
if (event?.data?.client_pharmacy) {
|
||||
pharmacyInfo = 'Pharmacy: ' + event?.data?.client_pharmacy;
|
||||
}
|
||||
}
|
||||
|
||||
const clientName = (customer?.name_cn && event?.data?.client_name && `${event?.data?.client_name} ${customer?.name_cn}`) || customer?.name_cn || (customer?.lastname && customer?.firstname && `${customer?.lastname}, ${customer?.firstname}`) || event?.data?.client_name;
|
||||
|
||||
docData.events.push({
|
||||
event_time: moment(event?.start_time).format('MM/DD/YYYY hh:mm A'),
|
||||
client_name: event?.data?.client_name, // event.data.client_name,
|
||||
client_status: '会员',
|
||||
client_dob: event.data.client_birth_date,
|
||||
// client_pcp: event.data.client_pcp,
|
||||
// client_pharmacy: event.data.client_pharmacy,
|
||||
client_seating: event.data.client_seating,
|
||||
doctor_name: event.data.resource_name,
|
||||
doctor_phone: event.data.resource_phone,
|
||||
//doctor_contact: event.data.resource_contact,
|
||||
doctor_address: event.data.resource_address?.replaceAll('\n', ' '),
|
||||
//title: event.title,
|
||||
// description: event.description,
|
||||
interpreter: event.data.interpreter,
|
||||
fasting: event.data.fasting,
|
||||
confirmed: event.data.confirmed,
|
||||
new_patient: event.data.new_patient,
|
||||
doc_order: event.data.doc_order,
|
||||
need_id: event.data.need_id,
|
||||
need_med_list: event.data.need_med_list,
|
||||
reason: event.data.reason,
|
||||
// notes: event.data.notes,
|
||||
other: event.data.other,
|
||||
pharmacy_info: pharmacyInfo,
|
||||
client_preferred_name: customer?.name_cn,
|
||||
member_type: customer?.type,
|
||||
disability: (customer?.disability === true) ? 'Yes' : (event?.data?.disability || 'No')
|
||||
});
|
||||
}
|
||||
// var transportationId = req.body.transportationId;d
|
||||
// var transportationName = req.body.transportationName;
|
||||
ExcelTemplate.find({name: excelTemplateName}).then((data) => {
|
||||
try {
|
||||
if (data && data.length > 0) {
|
||||
var excelTemplate = data[0] || {};
|
||||
var templateExcel = `${__dirname.replace('/controllers', '')}${excelTemplate?.file[0]?.url}`;
|
||||
var outputFileRandom = Math.ceil(Math.random() * 100000000);
|
||||
var outputFile = `/tmp/${excelTemplate.name}_${outputFileRandom}.xlsx`;
|
||||
var data = fs.readFileSync(templateExcel, 'binary');
|
||||
var template = new XlsxTemplate(data);
|
||||
var eventDatas = docData.events;
|
||||
for (var i = 0; i < eventDatas.length; i++) {
|
||||
var pageNumber = i + 2;
|
||||
var eventData = eventDatas[i];
|
||||
// template.copySheet(1, pageNumber);
|
||||
template.copySheet(1, eventData.client_name);
|
||||
// console.log('>>> template substitute:', pageNumber, event);
|
||||
template.substitute(pageNumber, eventData);
|
||||
}
|
||||
template.deleteSheet(1);
|
||||
var newData = template.generate();
|
||||
fs.writeFileSync(outputFile, newData, 'binary');
|
||||
console.log('test');
|
||||
res.download(outputFile, (error) => {
|
||||
if (error) {
|
||||
console.log('Error in downloading excel')
|
||||
}
|
||||
})
|
||||
console.log('Download finish');
|
||||
} else {
|
||||
res.status(404).send({
|
||||
success: false,
|
||||
message: "Sheet Template doesn't exist"
|
||||
})
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
}).catch(err => {
|
||||
res.status(500).send({
|
||||
success: false,
|
||||
message: "Error Geting docs"
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
})
|
||||
});
|
||||
})
|
||||
}
|
||||
BIN
app/middlewares/.DS_Store
vendored
Normal file
23
app/middlewares/authJwt.js
Normal file
@ -0,0 +1,23 @@
|
||||
const jwt = require("jsonwebtoken");
|
||||
const config = require("../config/auth.config.js");
|
||||
const db = require("../models");
|
||||
const User = db.user;
|
||||
const Role = db.role;
|
||||
verifyToken = (req, res, next) => {
|
||||
let token = req.headers["x-access-token"];
|
||||
if (!token) {
|
||||
return res.status(403).send({ message: "No token provided!" });
|
||||
}
|
||||
jwt.verify(token, config.secret, (err, decoded) => {
|
||||
if (err) {
|
||||
return res.status(401).send({ message: "Unauthorized!" });
|
||||
}
|
||||
req.userId = decoded.id;
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
||||
const authJwt = {
|
||||
verifyToken
|
||||
};
|
||||
module.exports = authJwt;
|
||||
6
app/middlewares/index.js
Normal file
@ -0,0 +1,6 @@
|
||||
const authJwt = require("./authJwt");
|
||||
const splitSite = require("./splitSite");
|
||||
module.exports = {
|
||||
authJwt,
|
||||
splitSite
|
||||
};
|
||||
45
app/middlewares/splitSite.js
Normal file
@ -0,0 +1,45 @@
|
||||
const siteMap = {
|
||||
'ws1': 1,
|
||||
'worldshine1': 1,
|
||||
'ws2': 2,
|
||||
'worldshine2': 2,
|
||||
'ws3': 3,
|
||||
'worldshine3': 3,
|
||||
'worldshine4': 4,
|
||||
'ws4': 4,
|
||||
'worldshine.mayo.llc': 1
|
||||
};
|
||||
|
||||
const findSiteNumber = (req) => {
|
||||
const hostname = req.hostname;
|
||||
let site = 1;
|
||||
for (const key of Object.keys(siteMap)) {
|
||||
if (hostname.includes(key)) {
|
||||
site = siteMap[key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return site;
|
||||
}
|
||||
|
||||
const splitSiteGet = (req, queryParams) => {
|
||||
const site = findSiteNumber(req);
|
||||
const newQueryParams = { ...queryParams, site: site };
|
||||
console.log('query', newQueryParams);
|
||||
return newQueryParams;
|
||||
}
|
||||
|
||||
const splitSitePost = (req, postBody) => {
|
||||
const site = findSiteNumber(req);
|
||||
const newPostBody = { ...postBody, site: site };
|
||||
console.log('post', newPostBody);
|
||||
return newPostBody;
|
||||
}
|
||||
|
||||
const splitSite = {
|
||||
findSiteNumber,
|
||||
splitSiteGet,
|
||||
splitSitePost
|
||||
}
|
||||
|
||||
module.exports = splitSite;
|
||||
22
app/middlewares/upload.js
Normal file
@ -0,0 +1,22 @@
|
||||
const util = require("util");
|
||||
const multer = require("multer");
|
||||
const { GridFsStorage } = require("multer-gridfs-storage");
|
||||
const dbConfig = require("../config/db.config");
|
||||
var storage = new GridFsStorage({
|
||||
url: dbConfig.url,
|
||||
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||
file: (req, file) => {
|
||||
const match = ["image/png", "image/jpeg", "image/jpg"];
|
||||
if (match.indexOf(file.mimetype) === -1) {
|
||||
const filename = req.params.filename;
|
||||
return filename;
|
||||
}
|
||||
return {
|
||||
bucketName: dbConfig.imgBucket,
|
||||
filename: req.params.filename
|
||||
};
|
||||
}
|
||||
});
|
||||
var uploadFiles = multer({ storage: storage }).single("file");
|
||||
var uploadFilesMiddleware = util.promisify(uploadFiles);
|
||||
module.exports = uploadFilesMiddleware;
|
||||
29
app/models/breakfast.model.js
Normal file
@ -0,0 +1,29 @@
|
||||
module.exports = mongoose => {
|
||||
var editHistorySchema = mongoose.Schema({
|
||||
employee: String,
|
||||
date: Date
|
||||
});
|
||||
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
customer_id: String,
|
||||
customer_name: String,
|
||||
date: String,
|
||||
has_breakfast: Boolean,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
edit_history: [{
|
||||
type: editHistorySchema
|
||||
}],
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'breakfast', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const Breakfast = mongoose.model("breakfast", schema);
|
||||
return Breakfast;
|
||||
};
|
||||
91
app/models/calendar-event.model.js
Normal file
@ -0,0 +1,91 @@
|
||||
module.exports = mongoose => {
|
||||
var editHistorySchema = mongoose.Schema({
|
||||
employee: String,
|
||||
date: Date
|
||||
});
|
||||
var eventDataSchema = mongoose.Schema({
|
||||
customer: {type: mongoose.Schema.Types.ObjectId, ref: 'Customer'},
|
||||
resource: {type: mongoose.Schema.Types.ObjectId, ref: 'Resource'},
|
||||
// These fields are legacy fields, we will keep it but won't use it again
|
||||
client_name: String,
|
||||
client_pharmacy: String,
|
||||
client_pcp: String,
|
||||
client_birth_date: String,
|
||||
client_seating: String,
|
||||
resource_type: String,
|
||||
resource_name: String,
|
||||
resource_phone: String,
|
||||
resource_contact: String,
|
||||
resource_address: String,
|
||||
resource_city: String,
|
||||
resource_state: String,
|
||||
// legacy fields end
|
||||
// We still wanna keep the legacy fields below
|
||||
new_patient: String,
|
||||
confirmed: String,
|
||||
fasting: String,
|
||||
interpreter: String,
|
||||
doc_order: String,
|
||||
need_id: String,
|
||||
need_med_list: String,
|
||||
notes: String,
|
||||
reason: String,
|
||||
other: String,
|
||||
disability: String,
|
||||
disability_support: String,
|
||||
video_type: String,
|
||||
video_id: String,
|
||||
presenter: String,
|
||||
trans_method: String,
|
||||
});
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
title: String,
|
||||
type: String,
|
||||
// value could be ['shopping', 'banking', 'singing', 'dancing', 'medical', 'haircut', 'meal', 'transportation', 'others']
|
||||
descrption: String,
|
||||
department: String,
|
||||
notes: String,
|
||||
start_time: Date,
|
||||
stop_time: Date,
|
||||
color: String,
|
||||
source_type: String,
|
||||
source_uuid: String,
|
||||
source_name: String,
|
||||
target_type: String,
|
||||
target_uuid: String,
|
||||
target_name: String,
|
||||
link_event_uuid: String,
|
||||
link_event_name: String,
|
||||
data: eventDataSchema,
|
||||
files: [{
|
||||
type: String
|
||||
}],
|
||||
status: String,
|
||||
confirmed: Boolean,
|
||||
// value could be ['active', 'inactive']
|
||||
signup_start_date: Date,
|
||||
member_col: Object,
|
||||
tags: [{
|
||||
type: String
|
||||
}],
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
edit_by: String,
|
||||
edit_date: Date,
|
||||
youtube_video_id: String,
|
||||
edit_history: [{
|
||||
type: editHistorySchema
|
||||
}],
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'calendar_event', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const CalendarEvent = mongoose.model("calendar_event", schema);
|
||||
return CalendarEvent;
|
||||
};
|
||||
20
app/models/center-phone.model.js
Normal file
@ -0,0 +1,20 @@
|
||||
const uniqueValidator = require('mongoose-unique-validator');
|
||||
module.exports = mongoose => {
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
phone_title: String,
|
||||
phone_number: String,
|
||||
activated: Boolean,
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'center_phone', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
schema.plugin(uniqueValidator);
|
||||
const CenterPhone = mongoose.model("center_phone", schema);
|
||||
return CenterPhone;
|
||||
};
|
||||
74
app/models/client.model.js
Normal file
@ -0,0 +1,74 @@
|
||||
const uniqueValidator = require('mongoose-unique-validator');
|
||||
module.exports = mongoose => {
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
username: {
|
||||
type: String,
|
||||
unique: true
|
||||
},
|
||||
name: String,
|
||||
name_cn: String,
|
||||
email: {
|
||||
type: String,
|
||||
unique: true
|
||||
},
|
||||
parent_id: String,
|
||||
password: String,
|
||||
care_provider: String,
|
||||
emergency_contact: String,
|
||||
medicare_number: String,
|
||||
medicaid_number: String,
|
||||
pharmacy: String,
|
||||
birth_date: String,
|
||||
firstname: String,
|
||||
lastname: String,
|
||||
address: String,
|
||||
address2: String,
|
||||
phone: String,
|
||||
mobile_phone: String,
|
||||
type: String,
|
||||
avatar: String,
|
||||
note: String,
|
||||
language: String,
|
||||
status: String,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
edit_by: String,
|
||||
edit_date: Date,
|
||||
password: String,
|
||||
pharmacy_id: String,
|
||||
pin: String,
|
||||
admission_date: String,
|
||||
home_phone: String,
|
||||
seating: String,
|
||||
vehicle_no: String,
|
||||
caller: String,
|
||||
roles: [{
|
||||
type: String
|
||||
}],
|
||||
discharge_date: String,
|
||||
placement: String,
|
||||
nickname: String,
|
||||
salt: String,
|
||||
groups: [{
|
||||
type: String
|
||||
}],
|
||||
tags: [{
|
||||
type: String
|
||||
}],
|
||||
api_token: String,
|
||||
data: String,
|
||||
title: String,
|
||||
private_note: String,
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'client', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const Client = mongoose.model("client", schema);
|
||||
return Client;
|
||||
};
|
||||
86
app/models/customer.model.js
Normal file
@ -0,0 +1,86 @@
|
||||
const uniqueValidator = require('mongoose-unique-validator');
|
||||
module.exports = mongoose => {
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
username: {
|
||||
type: String,
|
||||
unique: true
|
||||
},
|
||||
name: String,
|
||||
name_cn: String,
|
||||
email: {
|
||||
type: String,
|
||||
unique: true
|
||||
},
|
||||
parent_id: String,
|
||||
password: String,
|
||||
care_provider: String,
|
||||
emergency_contact: String,
|
||||
medicare_number: String,
|
||||
medicaid_number: String,
|
||||
pharmacy: String,
|
||||
birth_date: String,
|
||||
firstname: String,
|
||||
lastname: String,
|
||||
address1: String,
|
||||
address2: String,
|
||||
address3: String,
|
||||
address4: String,
|
||||
address5: String,
|
||||
phone: String,
|
||||
mobile_phone: String,
|
||||
type: String,
|
||||
avatar: String,
|
||||
special_needs: String,
|
||||
note: String,
|
||||
language: String,
|
||||
status: String,
|
||||
pickup_status: String,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
edit_by: String,
|
||||
edit_date: Date,
|
||||
password: String,
|
||||
pharmacy_id: String,
|
||||
pin: String,
|
||||
admission_date: String,
|
||||
home_phone: String,
|
||||
seating: String,
|
||||
vehicle_no: String,
|
||||
caller: String,
|
||||
roles: [{
|
||||
type: String
|
||||
}],
|
||||
discharge_date: String,
|
||||
placement: String,
|
||||
nickname: String,
|
||||
table_id: String,
|
||||
salt: String,
|
||||
groups: [{
|
||||
type: String
|
||||
}],
|
||||
tags: [{
|
||||
type: String
|
||||
}],
|
||||
api_token: String,
|
||||
data: String,
|
||||
title: String,
|
||||
apartment: String,
|
||||
private_note: String,
|
||||
site: Number,
|
||||
disability: Boolean,
|
||||
height: String,
|
||||
weight: String,
|
||||
gender: String,
|
||||
text_msg_enabled: Boolean
|
||||
},
|
||||
{ collection: 'customer', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const Customer = mongoose.model("customer", schema);
|
||||
return Customer;
|
||||
};
|
||||
37
app/models/doctemplate.model.js
Normal file
@ -0,0 +1,37 @@
|
||||
module.exports = mongoose => {
|
||||
var editHistorySchema = mongoose.Schema({
|
||||
employee: String,
|
||||
date: Date
|
||||
});
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
content: String,
|
||||
description: String,
|
||||
model: Object,
|
||||
status: String, // 'active', 'inactive'
|
||||
file: [{
|
||||
type: Object
|
||||
}],
|
||||
site: Number,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
edit_by: String,
|
||||
edit_date: Date,
|
||||
edit_history: [{
|
||||
type: editHistorySchema
|
||||
}],
|
||||
},
|
||||
{ collection: 'doctemplate', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const DocTemplate = mongoose.model("doctemplate", schema);
|
||||
return DocTemplate;
|
||||
};
|
||||
49
app/models/employee.model.js
Normal file
@ -0,0 +1,49 @@
|
||||
const uniqueValidator = require('mongoose-unique-validator');
|
||||
module.exports = mongoose => {
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
username: String,
|
||||
name: String,
|
||||
name_cn: String,
|
||||
email: String,
|
||||
password: String,
|
||||
roles: [{
|
||||
type: String
|
||||
}],
|
||||
mobile_phone: String,
|
||||
phone: String,
|
||||
home_phone: String,
|
||||
language: String,
|
||||
employment_status: String,
|
||||
status: String,
|
||||
address: String,
|
||||
title: String,
|
||||
title_cn: String,
|
||||
firstname: String,
|
||||
lastname: String,
|
||||
department: String,
|
||||
birth_date: String,
|
||||
driver_capacity: Number,
|
||||
date_hired: String,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
edit_by: String,
|
||||
edit_date: Date,
|
||||
note: String,
|
||||
tags: [{
|
||||
type: String
|
||||
}],
|
||||
fetch_route_time: Date,
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'employee', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
schema.index({username: 1, email: 1, site:1}, {unique: true});
|
||||
const Employee = mongoose.model("employee", schema);
|
||||
return Employee;
|
||||
};
|
||||
39
app/models/event-request.model.js
Normal file
@ -0,0 +1,39 @@
|
||||
module.exports = mongoose => {
|
||||
var editHistorySchema = mongoose.Schema({
|
||||
employee: String,
|
||||
date: Date
|
||||
});
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
customer_id: String,
|
||||
customer_display: String,
|
||||
source: String,
|
||||
type: String,
|
||||
symptom: String,
|
||||
resource: String,
|
||||
resource_display: String,
|
||||
transportation: String,
|
||||
np: String,
|
||||
upload: String,
|
||||
notes: [{
|
||||
content: String,
|
||||
author: String
|
||||
}],
|
||||
status: String,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
edit_history: [{
|
||||
type: editHistorySchema
|
||||
}],
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'event_request', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const EventRequest = mongoose.model("event_request", schema);
|
||||
return EventRequest;
|
||||
};
|
||||
30
app/models/index.js
Normal file
@ -0,0 +1,30 @@
|
||||
const dbConfig = require("../config/db.config.js");
|
||||
const mongoose = require("mongoose");
|
||||
mongoose.Promise = global.Promise;
|
||||
const db = {};
|
||||
db.mongoose = mongoose;
|
||||
db.url = dbConfig.url;
|
||||
db.user = require("./user.model.js")(mongoose);
|
||||
db.employee = require("./employee.model.js")(mongoose);
|
||||
db.staff = require("./staff.model")(mongoose);
|
||||
db.vehicle = require("./vehicle.model")(mongoose);
|
||||
db.customer = require("./customer.model")(mongoose);
|
||||
db.route_path = require("./route-path.model")(mongoose);
|
||||
db.route_path_template = require("./route-path-template.model")(mongoose);
|
||||
db.report = require("./report.model")(mongoose);
|
||||
db.client = require("./client.model")(mongoose);
|
||||
db.message = require("./message.model")(mongoose);
|
||||
db.resource = require("./resource.model")(mongoose);
|
||||
db.center_phone = require("./center-phone.model")(mongoose);
|
||||
db.message_token = require("./message-token.model")(mongoose);
|
||||
db.sent_message = require("./sent-message.model")(mongoose);
|
||||
db.calendar_event = require("./calendar-event.model")(mongoose);
|
||||
db.doctemplate = require("./doctemplate.model")(mongoose);
|
||||
db.exceltemplate = require("./xlsxtemplate.model")(mongoose);
|
||||
db.timedata = require("./timedata.model")(mongoose);
|
||||
db.breakfast = require("./breakfast.model")(mongoose);
|
||||
db.event_request = require("./event-request.model")(mongoose);
|
||||
db.signature_request = require("./signature-request.model")(mongoose);
|
||||
db.lunch = require("./lunch.model")(mongoose);
|
||||
db.snack = require("./snack.model")(mongoose);
|
||||
module.exports = db;
|
||||
29
app/models/lunch.model.js
Normal file
@ -0,0 +1,29 @@
|
||||
module.exports = mongoose => {
|
||||
var editHistorySchema = mongoose.Schema({
|
||||
employee: String,
|
||||
date: Date
|
||||
});
|
||||
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
customer_id: String,
|
||||
customer_name: String,
|
||||
date: String,
|
||||
has_lunch: Boolean,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
edit_history: [{
|
||||
type: editHistorySchema
|
||||
}],
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'lunch', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const Lunch = mongoose.model("lunch", schema);
|
||||
return Lunch;
|
||||
};
|
||||
18
app/models/message-token.model.js
Normal file
@ -0,0 +1,18 @@
|
||||
const uniqueValidator = require('mongoose-unique-validator');
|
||||
module.exports = mongoose => {
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
message_token: String,
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'message_token', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
schema.plugin(uniqueValidator);
|
||||
const MessageToken = mongoose.model("message_token", schema);
|
||||
return MessageToken;
|
||||
};
|
||||
22
app/models/message.model.js
Normal file
@ -0,0 +1,22 @@
|
||||
const uniqueValidator = require('mongoose-unique-validator');
|
||||
module.exports = mongoose => {
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
message_name: String,
|
||||
message_group: Number,
|
||||
language: String,
|
||||
message_body: String,
|
||||
message_title: String,
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'message_template', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
schema.plugin(uniqueValidator);
|
||||
const Message = mongoose.model("message", schema);
|
||||
return Message;
|
||||
};
|
||||
39
app/models/report.model.js
Normal file
@ -0,0 +1,39 @@
|
||||
const uniqueValidator = require('mongoose-unique-validator');
|
||||
module.exports = mongoose => {
|
||||
var checklistResultSchema = mongoose.Schema({
|
||||
item: String,
|
||||
result: Boolean
|
||||
});
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
date: String,
|
||||
route_id: String,
|
||||
route_name: String,
|
||||
driver_name: String,
|
||||
checklist_result: [{
|
||||
type: checklistResultSchema
|
||||
}],
|
||||
vehicle_number: Number,
|
||||
type: String,
|
||||
head: [{
|
||||
type: String
|
||||
}],
|
||||
chinese_head: [{
|
||||
type: String
|
||||
}],
|
||||
data: [{
|
||||
type: Object
|
||||
}],
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'report', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
schema.plugin(uniqueValidator);
|
||||
const Report = mongoose.model("report", schema);
|
||||
return Report;
|
||||
};
|
||||
51
app/models/resource.model.js
Normal file
@ -0,0 +1,51 @@
|
||||
module.exports = mongoose => {
|
||||
var editHistorySchema = mongoose.Schema({
|
||||
employee: String,
|
||||
date: Date
|
||||
});
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
name: String,
|
||||
name_original: String,
|
||||
name_branch: String,
|
||||
specialty: String,
|
||||
type: String, // value may be ['doctor', 'pharmacy' or 'other']
|
||||
color: String,
|
||||
address: String,
|
||||
city: String,
|
||||
state: String,
|
||||
zipcode: String,
|
||||
phone: String,
|
||||
status: String, // value might be ['active', 'inactive']
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
parent_id: String,
|
||||
ext_id: String,
|
||||
category: String,
|
||||
description: String,
|
||||
contact: String,
|
||||
fax: String,
|
||||
note: String,
|
||||
data: Object,
|
||||
edit_by: String,
|
||||
edit_date: Date,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
site: Number,
|
||||
images: [{
|
||||
type: String
|
||||
}],
|
||||
edit_history: [{
|
||||
type: editHistorySchema
|
||||
}],
|
||||
},
|
||||
{ collection: 'resource', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const Resource = mongoose.model("resource", schema);
|
||||
return Resource;
|
||||
};
|
||||
45
app/models/route-path-template.model.js
Normal file
@ -0,0 +1,45 @@
|
||||
module.exports = mongoose => {
|
||||
var routeCustomerListSchema = mongoose.Schema({
|
||||
customer_id: String,
|
||||
customer_name: String,
|
||||
customer_address: String,
|
||||
customer_avatar: String,
|
||||
customer_group: String,
|
||||
customer_group_address: String,
|
||||
customer_type: String,
|
||||
customer_pickup_status: String,
|
||||
customer_note: String,
|
||||
customer_special_needs: String,
|
||||
customer_phone: String,
|
||||
customer_enter_center_time: Date,
|
||||
customer_leave_center_time: Date,
|
||||
customer_pickup_time: Date,
|
||||
customer_dropoff_time: Date,
|
||||
customer_route_status: String,
|
||||
customer_pickup_order: Number,
|
||||
customer_table_id: String,
|
||||
customer_estimated_pickup_time: String,
|
||||
customer_estimated_dropoff_time: String
|
||||
});
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
name: String,
|
||||
vehicle: String,
|
||||
driver: String,
|
||||
type: String,
|
||||
route_customer_list: [{
|
||||
type: routeCustomerListSchema
|
||||
}],
|
||||
status: String,
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'route_path_template', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const RoutePathTemplate = mongoose.model("route_path_template", schema);
|
||||
return RoutePathTemplate;
|
||||
};
|
||||
65
app/models/route-path.model.js
Normal file
@ -0,0 +1,65 @@
|
||||
const uniqueValidator = require('mongoose-unique-validator');
|
||||
module.exports = mongoose => {
|
||||
var routeCustomerListSchema = mongoose.Schema({
|
||||
customer_id: String,
|
||||
customer_name: String,
|
||||
customer_address: String,
|
||||
customer_avatar: String,
|
||||
customer_group: String,
|
||||
customer_group_address: String,
|
||||
customer_type: String,
|
||||
customer_pickup_status: String,
|
||||
customer_note: String,
|
||||
customer_special_needs: String,
|
||||
customer_phone: String,
|
||||
customer_enter_center_time: Date,
|
||||
customer_leave_center_time: Date,
|
||||
customer_pickup_time: Date,
|
||||
customer_dropoff_time: Date,
|
||||
customer_route_status: String,
|
||||
customer_pickup_order: Number,
|
||||
customer_table_id: String,
|
||||
customer_transfer_to_route: String,
|
||||
customer_language: String,
|
||||
customer_estimated_pickup_time: String,
|
||||
customer_estimated_dropoff_time: String,
|
||||
customer_address_override: String,
|
||||
});
|
||||
var checklistResultSchema = mongoose.Schema({
|
||||
item: String,
|
||||
result: Boolean
|
||||
});
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
name: String,
|
||||
schedule_date: String,
|
||||
vehicle: String,
|
||||
status: [{
|
||||
type: String
|
||||
}],
|
||||
driver: String,
|
||||
type: String,
|
||||
start_mileage: Number,
|
||||
end_mileage: Number,
|
||||
start_time: Date,
|
||||
end_time: Date,
|
||||
estimated_start_time: Date,
|
||||
route_customer_list: [{
|
||||
type: routeCustomerListSchema
|
||||
}],
|
||||
checklist_result: [{
|
||||
type: checklistResultSchema,
|
||||
}],
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'route_path', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
schema.plugin(uniqueValidator);
|
||||
const RoutePath = mongoose.model("route_path", schema);
|
||||
return RoutePath;
|
||||
};
|
||||
26
app/models/sent-message.model.js
Normal file
@ -0,0 +1,26 @@
|
||||
const uniqueValidator = require('mongoose-unique-validator');
|
||||
module.exports = mongoose => {
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
from_type: String,
|
||||
from: String,
|
||||
to_type: String,
|
||||
to: String,
|
||||
department: String,
|
||||
content: String,
|
||||
status: String,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'message', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
schema.plugin(uniqueValidator);
|
||||
const SentMessage = mongoose.model("sentMessage", schema);
|
||||
return SentMessage;
|
||||
};
|
||||
23
app/models/signature-request.model.js
Normal file
@ -0,0 +1,23 @@
|
||||
module.exports = mongoose => {
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
driver_id: String,
|
||||
driver_name: String,
|
||||
route_id: String,
|
||||
route_date: String,
|
||||
route_name: String,
|
||||
status: String,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'signature_request', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const SignatureRequest = mongoose.model("signature_request", schema);
|
||||
return SignatureRequest;
|
||||
};
|
||||
29
app/models/snack.model.js
Normal file
@ -0,0 +1,29 @@
|
||||
module.exports = mongoose => {
|
||||
var editHistorySchema = mongoose.Schema({
|
||||
employee: String,
|
||||
date: Date
|
||||
});
|
||||
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
customer_id: String,
|
||||
customer_name: String,
|
||||
date: String,
|
||||
has_snack: Boolean,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
edit_history: [{
|
||||
type: editHistorySchema
|
||||
}],
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'snack', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const Snack = mongoose.model("snack", schema);
|
||||
return Snack;
|
||||
};
|
||||
63
app/models/staff.model.js
Normal file
@ -0,0 +1,63 @@
|
||||
const uniqueValidator = require('mongoose-unique-validator');
|
||||
module.exports = mongoose => {
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
username: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true
|
||||
},
|
||||
name: String,
|
||||
name_cn: String,
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true
|
||||
},
|
||||
password: String,
|
||||
roles: [{
|
||||
type: String
|
||||
}],
|
||||
mobile_phone: String,
|
||||
phone: String,
|
||||
home_phone: String,
|
||||
language: String,
|
||||
employment_status: String,
|
||||
status: String,
|
||||
title: String,
|
||||
title_cn: String,
|
||||
firstname: String,
|
||||
lastname: String,
|
||||
department: String,
|
||||
birth_date: String,
|
||||
driver_capacity: Number,
|
||||
date_hired: String,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
edit_by: String,
|
||||
edit_date: Date,
|
||||
note: Object,
|
||||
salt: String,
|
||||
city: String,
|
||||
state: String,
|
||||
zipcode: String,
|
||||
group: [{
|
||||
type: String
|
||||
}],
|
||||
tags: [{
|
||||
type: String
|
||||
}],
|
||||
parent_id: String,
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'staff', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
schema.plugin(uniqueValidator);
|
||||
const Staff = mongoose.model("staff", schema);
|
||||
return Staff;
|
||||
};
|
||||
25
app/models/timedata.model.js
Normal file
@ -0,0 +1,25 @@
|
||||
module.exports = mongoose => {
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
time: Date,
|
||||
translate1_number: Number,
|
||||
translate2_number: Number,
|
||||
max_resource_number: Number,
|
||||
status: String, // 'active', 'inactive'
|
||||
data: Object,
|
||||
site: Number,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
edit_by: String,
|
||||
edit_date: Date
|
||||
},
|
||||
{ collection: 'timedata', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const Timedata = mongoose.model("timedata", schema);
|
||||
return Timedata;
|
||||
};
|
||||
26
app/models/user.model.js
Normal file
@ -0,0 +1,26 @@
|
||||
module.exports = mongoose => {
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
username: String,
|
||||
email: String,
|
||||
salt: Number,
|
||||
password: String,
|
||||
api_token: String,
|
||||
roles: [{
|
||||
type: String
|
||||
}],
|
||||
status: String,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'user', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const User = mongoose.model("user", schema);
|
||||
return User;
|
||||
};
|
||||
40
app/models/vehicle.model.js
Normal file
@ -0,0 +1,40 @@
|
||||
const uniqueValidator = require('mongoose-unique-validator');
|
||||
module.exports = mongoose => {
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
vehicle_number: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
tag: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
ezpass: {
|
||||
type: String,
|
||||
},
|
||||
gps_tag: {
|
||||
type: String,
|
||||
},
|
||||
mileage: Number,
|
||||
capacity: Number,
|
||||
make: String,
|
||||
vehicle_model: String,
|
||||
year: String,
|
||||
checklist: [{
|
||||
type: String
|
||||
}],
|
||||
status: String,
|
||||
site: Number
|
||||
},
|
||||
{ collection: 'vehicle', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
schema.index({tag: 1, site:1}, {unique: true});
|
||||
const Vehicle = mongoose.model("vehicle", schema);
|
||||
return Vehicle;
|
||||
};
|
||||
37
app/models/xlsxtemplate.model.js
Normal file
@ -0,0 +1,37 @@
|
||||
module.exports = mongoose => {
|
||||
var editHistorySchema = mongoose.Schema({
|
||||
employee: String,
|
||||
date: Date
|
||||
});
|
||||
var schema = mongoose.Schema(
|
||||
{
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
content: String,
|
||||
description: String,
|
||||
model: Object,
|
||||
status: String, // 'active', 'inactive'
|
||||
file: [{
|
||||
type: Object
|
||||
}],
|
||||
site: Number,
|
||||
create_by: String,
|
||||
create_date: Date,
|
||||
edit_by: String,
|
||||
edit_date: Date,
|
||||
edit_history: [{
|
||||
type: editHistorySchema
|
||||
}],
|
||||
},
|
||||
{ collection: 'xlsx-template', timestamps: true }
|
||||
);
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
const ExcelTemplate = mongoose.model("xlsxtemplate", schema);
|
||||
return ExcelTemplate;
|
||||
};
|
||||
BIN
app/routes/.DS_Store
vendored
Normal file
11
app/routes/auth.routes.js
Normal file
@ -0,0 +1,11 @@
|
||||
module.exports = app => {
|
||||
const auth = require("../controllers/auth.controller");
|
||||
app.use(function(req, res, next) {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
app.post('/api/auth/login', auth.login);
|
||||
};
|
||||
19
app/routes/breakfast.routes.js
Normal file
@ -0,0 +1,19 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const breakfast = require("../controllers/breakfast.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all breakfasts
|
||||
router.get("/", [authJwt.verifyToken], breakfast.getAllBreakfasts);
|
||||
// Create a new breakfast
|
||||
router.post("/", [authJwt.verifyToken], breakfast.createNewBreakfast);
|
||||
router.put('/:id', [authJwt.verifyToken], breakfast.updateBreakfast);
|
||||
router.delete('/:id', [authJwt.verifyToken], breakfast.deleteBreakfast)
|
||||
app.use('/api/breakfasts', router);
|
||||
};
|
||||
23
app/routes/calendar-event.route.js
Normal file
@ -0,0 +1,23 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const calendarEvent = require("../controllers/calendar-event.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all Events
|
||||
router.get("/", [authJwt.verifyToken], calendarEvent.getAllEvents);
|
||||
router.get('/getByCustomer',[authJwt.verifyToken], calendarEvent.getEventsByCustomer );
|
||||
// Create a new Event
|
||||
router.post("/", [authJwt.verifyToken], calendarEvent.createCalendarEvent);
|
||||
router.get('/:id', [authJwt.verifyToken], calendarEvent.getEvent);
|
||||
router.put('/:id', [authJwt.verifyToken], calendarEvent.updateEvent);
|
||||
router.put('/:id/disable', [authJwt.verifyToken], calendarEvent.disableEvent);
|
||||
router.post('/assign', [authJwt.verifyToken], calendarEvent.assignTransportationToEvents);
|
||||
router.delete('/:id', [authJwt.verifyToken], calendarEvent.deleteEvent);
|
||||
app.use('/api/events', router);
|
||||
};
|
||||
19
app/routes/center-phone.routes.js
Normal file
@ -0,0 +1,19 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const centerPhone = require("../controllers/center-phone.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all Phones
|
||||
router.get("/", [authJwt.verifyToken], centerPhone.getAllCenterPhones);
|
||||
// Create a new Phone
|
||||
router.post("/", [authJwt.verifyToken], centerPhone.createCenterPhone);
|
||||
router.get('/:id', [authJwt.verifyToken], centerPhone.getCenterPhone);
|
||||
router.put('/:id', [authJwt.verifyToken], centerPhone.updateCenterPhone);
|
||||
app.use('/api/phones', router);
|
||||
};
|
||||
20
app/routes/client.routes.js
Normal file
@ -0,0 +1,20 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const clients = require("../controllers/client.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Create a new client
|
||||
router.post("/",[authJwt.verifyToken], clients.createClient);
|
||||
router.get("/:id",[authJwt.verifyToken], clients.getClient);
|
||||
// Update Client
|
||||
router.put("/:id",[authJwt.verifyToken], clients.updateClient );
|
||||
// Get clients with name or email
|
||||
router.get("/search", [authJwt.verifyToken], clients.getClientsWithNameOrEmail);
|
||||
app.use('/api/clients', router);
|
||||
};
|
||||
24
app/routes/customer.routes.js
Normal file
@ -0,0 +1,24 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const customers = require("../controllers/customer.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all customer
|
||||
router.get("/", [authJwt.verifyToken], customers.getAllCustomers);
|
||||
// Get All active customers
|
||||
router.get("/active",[authJwt.verifyToken], customers.getAllActiveCustomers);
|
||||
// Create a new customer
|
||||
router.post("/",[authJwt.verifyToken], customers.createCustomer);
|
||||
// Get Customers with name or email
|
||||
router.get("/search", [authJwt.verifyToken], customers.getCustomersWithNameOrEmail);
|
||||
// Update Customer
|
||||
router.put("/:id",[authJwt.verifyToken], customers.updateCustomer );
|
||||
router.get("/:id", [authJwt.verifyToken], customers.getCustomer);
|
||||
app.use('/api/customers', router);
|
||||
};
|
||||
9
app/routes/doctemplate.route.js
Normal file
@ -0,0 +1,9 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const docTemplates = require("../controllers/doctemplate.controller.js");
|
||||
var router = require("express").Router();
|
||||
// Retrieve all users
|
||||
router.get("/get-docs", docTemplates.createDocFromDocTemplateName);
|
||||
router.get("/get-pdfs", docTemplates.createPDFFromDocTemplateName);
|
||||
app.use('/api/docs', router);
|
||||
};
|
||||
21
app/routes/employee.routes.js
Normal file
@ -0,0 +1,21 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const employees = require("../controllers/employee.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all employee
|
||||
router.get("/",[authJwt.verifyToken], employees.getAllEmployees);
|
||||
// Create a new employee
|
||||
router.post("/", employees.createEmployee);
|
||||
// Update an employee
|
||||
router.put("/:id",[authJwt.verifyToken], employees.updateEmployee );
|
||||
// Get one employee
|
||||
router.get("/:id",[authJwt.verifyToken], employees.getEmployee)
|
||||
app.use('/api/employees', router);
|
||||
};
|
||||
19
app/routes/event-request.routes.js
Normal file
@ -0,0 +1,19 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const eventRequest = require("../controllers/event-request.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all event Request
|
||||
router.get("/", [authJwt.verifyToken], eventRequest.getAllEventRequests);
|
||||
// Create a new event Request
|
||||
router.post("/", [authJwt.verifyToken], eventRequest.createEventRequest);
|
||||
router.put('/:id', [authJwt.verifyToken], eventRequest.updateRequestItem);
|
||||
router.delete('/:id', [authJwt.verifyToken], eventRequest.deleteEventRequest)
|
||||
app.use('/api/event-requests', router);
|
||||
};
|
||||
19
app/routes/lunch.routes.js
Normal file
@ -0,0 +1,19 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const lunch = require("../controllers/lunch.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all lunches
|
||||
router.get("/", [authJwt.verifyToken], lunch.getAllLunches);
|
||||
// Create a new Lunch
|
||||
router.post("/", [authJwt.verifyToken], lunch.createNewLunch);
|
||||
router.put('/:id', [authJwt.verifyToken], lunch.updateLunch);
|
||||
router.delete('/:id', [authJwt.verifyToken], lunch.deleteLunch)
|
||||
app.use('/api/lunches', router);
|
||||
};
|
||||
19
app/routes/message-token.routes.js
Normal file
@ -0,0 +1,19 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const messageTokens = require("../controllers/message-token.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all messageTokens
|
||||
router.get("/",[authJwt.verifyToken], messageTokens.getAllMessageTokens);
|
||||
// Create a new messageToken
|
||||
router.post("/", [authJwt.verifyToken], messageTokens.createMessageToken);
|
||||
// Update an messageToken
|
||||
router.put("/:id",[authJwt.verifyToken], messageTokens.updateMessageToken );
|
||||
app.use('/api/message-tokens', router);
|
||||
};
|
||||
25
app/routes/message.routes.js
Normal file
@ -0,0 +1,25 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
|
||||
module.exports = app => {
|
||||
const messages = require("../controllers/message.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all messages
|
||||
router.get("/",[authJwt.verifyToken], messages.getAllMessages);
|
||||
// Create a new message
|
||||
router.post("/", [authJwt.verifyToken], messages.createMessage);
|
||||
// Update an message
|
||||
router.put("/:id",[authJwt.verifyToken], messages.updateMessage );
|
||||
// Get messages by Date and Type
|
||||
router.get("/:id", [authJwt.verifyToken], messages.getMessage);
|
||||
router.get("/sent-messages/all", [authJwt.verifyToken], messages.getAllSentMessages);
|
||||
router.get("/public/search", messages.getMessagesByGroupAndLanguage);
|
||||
router.post("/public/send", [authJwt.verifyToken], messages.sendMessage);
|
||||
app.use('/api/messages', router);
|
||||
};
|
||||
22
app/routes/report.routes.js
Normal file
@ -0,0 +1,22 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const reports = require("../controllers/report.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all reports
|
||||
router.get("/",[authJwt.verifyToken], reports.getAllReports);
|
||||
// Create a new report
|
||||
router.post("/", [authJwt.verifyToken], reports.createReport);
|
||||
// Update an report
|
||||
router.put("/:id",[authJwt.verifyToken], reports.updateReport );
|
||||
// Get reports by Date and Type
|
||||
router.get("/search", reports.getReportsByDateAndType);
|
||||
router.get("/search-route", reports.getReportsByRouteIdAndType);
|
||||
app.use('/api/reports', router);
|
||||
};
|
||||
14
app/routes/resource.routes.js
Normal file
@ -0,0 +1,14 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const resource = require("../controllers/resource.controller.js");
|
||||
var router = require("express").Router();
|
||||
// Retrieve all resources
|
||||
router.get("/", [authJwt.verifyToken], resource.getAllResources);
|
||||
// Create a new resource
|
||||
router.post("/", [authJwt.verifyToken], resource.createResource);
|
||||
router.get('/:id', [authJwt.verifyToken], resource.getResource);
|
||||
router.put('/:id', [authJwt.verifyToken], resource.updateResource);
|
||||
router.put('/:id/disable', [authJwt.verifyToken], resource.disableResource);
|
||||
router.delete('/:id', [authJwt.verifyToken], resource.deleteResource)
|
||||
app.use('/api/resources', router);
|
||||
};
|
||||
22
app/routes/route-path-template.routes.js
Normal file
@ -0,0 +1,22 @@
|
||||
const { route } = require("express/lib/application");
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const routePathTemplates = require("../controllers/route-path-template.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all routes
|
||||
router.get("/", [authJwt.verifyToken],routePathTemplates.getAllRoutesTemplates);
|
||||
// Create a new route
|
||||
router.post("/", [authJwt.verifyToken], routePathTemplates.createRoutePathTemplate);
|
||||
// Update a route with id
|
||||
router.put("/:id", [authJwt.verifyToken], routePathTemplates.updateRouteTemplate);
|
||||
// Delete a route with id
|
||||
router.delete("/:id", [authJwt.verifyToken], routePathTemplates.deleteRouteTemplate);
|
||||
app.use('/api/route-templates', router);
|
||||
};
|
||||
25
app/routes/route-path.routes.js
Normal file
@ -0,0 +1,25 @@
|
||||
const { route } = require("express/lib/application");
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const routePaths = require("../controllers/route-path.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all routes
|
||||
router.get("/", [authJwt.verifyToken], routePaths.getAllRoutes);
|
||||
router.get("/:id", [authJwt.verifyToken], routePaths.getRoute);
|
||||
// Create a new route
|
||||
router.post("/", [authJwt.verifyToken], routePaths.createRoutePath);
|
||||
// Update a route with id
|
||||
router.put("/:id", [authJwt.verifyToken], routePaths.updateRoute);
|
||||
// Delete a route with id
|
||||
router.delete("/:id", [authJwt.verifyToken], routePaths.deleteRoute);
|
||||
router.post("/update-in-progress", [authJwt.verifyToken], routePaths.updateRouteInProgress);
|
||||
router.get("/routes-with-phone", routePaths.getAllRoutesWithPhones);
|
||||
app.use('/api/routes', router);
|
||||
};
|
||||
23
app/routes/signature-request.routes.js
Normal file
@ -0,0 +1,23 @@
|
||||
const { route } = require("express/lib/application");
|
||||
module.exports = app => {
|
||||
const signatureRequest = require("../controllers/signature-request.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all signature requests
|
||||
router.get("/",signatureRequest.getAllSignatureRequests);
|
||||
// Get one signature request by id
|
||||
router.get("/:id", signatureRequest.getSignatureRequest);
|
||||
// Create a new signature request
|
||||
router.post("/", signatureRequest.createNewSignatureRequest);
|
||||
// Update a signature request with id
|
||||
router.put("/:id", signatureRequest.updateSignatureRequest);
|
||||
// Delete a signature request with id
|
||||
router.delete("/:id", signatureRequest.deleteSignatureRequest);
|
||||
app.use('/api/signature-requests', router);
|
||||
};
|
||||
19
app/routes/snack.routes.js
Normal file
@ -0,0 +1,19 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const snack = require("../controllers/snack.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all snacks
|
||||
router.get("/", [authJwt.verifyToken], snack.getAllSnacks);
|
||||
// Create a new snack
|
||||
router.post("/", [authJwt.verifyToken], snack.createNewSnack);
|
||||
router.put('/:id', [authJwt.verifyToken], snack.updateSnack);
|
||||
router.delete('/:id', [authJwt.verifyToken], snack.deleteSnack)
|
||||
app.use('/api/snacks', router);
|
||||
};
|
||||
19
app/routes/staff.routes.js
Normal file
@ -0,0 +1,19 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const staffs = require("../controllers/staff.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Create a new staff
|
||||
router.post("/", staffs.createStaff);
|
||||
// Update an Staff
|
||||
router.put("/:id",[authJwt.verifyToken], staffs.updateStaff );
|
||||
// Get Staff by email or username
|
||||
router.get("/search", [authJwt.verifyToken], staffs.getStaffsWithNameOrEmail)
|
||||
app.use('/api/staffs', router);
|
||||
};
|
||||
9
app/routes/timedata.routes.js
Normal file
@ -0,0 +1,9 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const timedata = require("../controllers/timedata.controller");
|
||||
var router = require("express").Router();
|
||||
// Retrieve all users
|
||||
router.get("/get-by-condition1", timedata.getDocsByCondition1);
|
||||
|
||||
app.use('/api/timedata', router);
|
||||
};
|
||||
8
app/routes/upload.routes.js
Normal file
@ -0,0 +1,8 @@
|
||||
module.exports = app => {
|
||||
const upload = require("../controllers/upload.controller.js");
|
||||
var router = require("express").Router();
|
||||
router.get("/:name", upload.getFile);
|
||||
router.post("/upload/:filename", upload.uploadFiles);
|
||||
router.post("/delete", upload.deleteFile);
|
||||
app.use('/api/files', router);
|
||||
};
|
||||
7
app/routes/user.routes.js
Normal file
@ -0,0 +1,7 @@
|
||||
module.exports = app => {
|
||||
const user = require("../controllers/user.controller.js");
|
||||
var router = require("express").Router();
|
||||
// Retrieve all users
|
||||
router.get("/", user.getAllUsers);
|
||||
app.use('/api/users', router);
|
||||
};
|
||||
21
app/routes/vehicle.routes.js
Normal file
@ -0,0 +1,21 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const vehicles = require("../controllers/vehicle.controller.js");
|
||||
app.use((req, res, next) => {
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"x-access-token, Origin, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
});
|
||||
var router = require("express").Router();
|
||||
// Retrieve all employee
|
||||
router.get("/", [authJwt.verifyToken], vehicles.getAllVehicles);
|
||||
// Create a new employee
|
||||
router.post("/", [authJwt.verifyToken], vehicles.createVehicle);
|
||||
router.get('/active', [authJwt.verifyToken], vehicles.getAllActiveVehicles);
|
||||
router.get('/:id', [authJwt.verifyToken], vehicles.getVehicle);
|
||||
router.put('/:id', [authJwt.verifyToken], vehicles.updateVehicle);
|
||||
router.delete('/:id', [authJwt.verifyToken], vehicles.deleteVehicle);
|
||||
app.use('/api/vehicles', router);
|
||||
};
|
||||
9
app/routes/xlsxtemplate.route.js
Normal file
@ -0,0 +1,9 @@
|
||||
const {authJwt} = require("../middlewares");
|
||||
module.exports = app => {
|
||||
const excelTemplates = require("../controllers/xlsxtemplate.controller");
|
||||
var router = require("express").Router();
|
||||
// Retrieve all users
|
||||
router.get("/get-sheets", excelTemplates.createSheetFromTemplateName);
|
||||
router.get("/get-pdf", excelTemplates.createPDFFromSheetTemplateName);
|
||||
app.use('/api/sheets', router);
|
||||
};
|
||||
BIN
app/upload/.DS_Store
vendored
Normal file
BIN
app/upload/module-file-1620410222358
Normal file
BIN
app/upload/module-file-1634054180752
Normal file
BIN
app/upload/module-file-1646425098919
Normal file
BIN
app/views/.DS_Store
vendored
Normal file
16
app/views/asset-manifest.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"files": {
|
||||
"main.css": "/static/css/main.22055773.css",
|
||||
"main.js": "/static/js/main.3884af74.js",
|
||||
"static/js/787.c4e7f8f9.chunk.js": "/static/js/787.c4e7f8f9.chunk.js",
|
||||
"static/media/background.jpg": "/static/media/background.d0e107221150b4c16901.jpg",
|
||||
"index.html": "/index.html",
|
||||
"main.22055773.css.map": "/static/css/main.22055773.css.map",
|
||||
"main.3884af74.js.map": "/static/js/main.3884af74.js.map",
|
||||
"787.c4e7f8f9.chunk.js.map": "/static/js/787.c4e7f8f9.chunk.js.map"
|
||||
},
|
||||
"entrypoints": [
|
||||
"static/css/main.22055773.css",
|
||||
"static/js/main.3884af74.js"
|
||||
]
|
||||
}
|
||||
BIN
app/views/favicon-16x16.png
Executable file
|
After Width: | Height: | Size: 643 B |
BIN
app/views/favicon-32x32.png
Executable file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
app/views/favicon.ico
Executable file
|
After Width: | Height: | Size: 15 KiB |
BIN
app/views/images/.DS_Store
vendored
Normal file
BIN
app/views/images/background.jpg
Normal file
|
After Width: | Height: | Size: 149 KiB |
BIN
app/views/images/default.png
Normal file
|
After Width: | Height: | Size: 201 B |
BIN
app/views/images/down_arrow.png
Normal file
|
After Width: | Height: | Size: 158 B |
1
app/views/images/drag-and-drop.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg class="svg-icon" style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M1020.928353 527.024211a39.408053 39.408053 0 0 0 3.056594-15.047455c0-5.247922-1.095664-10.342246-3.056594-15.124255a38.445507 38.445507 0 0 0-8.463234-12.620612l-162.542218-162.547338c-15.277852-15.282972-40.042923-15.282972-55.407814 0-15.277852 15.359771-15.277852 40.129962 0 55.412934l95.691374 95.691374h-339.031109V133.665592l95.691374 95.691375a39.044538 39.044538 0 0 0 27.668068 11.443029c10.029931 0 20.059861-3.839943 27.739747-11.443029 15.282972-15.359771 15.282972-40.124842 0-55.407815L539.655524 11.396694c-1.802213-1.879012-4.075459-2.739159-6.189988-4.147138-2.114528-1.413099-3.99354-3.215312-6.425504-4.234177a39.459252 39.459252 0 0 0-30.171711 0c-2.431964 1.018865-4.234177 2.815958-6.425504 4.229057-2.03773 1.413099-4.310976 2.273246-6.195107 4.152258L321.710611 173.949152c-15.282972 15.282972-15.282972 40.048043 0 55.407815a39.208376 39.208376 0 0 0 55.407815 0l95.691374-95.691375V472.788859H133.778692l95.609455-95.691374c15.359771-15.282972 15.359771-40.053163 0-55.412934-15.282972-15.282972-40.048043-15.282972-55.407815 0L11.525153 484.231889A37.273045 37.273045 0 0 0 3.051679 496.852501 38.368708 38.368708 0 0 0 0.000205 511.976756a37.989834 37.989834 0 0 0 3.056594 15.052575 37.58536 37.58536 0 0 0 8.463234 12.697411l162.460299 162.465419a39.029178 39.029178 0 0 0 27.744867 11.44303c10.03505 0 20.064981-3.763144 27.662948-11.44303 15.359771-15.282972 15.359771-40.124842 0-55.407814L133.783811 551.164652h339.031109v339.051588l-95.691374-95.619695a39.065018 39.065018 0 0 0-55.407815 0c-15.282972 15.282972-15.282972 40.048043 0 55.412934l162.4603 162.470539a39.438772 39.438772 0 0 0 12.851008 8.463234A37.887435 37.887435 0 0 0 511.992576 1023.999846c5.094324 0 10.188648-1.018865 14.888738-3.056594a38.629824 38.629824 0 0 0 12.851009-8.463234l162.542218-162.470539c15.282972-15.359771 15.282972-40.129962 0-55.412934-15.359771-15.359771-40.124842-15.359771-55.407815 0l-95.691374 95.619695v-339.051588h339.031109l-95.691374 95.619695c-15.277852 15.282972-15.277852 40.124842 0 55.407814a39.029178 39.029178 0 0 0 27.744866 11.44303c10.03505 0 20.064981-3.763144 27.662948-11.44303l162.542218-162.470539a38.773182 38.773182 0 0 0 8.463234-12.697411" fill="#304156" /></svg>
|
||||
|
After Width: | Height: | Size: 2.4 KiB |
BIN
app/views/images/logo.png
Normal file
|
After Width: | Height: | Size: 228 KiB |
BIN
app/views/images/logo1.png
Normal file
|
After Width: | Height: | Size: 230 KiB |
BIN
app/views/images/logo2.png
Normal file
|
After Width: | Height: | Size: 233 KiB |