diff --git a/controllers/backend.js b/controllers/backend.js deleted file mode 100644 index f6f134a..0000000 --- a/controllers/backend.js +++ /dev/null @@ -1,17 +0,0 @@ -const {Application} = require("../core/server"); -const Joi = require("joi"); -const { PostDataProcess } = require("../core/postdata"); -const User = require("../database/user"); -const { MiddlewareAuth } = require("./auth"); - - -Application.get("/panel", MiddlewareAuth,PanelPage); - -/** - * @param {import("express").Request} request - * @param {import("express").Response} response - */ -async function PanelPage(request, response) -{ - response.render("panel"); -} \ No newline at end of file diff --git a/controllers/catalog.js b/controllers/catalog.js new file mode 100644 index 0000000..66ebb49 --- /dev/null +++ b/controllers/catalog.js @@ -0,0 +1,87 @@ +const {Application} = require("../core/server"); +const Joi = require("joi"); +const { PostDataProcess } = require("../core/postdata"); +const User = require("../database/user"); +const { MiddlewareAuth } = require("./auth"); +const express = require("express"); +const { countCatalogs, getCatalogs, createCatalog } = require("../database/catalog"); + + +Application.get("/catalogs", MiddlewareAuth,CatalogPage); +/** + * @param {import("express").Request} request + * @param {import("express").Response} response + */ +async function CatalogPage(request, response) +{ + response.render("panel/catalogs"); +} + +Application.post("/catalog/list", MiddlewareAuth, express.urlencoded({extended: true}), CatalogsList); +/** + * @param {import("express").Request} request + * @param {import("express").Response} response + */ +async function CatalogsList(request, response) +{ + let start = request.body.start ?? 0; + let length = request.body.length ?? 100; + let term = request.body.search?.value ?? null; + let count = await countCatalogs(request.session.user_id, term); + let data = await getCatalogs(request.session.user_id,start,length, term); + response.json({ + "draw": request.body.draw | 0, + "recordsTotal": count, + "recordsFiltered" : count, + "length": 0, + "data": data + }); +} + + +Application.post("/catalog/store", MiddlewareAuth, PostDataProcess(), CatalogStore); +/** + * @param {import("express").Request} request + * @param {import("express").Response} response + */ +async function CatalogStore(request, response) +{ + const error = catalogStoreValidation(request.body); + + if(error) + { + return response.status(400).json({ + status: "fail", + message: error.message + }); + } + + try{ + await createCatalog( + request.session.user_id, + request.body.name, + request.body.score, + request.body.description + ); + return response.status(200).json({ + status: "success" + }); + }catch(err){ + console.log(err) + return response.status(500).json({ + status: "fail" + }); + } +} + +function catalogStoreValidation(body) +{ + const schema = Joi.object({ + id: Joi.number().min(1), + name: Joi.string().min(3).max(200).required().error(new Error('Adı en az 3 karakter ve zorunludur')), + score: Joi.number().min(1).allow('', null).error(new Error('Soyadı formatı hatalı')), + description: Joi.string().allow('', null) + }); + const {error} = schema.validate(body); + return error; +} \ No newline at end of file diff --git a/controllers/students.js b/controllers/students.js new file mode 100644 index 0000000..ca22573 --- /dev/null +++ b/controllers/students.js @@ -0,0 +1,163 @@ +const {Application} = require("../core/server"); +const Joi = require("joi"); +const { PostDataProcess } = require("../core/postdata"); +const User = require("../database/user"); +const { MiddlewareAuth } = require("./auth"); +const { createStudent, getStudents, countStudents, updateStudent } = require("../database/student"); +const express = require("express"); + + +Application.get("/panel", MiddlewareAuth,PanelPage); +/** + * @param {import("express").Request} request + * @param {import("express").Response} response + */ +async function PanelPage(request, response) +{ + response.render("panel/panel"); +} + +Application.post("/user/profile", MiddlewareAuth,ApiUserProfile); +/** + * @param {import("express").Request} request + * @param {import("express").Response} response + */ +async function ApiUserProfile(request, response) +{ + let name = request.session.user.name; + let surname = request.session.user.surname; + + response.json({ + status: "active", + name, + surname + }); +} + + +Application.get("/students", MiddlewareAuth,StudentsPage); +/** + * @param {import("express").Request} request + * @param {import("express").Response} response + */ +async function StudentsPage(request, response) +{ + response.render("panel/students"); +} + +Application.post("/students/store", MiddlewareAuth, PostDataProcess(), StudentStore); +/** + * @param {import("express").Request} request + * @param {import("express").Response} response + */ +async function StudentStore(request, response) +{ + const error = studentStoreValidation(request.body); + + if(error) + { + return response.status(400).json({ + status: "fail", + message: error.message + }); + } + + try{ + await createStudent( + request.session.user_id, + request.body.name, + request.body.surname, + request.body.studentno, + request.body.email, + request.body.gender, + request.body.birthdate || null, + request.body.description + ); + return response.status(200).json({ + status: "success" + }); + }catch(err){ + console.log(err) + return response.status(500).json({ + status: "fail" + }); + } +} + +Application.post("/students/update", MiddlewareAuth, PostDataProcess(), StudentUpdate); +/** + * @param {import("express").Request} request + * @param {import("express").Response} response + */ +async function StudentUpdate(request, response) +{ + const error = studentStoreValidation(request.body); + + if(error) + { + return response.status(400).json({ + status: "fail", + message: error.message + }); + } + + try{ + await updateStudent( + request.body.id, + request.session.user_id, + request.body.name, + request.body.surname, + request.body.studentno, + request.body.email, + request.body.gender, + request.body.birthdate || null, + request.body.description + ); + return response.status(200).json({ + status: "success" + }); + }catch(err){ + console.log(err) + return response.status(500).json({ + status: "fail" + }); + } +} + + +Application.post("/students/list", MiddlewareAuth, express.urlencoded({extended: true}), StudentList); +/** + * @param {import("express").Request} request + * @param {import("express").Response} response + */ +async function StudentList(request, response) +{ + let start = request.body.start ?? 0; + let length = request.body.length ?? 100; + let term = request.body.search?.value ?? null; + let count = await countStudents(request.session.user_id, term); + let data = await getStudents(request.session.user_id,start,length, term); + response.json({ + "draw": request.body.draw | 0, + "recordsTotal": count, + "recordsFiltered" : count, + "data": data + }); +} + + +function studentStoreValidation(body) +{ + const schema = Joi.object({ + id: Joi.number().min(1), + name: Joi.string().min(3).max(200).required().error(new Error('Adı en az 3 karakter ve zorunludur')), + surname: Joi.string().max(200).allow('', null).error(new Error('Soyadı formatı hatalı')), + studentno: Joi.string().max(200).allow('', null).error(new Error('Numara formatı hatalı')), + email: Joi.string().email().max(200).allow('', null).error(new Error('E-posta adresi geçersiz')), + birthdate: Joi.date().iso().allow('', null).error(new Error('Doğum tarihi geçersiz')), + gender: Joi.string().valid('male', 'female', 'Belirtilmemiş').allow('', null).error(new Error('Cinsiyet seçimi hatalı')), + description: Joi.string().allow('', null) + }); + const {error} = schema.validate(body); + return error; +} \ No newline at end of file diff --git a/core/postdata.js b/core/postdata.js index 2828a96..02c81b6 100644 --- a/core/postdata.js +++ b/core/postdata.js @@ -5,7 +5,10 @@ const storage = multer.memoryStorage(); const upload = multer({ storage: storage, - limits: { fileSize: 5 * 1024 * 1024 } // Örn: Max 5MB sınırı + limits: { + fileSize: 5 * 1024 * 1024, + fieldNameSize: 200 + } }); exports.PostDataProcess = () => upload.none(); \ No newline at end of file diff --git a/database/catalog.js b/database/catalog.js new file mode 100644 index 0000000..2b70101 --- /dev/null +++ b/database/catalog.js @@ -0,0 +1,72 @@ +const crypto = require("node:crypto"); +const DB = require("./connection"); + + +exports.createCatalog = createCatalog; +exports.getCatalogs = getCatalogs; +exports.countCatalogs = countCatalogs; +exports.updateCatalog = updateCatalog; + +async function createCatalog( + owner_id, + name, + score, + description +) +{ + const [id] = await DB.table("events") + .insert({ + owner_id, + name, + score, + description + }) + .returning("id"); + return id; +} +async function updateCatalog( + id, + owner_id, + name, + score, + description +) +{ + await DB.table("events") + .where("id",id) + .where("owner_id", owner_id) + .update({ + name, + score, + description + }); +} + + + + +async function getCatalogs( + owner_id, + offset, + limit, + searchTerm +) +{ + return await DB.table("events") + .where("owner_id",owner_id) + .whereNull("deleted_at") + .where("name","like",`%${searchTerm ?? ""}%`) + .limit(limit) + .offset(offset); +} +async function countCatalogs(owner_id, searchTerm) +{ + return ( + await DB.table("events") + .where("owner_id",owner_id) + .whereNull("deleted_at") + .where("name","like",`%${searchTerm ?? ""}%`) + .count("id as total") + .first() + ).total; +} \ No newline at end of file diff --git a/database/migrations/3_students.js b/database/migrations/3_students.js index c52a829..b280c2d 100644 --- a/database/migrations/3_students.js +++ b/database/migrations/3_students.js @@ -11,7 +11,7 @@ exports.up = function(knex) { table.string("studentno").nullable(); table.string("email").nullable(); table.string("gender").nullable(); - table.dateTime("bithdate").nullable(); + table.dateTime("birthdate").nullable(); table.text("description").nullable(); table.dateTime("created_at").defaultTo(knex.fn.now());; diff --git a/database/student.js b/database/student.js new file mode 100644 index 0000000..d84cd99 --- /dev/null +++ b/database/student.js @@ -0,0 +1,88 @@ +const crypto = require("node:crypto"); +const DB = require("./connection"); + + +exports.createStudent = createStudent; +exports.getStudents = getStudents; +exports.countStudents = countStudents; +exports.updateStudent = updateStudent; + +async function createStudent( + owner_id, + name, + surname, + studentno, + email, + gender, + birthdate, + description +) +{ + const [id] = await DB.table("students") + .insert({ + owner_id, + name, + surname, + studentno, + email, + gender, + birthdate, + description + }) + .returning("id"); + return id; +} +async function updateStudent( + id, + owner_id, + name, + surname, + studentno, + email, + gender, + birthdate, + description +) +{ + await DB.table("students") + .where("id",id) + .where("owner_id", owner_id) + .update({ + name, + surname, + studentno, + email, + gender, + birthdate, + description + }); +} + + + + +async function getStudents( + owner_id, + offset, + limit, + searchTerm +) +{ + return await DB.table("students") + .where("owner_id",owner_id) + .whereNull("deleted_at") + .where("name","like",`%${searchTerm ?? ""}%`) + .limit(limit) + .offset(offset); +} +async function countStudents(owner_id, searchTerm) +{ + return ( + await DB.table("students") + .where("owner_id",owner_id) + .whereNull("deleted_at") + .where("name","like",`%${searchTerm ?? ""}%`) + .count("id as total") + .first() + ).total; +} \ No newline at end of file diff --git a/index.js b/index.js index 5d2c494..8bfe85c 100644 --- a/index.js +++ b/index.js @@ -5,5 +5,6 @@ require("./core/static"); require("./database/session"); require("./controllers/auth"); -require("./controllers/backend"); +require("./controllers/students"); +require("./controllers/catalog"); require("./controllers/fallback"); \ No newline at end of file diff --git a/public/assets/css/style.css b/public/assets/css/style.css index 41b0273..85944b2 100644 --- a/public/assets/css/style.css +++ b/public/assets/css/style.css @@ -12108,19 +12108,6 @@ nav .app-logo .profile-menu-dropdown .dropdown-menu { -webkit-user-select: none; -moz-user-select: none; user-select: none; - transform: translate(32px, -70px) !important; -} -nav .app-logo .profile-menu-dropdown .dropdown-menu:before { - content: ""; - width: 15px; - height: 15px; - background: rgba(var(--white), 1); - border-left: 1px solid rgba(var(--secondary), 0.4); - border-bottom: 1px solid rgba(var(--secondary), 0.4); - position: absolute; - top: 73px; - left: -8px; - transform: rotate(45deg); } nav .app-nav { height: calc(100% - 162px); @@ -12665,7 +12652,7 @@ div .semi-nav ~ footer { width: 100%; height: 100%; transition: var(--app-transition); - box-shadow: var(--box-shadow); + /*box-shadow: var(--box-shadow);*/ overflow: hidden; } .app-wrapper .app-content .container-xxl { @@ -34725,9 +34712,9 @@ body.dark nav .app-logo .logo img { } } @media screen and (max-width: 576px) { - nav .app-logo .profile-menu-dropdown .dropdown-menu { + /*nav .app-logo .profile-menu-dropdown .dropdown-menu { transform: translate(-28px, -70px) !important; - } + }*/ nav .app-logo .profile-menu-dropdown .dropdown-menu:before { left: auto; right: -8px; diff --git a/views/panel.ejs b/views/panel.ejs deleted file mode 100644 index 495eaa8..0000000 --- a/views/panel.ejs +++ /dev/null @@ -1,15 +0,0 @@ -<%-include("./partials/header.ejs") %> - -
- <%-include("./partials/sidebar.ejs") %> -
- <%-include("./partials/navbar.ejs") %> -
-
-

Merhaba

-
-
- - - -<%-include("./partials/footer.ejs") %> \ No newline at end of file diff --git a/views/panel/catalogs.ejs b/views/panel/catalogs.ejs new file mode 100644 index 0000000..78b6c65 --- /dev/null +++ b/views/panel/catalogs.ejs @@ -0,0 +1,273 @@ +<%-include("../partials/header.ejs") %> +<%-include("../partials/sidebar.ejs") %> +
+ <%-include("../partials/navbar.ejs") %> + +
+
+ +
+
+

Puan Kataloğu

+

+ Öğrencileri değerlendireceğiniz kategorileri belirleyin +

+
+
+
+
+
+
+
+
+ Puan Kataloğu listesi +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + +<%-include("../partials/footer.ejs") %> \ No newline at end of file diff --git a/views/panel/panel.ejs b/views/panel/panel.ejs new file mode 100644 index 0000000..729ac6d --- /dev/null +++ b/views/panel/panel.ejs @@ -0,0 +1,12 @@ +<%-include("../partials/header.ejs") %> +<%-include("../partials/sidebar.ejs") %> +
+ <%-include("../partials/navbar.ejs") %> +
+

Merhaba

+
+
+ + + +<%-include("../partials/footer.ejs") %> \ No newline at end of file diff --git a/views/panel/students.ejs b/views/panel/students.ejs new file mode 100644 index 0000000..41c8451 --- /dev/null +++ b/views/panel/students.ejs @@ -0,0 +1,297 @@ +<%-include("../partials/header.ejs") %> +<%-include("../partials/sidebar.ejs") %> +
+ <%-include("../partials/navbar.ejs") %> + +
+
+ +
+
+

Sisteme Kayıtlı Öğrenciler

+

+ Öğrenciler ekleyebilir, düzenleyebilir ve silebilirsiniz +

+
+
+
+
+
+
+
+
+ Öğrenciler +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + +<%-include("../partials/footer.ejs") %> \ No newline at end of file diff --git a/views/partials/footer.ejs b/views/partials/footer.ejs index 8f2857f..39959ec 100644 --- a/views/partials/footer.ejs +++ b/views/partials/footer.ejs @@ -5,14 +5,13 @@
- - - + + \ No newline at end of file diff --git a/views/partials/header.ejs b/views/partials/header.ejs index 920b50d..cfe297b 100644 --- a/views/partials/header.ejs +++ b/views/partials/header.ejs @@ -20,6 +20,8 @@ + +
diff --git a/views/partials/sidebar.ejs b/views/partials/sidebar.ejs index cd895f7..79e871e 100644 --- a/views/partials/sidebar.ejs +++ b/views/partials/sidebar.ejs @@ -1,7 +1,10 @@