1
This commit is contained in:
52
tasks/tasks.controller.js
Normal file
52
tasks/tasks.controller.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const TasksModel = require("./tasks.model.js");
|
||||
|
||||
// Get all task configurations
|
||||
exports.getAllTasks = async (req, res) => {
|
||||
try {
|
||||
const tasks = await TasksModel.getAllTaskConfigs();
|
||||
res.status(200).send(tasks);
|
||||
} catch (error) {
|
||||
res.status(500).send({ error: "Internal server error" });
|
||||
}
|
||||
};
|
||||
|
||||
// Get player tasks
|
||||
exports.getPlayerTasks = async (req, res) => {
|
||||
try {
|
||||
const userId = req.params.userId;
|
||||
if (!userId) {
|
||||
return res.status(400).send({ error: "User ID is required" });
|
||||
}
|
||||
|
||||
const playerTasks = await TasksModel.getPlayerTasks(userId);
|
||||
if (!playerTasks) {
|
||||
return res.status(404).send({ error: "Player tasks not found" });
|
||||
}
|
||||
|
||||
res.status(200).send(playerTasks);
|
||||
} catch (error) {
|
||||
res.status(500).send({ error: "Internal server error" });
|
||||
}
|
||||
};
|
||||
|
||||
// Save player tasks
|
||||
exports.savePlayerTasks = async (req, res) => {
|
||||
try {
|
||||
const userId = req.params.userId;
|
||||
if (!userId) {
|
||||
return res.status(400).send({ error: "User ID is required" });
|
||||
}
|
||||
|
||||
const tasksData = req.body;
|
||||
tasksData.userId = userId;
|
||||
|
||||
const updatedTasks = await TasksModel.savePlayerTasks(tasksData);
|
||||
if (!updatedTasks) {
|
||||
return res.status(500).send({ error: "Failed to save player tasks" });
|
||||
}
|
||||
|
||||
res.status(200).send({ success: true });
|
||||
} catch (error) {
|
||||
res.status(500).send({ error: "Internal server error" });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user