visit rd and pd stored in database
This commit is contained in:
parent
ec4284bfc4
commit
e1906cadbb
@ -1,5 +1,10 @@
|
||||
import VisitRDandPD from './VisitRD&PDModel.js';
|
||||
|
||||
const parseDate = (dateStr) => {
|
||||
const [day, month, year] = dateStr.split("/").map(Number);
|
||||
// Create a UTC date object to ensure the correct date is stored
|
||||
return new Date(Date.UTC(year, month - 1, day));
|
||||
};
|
||||
// Controller for creating a visit record
|
||||
export const createVisit = async (req, res) => {
|
||||
try {
|
||||
@ -9,7 +14,7 @@ export const createVisit = async (req, res) => {
|
||||
if (!addedFor || !addedForId || !tradename || !visitDate) {
|
||||
return res.status(400).json({ message: 'All fields are required' });
|
||||
}
|
||||
|
||||
const parsedDate = parseDate(visitDate);
|
||||
// Create a new visit record
|
||||
const newVisit = new VisitRDandPD({
|
||||
visitBy,
|
||||
@ -17,7 +22,7 @@ export const createVisit = async (req, res) => {
|
||||
addedFor,
|
||||
addedForId,
|
||||
tradename,
|
||||
visitDate,
|
||||
visitDate: parsedDate,
|
||||
note,
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user