created API For Aplication Absensi

This commit is contained in:
2025-10-14 14:08:11 +07:00
commit 96d206d892
56 changed files with 6533 additions and 0 deletions

48
app/middlewares/apiKey.js Normal file
View File

@@ -0,0 +1,48 @@
const express = require("express");
const app = express();
const Sequelize = require("sequelize");
const db = require("../../models/migration");
const ApiKey = db.apiKey;
async function apiKey(req, res, next) {
const api_key = req.get("ApiKey");
if (!api_key) {
return res.status(401).json({
success: false,
message: "API Key is missing",
code: 401,
});
}
try {
const apiKeyData = await ApiKey.findOne({
where: {
api_key: api_key,
is_actived: 1,
},
});
if (!apiKeyData) {
return res.status(401).json({
success: false,
message: "Unauthorized",
code: 401,
});
}
next();
} catch (err) {
console.error("Error querying API key from database:", err);
return res.status(500).json({
success: false,
message: "Internal Server Error",
code: 500,
});
}
}
module.exports = apiKey;