UI update
This commit is contained in:
@@ -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
26
backend/src/models/job.ts
Normal 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);
|
||||
54
backend/src/routes/jobs.ts
Normal file
54
backend/src/routes/jobs.ts
Normal 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;
|
||||
Reference in New Issue
Block a user