This commit is contained in:
yaoyanwei
2025-08-04 16:25:38 +08:00
parent 8d542ea201
commit 4b2bb35c20
46 changed files with 5128 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
// MODELS / TOOLS
const Activity = require("./activity.model");
exports.GetAllActivities = async (req, res) => {
let activityRequest;
if (req.body.type) {
activityRequest = { type: req.body.type };
} else if (req.body.username) {
activityRequest = { username: req.body.username };
}
else {
activityRequest = { };
}
const a = await Activity.Get(activityRequest);
if (!a) return res.status(500).send({ error: "Failed!!" });
return res.status(200).send(a);
};

View File

@@ -0,0 +1,56 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const activitySchema = new Schema(
{
type: {type: String},
username: {type: String},
timestamp: {type: Date},
data: {type: Object, _id: false},
});
activitySchema.methods.toObj = function () {
var elem = this.toObject();
delete elem.__v;
delete elem._id;
return elem;
};
const Activity = mongoose.model("Activity", activitySchema);
exports.Activity = Activity;
// ------------------------------
exports.LogActivity = async (type, username, data) => {
var activity_data = {
type: type,
username: username,
timestamp: Date.now(),
data: data
}
try {
const activity = new Activity(activity_data);
return await activity.save();
}
catch{
return null;
}
};
exports.GetAll = async () => {
try {
const logs = await Activity.find({});
return logs;
} catch (e) {
return [];
}
};
exports.Get = async (data) => {
try {
const logs = await Activity.find(data);
return logs;
} catch (e) {
return [];
}
};

View File

@@ -0,0 +1,19 @@
const ActivityController = require("./activity.controller");
const AuthTool = require("../authorization/auth.tool");
const config = require("../config");
const ADMIN = config.permissions.ADMIN; //Highest permision, can read and write all users
const SERVER = config.permissions.SERVER; //Middle permission, can read all users
const USER = config.permissions.USER; //Lowest permision, can only do things on same user
exports.route = function (app) {
app.get("/activity", [
AuthTool.isValidJWT,
AuthTool.isPermissionLevel(ADMIN),
ActivityController.GetAllActivities,
]);
}