UI update

This commit is contained in:
2025-11-26 20:17:53 +03:00
parent e07c5933ee
commit b6dfe5546e
7 changed files with 544 additions and 19 deletions

View File

@@ -4,6 +4,7 @@ import cors from "cors";
import mongoose from "mongoose";
import { Server } from "socket.io";
import authRoutes from "./routes/auth.js";
import jobsRoutes from "./routes/jobs.js";
import { config } from "./config/env.js";
import jwt from "jsonwebtoken";
@@ -22,6 +23,7 @@ app.get("/health", (_req, res) => {
});
app.use("/auth", authRoutes);
app.use("/jobs", jobsRoutes);
const server = http.createServer(app);

26
backend/src/models/job.ts Normal file
View File

@@ -0,0 +1,26 @@
import mongoose, { Schema, Document } from "mongoose";
export type TimeUnit = "dakika" | "saat" | "gün";
export interface JobDocument extends Document {
name: string;
repoUrl: string;
testCommand: string;
checkValue: number;
checkUnit: TimeUnit;
createdAt: Date;
updatedAt: Date;
}
const JobSchema = new Schema<JobDocument>(
{
name: { type: String, required: true, trim: true },
repoUrl: { type: String, required: true, trim: true },
testCommand: { type: String, required: true, trim: true },
checkValue: { type: Number, required: true, min: 1 },
checkUnit: { type: String, required: true, enum: ["dakika", "saat", "gün"] }
},
{ timestamps: true }
);
export const Job = mongoose.model<JobDocument>("Job", JobSchema);

View File

@@ -0,0 +1,54 @@
import { Router } from "express";
import { authMiddleware } from "../middleware/authMiddleware.js";
import { Job } from "../models/job.js";
const router = Router();
router.use(authMiddleware);
router.get("/", async (_req, res) => {
const jobs = await Job.find().sort({ createdAt: -1 }).lean();
res.json(jobs);
});
router.post("/", async (req, res) => {
const { name, repoUrl, testCommand, checkValue, checkUnit } = req.body;
if (!name || !repoUrl || !testCommand || !checkValue || !checkUnit) {
return res.status(400).json({ message: "Tüm alanlar gerekli" });
}
try {
const job = await Job.create({ name, repoUrl, testCommand, checkValue, checkUnit });
return res.status(201).json(job);
} catch (err) {
return res.status(400).json({ message: "Job oluşturulamadı", error: (err as Error).message });
}
});
router.put("/:id", async (req, res) => {
const { id } = req.params;
const { name, repoUrl, testCommand, checkValue, checkUnit } = req.body;
try {
const job = await Job.findByIdAndUpdate(
id,
{ name, repoUrl, testCommand, checkValue, checkUnit },
{ new: true, runValidators: true }
);
if (!job) return res.status(404).json({ message: "Job bulunamadı" });
return res.json(job);
} catch (err) {
return res.status(400).json({ message: "Job güncellenemedi", error: (err as Error).message });
}
});
router.delete("/:id", async (req, res) => {
const { id } = req.params;
try {
const job = await Job.findByIdAndDelete(id);
if (!job) return res.status(404).json({ message: "Job bulunamadı" });
return res.json({ success: true });
} catch (err) {
return res.status(400).json({ message: "Job silinemedi", error: (err as Error).message });
}
});
export default router;