location controller updated with heading and created new models and controllers for remaining modules
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import {
|
||||
createAssignment,
|
||||
updateAssignment,
|
||||
getAssignmentsByQuery,
|
||||
} from "../models/Assignment/operations.js";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
export const createAssignmentHandler = async (req, res) => {
|
||||
try {
|
||||
const { user } = res.locals;
|
||||
const previousAssignment = await updateAssignment(req.body.venue, {
|
||||
isActive: false,
|
||||
});
|
||||
const assignment = await createAssignment({
|
||||
...req.body,
|
||||
createdOn: dayjs().toISOString(),
|
||||
createdBy: user.id,
|
||||
});
|
||||
res.status(201).json({ result: { assignment, previousAssignment } });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Error creating assignment", error });
|
||||
}
|
||||
};
|
||||
|
||||
export const updateAssignmentHandler = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const assignment = await updateAssignment(id, req.body);
|
||||
res.status(200).json({ result: assignment });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Error updating assignment", error });
|
||||
}
|
||||
};
|
||||
|
||||
export const getAssignmentsByUserHandler = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const assignment = await getAssignmentsByQuery({ user: id });
|
||||
res.status(200).json({ result: assignment });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Error getting assignment", error });
|
||||
}
|
||||
};
|
||||
|
||||
export const deactivateAssignmentHandler = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const assignment = await updateAssignment(id, { isActive: false });
|
||||
res.status(200).json({ result: assignment });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Error deactivating assignment", error });
|
||||
}
|
||||
};
|
||||
|
||||
export const getAssignmentByVenueHandler = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const assignment = await getAssignmentsByQuery({ venue: id });
|
||||
res.status(200).json({ result: assignment });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Error getting assignment", error });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user