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';
|
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
|
// Controller for creating a visit record
|
||||||
export const createVisit = async (req, res) => {
|
export const createVisit = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@ -9,7 +14,7 @@ export const createVisit = async (req, res) => {
|
|||||||
if (!addedFor || !addedForId || !tradename || !visitDate) {
|
if (!addedFor || !addedForId || !tradename || !visitDate) {
|
||||||
return res.status(400).json({ message: 'All fields are required' });
|
return res.status(400).json({ message: 'All fields are required' });
|
||||||
}
|
}
|
||||||
|
const parsedDate = parseDate(visitDate);
|
||||||
// Create a new visit record
|
// Create a new visit record
|
||||||
const newVisit = new VisitRDandPD({
|
const newVisit = new VisitRDandPD({
|
||||||
visitBy,
|
visitBy,
|
||||||
@ -17,7 +22,7 @@ export const createVisit = async (req, res) => {
|
|||||||
addedFor,
|
addedFor,
|
||||||
addedForId,
|
addedForId,
|
||||||
tradename,
|
tradename,
|
||||||
visitDate,
|
visitDate: parsedDate,
|
||||||
note,
|
note,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user