fix: Mal Sorumlusu giriş sorunu çözüldü
- Mal sorumlusu kullanıcılarının giriş yapamama sorunu düzeltildi - Internal API fetch hatası yerine paylaşılan veri modülü kullanıldı - src/lib/data/goodsManagers.js merkezi veri yönetim modülü eklendi - Login API'de server-side HTTP çağrıları direct function calls ile değiştirildi - Tüm goods-managers API endpoint'leri yeni modülü kullanacak şekilde güncellendi - Performans artışı ve hata yönetimi iyileştirildi 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
254
src/lib/data/goodsManagers.js
Normal file
254
src/lib/data/goodsManagers.js
Normal file
@@ -0,0 +1,254 @@
|
|||||||
|
// Mal sorumluları veritabanı modülü
|
||||||
|
// Bu modül tüm API endpoint'leri tarafından paylaşılır
|
||||||
|
|
||||||
|
// Geçici veritabanı simülasyonu
|
||||||
|
let goodsManagers = [
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
full_name: 'Ali Veli',
|
||||||
|
rank: 'Binbaşı',
|
||||||
|
registration_number: 'GM001',
|
||||||
|
tc_kimlik: '12345678901',
|
||||||
|
phone: '05321234567',
|
||||||
|
email: 'ali.veli@mil.tr',
|
||||||
|
username: 'goods',
|
||||||
|
password: 'goods123',
|
||||||
|
is_active: true,
|
||||||
|
created_at: new Date().toISOString()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
full_name: 'İbrahim Kara',
|
||||||
|
rank: 'Yüzbaşı',
|
||||||
|
registration_number: 'GM002',
|
||||||
|
tc_kimlik: '98765432101',
|
||||||
|
phone: '05339876543',
|
||||||
|
email: 'ibrahim.kara@mil.tr',
|
||||||
|
username: 'ibrahim_kara',
|
||||||
|
password: 'kara123',
|
||||||
|
is_active: true,
|
||||||
|
created_at: new Date().toISOString()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 6,
|
||||||
|
full_name: 'Mehmet Fatih Aköz',
|
||||||
|
rank: 'U/B Asb.Kd.Üçvş.',
|
||||||
|
registration_number: '2022/21345',
|
||||||
|
tc_kimlik: '12312321312',
|
||||||
|
phone: '05537746067',
|
||||||
|
email: 'ibo@gmail.com',
|
||||||
|
username: 'fatih',
|
||||||
|
password: 'fat123',
|
||||||
|
is_active: true,
|
||||||
|
created_at: '2025-11-06T15:51:54.907Z'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
let nextId = 7;
|
||||||
|
|
||||||
|
// Mal sorumlularını getir
|
||||||
|
export function getGoodsManagers() {
|
||||||
|
return goodsManagers;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mal sorumlusu bul (username ile)
|
||||||
|
export function findGoodsManagerByUsername(username) {
|
||||||
|
if (!username) return null;
|
||||||
|
|
||||||
|
return goodsManagers.find(gm =>
|
||||||
|
gm.username &&
|
||||||
|
gm.username.toLowerCase() === username.toLowerCase() &&
|
||||||
|
gm.is_active
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mal sorumlusu bul (ID ile)
|
||||||
|
export function findGoodsManagerById(id) {
|
||||||
|
return goodsManagers.find(gm => gm.id === parseInt(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Yeni mal sorumlusu ekle
|
||||||
|
export function addGoodsManager(managerData) {
|
||||||
|
const {
|
||||||
|
full_name,
|
||||||
|
rank,
|
||||||
|
registration_number,
|
||||||
|
tc_kimlik,
|
||||||
|
phone,
|
||||||
|
email,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
is_active = true
|
||||||
|
} = managerData;
|
||||||
|
|
||||||
|
// Validasyonlar
|
||||||
|
if (!full_name || !rank || !registration_number || !tc_kimlik ||
|
||||||
|
!phone || !email || !username || !password) {
|
||||||
|
throw new Error('Tüm alanlar zorunludur.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^[0-9]{11}$/.test(tc_kimlik)) {
|
||||||
|
throw new Error('TC Kimlik numarası 11 haneli olmalıdır.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
|
if (!emailRegex.test(email)) {
|
||||||
|
throw new Error('Geçersiz e-posta formatı.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tekrar kontrolü
|
||||||
|
const existingByReg = goodsManagers.find(m =>
|
||||||
|
m.registration_number.toLowerCase() === registration_number.toLowerCase()
|
||||||
|
);
|
||||||
|
if (existingByReg) {
|
||||||
|
throw new Error('Bu sicil numarası zaten kayıtlı.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingByTC = goodsManagers.find(m => m.tc_kimlik === tc_kimlik);
|
||||||
|
if (existingByTC) {
|
||||||
|
throw new Error('Bu TC Kimlik numarası zaten kayıtlı.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingByEmail = goodsManagers.find(m =>
|
||||||
|
m.email.toLowerCase() === email.toLowerCase()
|
||||||
|
);
|
||||||
|
if (existingByEmail) {
|
||||||
|
throw new Error('Bu e-posta adresi zaten kayıtlı.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingByUsername = goodsManagers.find(m =>
|
||||||
|
m.username.toLowerCase() === username.toLowerCase()
|
||||||
|
);
|
||||||
|
if (existingByUsername) {
|
||||||
|
throw new Error('Bu kullanıcı adı zaten kullanılıyor.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^[a-zA-Z0-9]{3,20}$/.test(username)) {
|
||||||
|
throw new Error('Kullanıcı adı 3-20 karakter arası olmalı ve sadece harf ve rakam içermelidir.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password.length < 6) {
|
||||||
|
throw new Error('Şifre en az 6 karakter olmalıdır.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Yeni mal sorumlusu oluştur
|
||||||
|
const newManager = {
|
||||||
|
id: nextId++,
|
||||||
|
full_name: full_name.trim(),
|
||||||
|
rank: rank.trim(),
|
||||||
|
registration_number: registration_number.trim().toUpperCase(),
|
||||||
|
tc_kimlik: tc_kimlik.trim(),
|
||||||
|
phone: phone.trim(),
|
||||||
|
email: email.trim().toLowerCase(),
|
||||||
|
username: username.trim().toLowerCase(),
|
||||||
|
password: password.trim(), // Gerçek uygulamada hash'lenmelidir
|
||||||
|
is_active: Boolean(is_active),
|
||||||
|
created_at: new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
goodsManagers.push(newManager);
|
||||||
|
return newManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mal sorumlusu güncelle
|
||||||
|
export function updateGoodsManager(id, updateData) {
|
||||||
|
const managerIndex = goodsManagers.findIndex(m => m.id === parseInt(id));
|
||||||
|
if (managerIndex === -1) {
|
||||||
|
throw new Error('Mal sorumlusu bulunamadı.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
full_name,
|
||||||
|
rank,
|
||||||
|
registration_number,
|
||||||
|
tc_kimlik,
|
||||||
|
phone,
|
||||||
|
email,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
is_active
|
||||||
|
} = updateData;
|
||||||
|
|
||||||
|
// Validasyonlar
|
||||||
|
if (!id || !full_name || !rank || !registration_number || !tc_kimlik ||
|
||||||
|
!phone || !email || !username) {
|
||||||
|
throw new Error('Tüm alanlar zorunludur.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^[0-9]{11}$/.test(tc_kimlik)) {
|
||||||
|
throw new Error('TC Kimlik numarası 11 haneli olmalıdır.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
|
if (!emailRegex.test(email)) {
|
||||||
|
throw new Error('Geçersiz e-posta formatı.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tekrar kontrolü (diğer managerlar için)
|
||||||
|
const existingByReg = goodsManagers.find(m =>
|
||||||
|
m.id !== parseInt(id) && m.registration_number.toLowerCase() === registration_number.toLowerCase()
|
||||||
|
);
|
||||||
|
if (existingByReg) {
|
||||||
|
throw new Error('Bu sicil numarası başka bir mal sorumlusunda kullanılıyor.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingByTC = goodsManagers.find(m =>
|
||||||
|
m.id !== parseInt(id) && m.tc_kimlik === tc_kimlik
|
||||||
|
);
|
||||||
|
if (existingByTC) {
|
||||||
|
throw new Error('Bu TC Kimlik numarası başka bir mal sorumlusunda kullanılıyor.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingByEmail = goodsManagers.find(m =>
|
||||||
|
m.id !== parseInt(id) && m.email.toLowerCase() === email.toLowerCase()
|
||||||
|
);
|
||||||
|
if (existingByEmail) {
|
||||||
|
throw new Error('Bu e-posta adresi başka bir mal sorumlusunda kullanılıyor.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingByUsername = goodsManagers.find(m =>
|
||||||
|
m.id !== parseInt(id) && m.username.toLowerCase() === username.toLowerCase()
|
||||||
|
);
|
||||||
|
if (existingByUsername) {
|
||||||
|
throw new Error('Bu kullanıcı adı başka bir mal sorumlusunda kullanılıyor.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^[a-zA-Z0-9]{3,20}$/.test(username)) {
|
||||||
|
throw new Error('Kullanıcı adı 3-20 karakter arası olmalı ve sadece harf ve rakam içermelidir.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password && password.trim().length > 0 && password.trim().length < 6) {
|
||||||
|
throw new Error('Şifre en az 6 karakter olmalıdır.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Manager güncelle
|
||||||
|
goodsManagers[managerIndex] = {
|
||||||
|
...goodsManagers[managerIndex],
|
||||||
|
full_name: full_name.trim(),
|
||||||
|
rank: rank.trim(),
|
||||||
|
registration_number: registration_number.trim().toUpperCase(),
|
||||||
|
tc_kimlik: tc_kimlik.trim(),
|
||||||
|
phone: phone.trim(),
|
||||||
|
email: email.trim().toLowerCase(),
|
||||||
|
username: username.trim().toLowerCase(),
|
||||||
|
is_active: Boolean(is_active)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Eğer yeni şifre verildiyse güncelle
|
||||||
|
if (password && password.trim().length > 0) {
|
||||||
|
goodsManagers[managerIndex].password = password.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
return goodsManagers[managerIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mal sorumlusu sil
|
||||||
|
export function deleteGoodsManager(id) {
|
||||||
|
const managerIndex = goodsManagers.findIndex(m => m.id === parseInt(id));
|
||||||
|
if (managerIndex === -1) {
|
||||||
|
throw new Error('Mal sorumlusu bulunamadı.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const deletedManager = goodsManagers.splice(managerIndex, 1)[0];
|
||||||
|
return deletedManager;
|
||||||
|
}
|
||||||
@@ -1,41 +1,20 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
|
import {
|
||||||
// Geçici veritabanı simülasyonu
|
getGoodsManagers,
|
||||||
let goodsManagers = [
|
addGoodsManager,
|
||||||
{
|
updateGoodsManager,
|
||||||
id: 3,
|
deleteGoodsManager
|
||||||
full_name: 'Ali Veli',
|
} from '$lib/data/goodsManagers.js';
|
||||||
rank: 'Binbaşı',
|
|
||||||
registration_number: 'GM001',
|
|
||||||
tc_kimlik: '12345678901',
|
|
||||||
phone: '05321234567',
|
|
||||||
email: 'ali.veli@mil.tr',
|
|
||||||
username: 'goods',
|
|
||||||
password: 'goods123',
|
|
||||||
is_active: true,
|
|
||||||
created_at: new Date().toISOString()
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
full_name: 'İbrahim Kara',
|
|
||||||
rank: 'Yüzbaşı',
|
|
||||||
registration_number: 'GM002',
|
|
||||||
tc_kimlik: '98765432101',
|
|
||||||
phone: '05339876543',
|
|
||||||
email: 'ibrahim.kara@mil.tr',
|
|
||||||
username: 'ibrahim_kara',
|
|
||||||
password: 'kara123',
|
|
||||||
is_active: true,
|
|
||||||
created_at: new Date().toISOString()
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
let nextId = 5;
|
|
||||||
|
|
||||||
// GET - Tüm mal sorumlularını listele
|
// GET - Tüm mal sorumlularını listele
|
||||||
export async function GET({ request }) {
|
export async function GET({ request }) {
|
||||||
// Yetki kontrolü (temporary - will be implemented with proper session)
|
// Yetki kontrolü (temporary - will be implemented with proper session)
|
||||||
return json({ goodsManagers });
|
try {
|
||||||
|
const goodsManagers = getGoodsManagers();
|
||||||
|
return json({ goodsManagers });
|
||||||
|
} catch (error) {
|
||||||
|
return json({ message: 'Mal sorumluları alınırken hata oluştu.' }, { status: 500 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST - Yeni mal sorumlusu ekle
|
// POST - Yeni mal sorumlusu ekle
|
||||||
@@ -55,74 +34,17 @@ export async function POST({ request }) {
|
|||||||
is_active = true
|
is_active = true
|
||||||
} = await request.json();
|
} = await request.json();
|
||||||
|
|
||||||
// Validasyon
|
const newManager = addGoodsManager({
|
||||||
if (!full_name || !rank || !registration_number || !tc_kimlik || !phone || !email || !username || !password) {
|
full_name,
|
||||||
return json({ message: 'Tüm alanlar zorunludur.' }, { status: 400 });
|
rank,
|
||||||
}
|
registration_number,
|
||||||
|
tc_kimlik,
|
||||||
// TC Kimlik numarası validasyonu
|
phone,
|
||||||
if (!/^[0-9]{11}$/.test(tc_kimlik)) {
|
email,
|
||||||
return json({ message: 'TC Kimlik numarası 11 haneli olmalıdır.' }, { status: 400 });
|
username,
|
||||||
}
|
password,
|
||||||
|
is_active
|
||||||
// Email format validasyonu
|
});
|
||||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
||||||
if (!emailRegex.test(email)) {
|
|
||||||
return json({ message: 'Geçersiz e-posta formatı.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sicil numarası tekrar kontrolü
|
|
||||||
const existingManager = goodsManagers.find(m =>
|
|
||||||
m.registration_number.toLowerCase() === registration_number.toLowerCase()
|
|
||||||
);
|
|
||||||
if (existingManager) {
|
|
||||||
return json({ message: 'Bu sicil numarası zaten kayıtlı.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// TC Kimlik numarası tekrar kontrolü
|
|
||||||
const existingTC = goodsManagers.find(m => m.tc_kimlik === tc_kimlik);
|
|
||||||
if (existingTC) {
|
|
||||||
return json({ message: 'Bu TC Kimlik numarası zaten kayıtlı.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Email tekrar kontrolü
|
|
||||||
const existingEmail = goodsManagers.find(m => m.email.toLowerCase() === email.toLowerCase());
|
|
||||||
if (existingEmail) {
|
|
||||||
return json({ message: 'Bu e-posta adresi zaten kayıtlı.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kullanıcı adı tekrar kontrolü
|
|
||||||
const existingUsername = goodsManagers.find(m => m.username.toLowerCase() === username.toLowerCase());
|
|
||||||
if (existingUsername) {
|
|
||||||
return json({ message: 'Bu kullanıcı adı zaten kullanılıyor.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kullanıcı adı format kontrolü (en az 3 karakter, sadece harf ve rakam)
|
|
||||||
if (!/^[a-zA-Z0-9]{3,20}$/.test(username)) {
|
|
||||||
return json({ message: 'Kullanıcı adı 3-20 karakter arası olmalı ve sadece harf ve rakam içermelidir.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Şifre en az 6 karakter olmalı
|
|
||||||
if (password.length < 6) {
|
|
||||||
return json({ message: 'Şifre en az 6 karakter olmalıdır.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Yeni mal sorumlusu oluştur
|
|
||||||
const newManager = {
|
|
||||||
id: nextId++,
|
|
||||||
full_name: full_name.trim(),
|
|
||||||
rank: rank.trim(),
|
|
||||||
registration_number: registration_number.trim().toUpperCase(),
|
|
||||||
tc_kimlik: tc_kimlik.trim(),
|
|
||||||
phone: phone.trim(),
|
|
||||||
email: email.trim().toLowerCase(),
|
|
||||||
username: username.trim().toLowerCase(),
|
|
||||||
password: password.trim(), // Gerçek uygulamada hash'lenmelidir
|
|
||||||
is_active: Boolean(is_active),
|
|
||||||
created_at: new Date().toISOString()
|
|
||||||
};
|
|
||||||
|
|
||||||
goodsManagers.push(newManager);
|
|
||||||
|
|
||||||
return json({
|
return json({
|
||||||
message: 'Mal sorumlusu başarıyla eklendi.',
|
message: 'Mal sorumlusu başarıyla eklendi.',
|
||||||
@@ -130,6 +52,12 @@ export async function POST({ request }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (error.message.includes('zorunludur') ||
|
||||||
|
error.message.includes('zaten kayıtlı') ||
|
||||||
|
error.message.includes('Geçersiz') ||
|
||||||
|
error.message.includes('karakter')) {
|
||||||
|
return json({ message: error.message }, { status: 400 });
|
||||||
|
}
|
||||||
return json({ message: 'Sunucu hatası.' }, { status: 500 });
|
return json({ message: 'Sunucu hatası.' }, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,90 +80,31 @@ export async function PUT({ request }) {
|
|||||||
is_active
|
is_active
|
||||||
} = await request.json();
|
} = await request.json();
|
||||||
|
|
||||||
// Validasyon
|
const updatedManager = updateGoodsManager(id, {
|
||||||
if (!id || !full_name || !rank || !registration_number || !tc_kimlik || !phone || !email || !username) {
|
full_name,
|
||||||
return json({ message: 'Tüm alanlar zorunludur.' }, { status: 400 });
|
rank,
|
||||||
}
|
registration_number,
|
||||||
|
tc_kimlik,
|
||||||
// TC Kimlik numarası validasyonu
|
phone,
|
||||||
if (!/^[0-9]{11}$/.test(tc_kimlik)) {
|
email,
|
||||||
return json({ message: 'TC Kimlik numarası 11 haneli olmalıdır.' }, { status: 400 });
|
username,
|
||||||
}
|
password,
|
||||||
|
is_active
|
||||||
// Email format validasyonu
|
});
|
||||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
||||||
if (!emailRegex.test(email)) {
|
|
||||||
return json({ message: 'Geçersiz e-posta formatı.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Manager bul
|
|
||||||
const managerIndex = goodsManagers.findIndex(m => m.id === parseInt(id));
|
|
||||||
if (managerIndex === -1) {
|
|
||||||
return json({ message: 'Mal sorumlusu bulunamadı.' }, { status: 404 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sicil numarası tekrar kontrolü (diğer managerlar için)
|
|
||||||
const existingManager = goodsManagers.find(m =>
|
|
||||||
m.id !== parseInt(id) && m.registration_number.toLowerCase() === registration_number.toLowerCase()
|
|
||||||
);
|
|
||||||
if (existingManager) {
|
|
||||||
return json({ message: 'Bu sicil numarası başka bir mal sorumlusunda kullanılıyor.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// TC Kimlik numarası tekrar kontrolü (diğer managerlar için)
|
|
||||||
const existingTC = goodsManagers.find(m => m.id !== parseInt(id) && m.tc_kimlik === tc_kimlik);
|
|
||||||
if (existingTC) {
|
|
||||||
return json({ message: 'Bu TC Kimlik numarası başka bir mal sorumlusunda kullanılıyor.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Email tekrar kontrolü (diğer managerlar için)
|
|
||||||
const existingEmail = goodsManagers.find(m => m.id !== parseInt(id) && m.email.toLowerCase() === email.toLowerCase());
|
|
||||||
if (existingEmail) {
|
|
||||||
return json({ message: 'Bu e-posta adresi başka bir mal sorumlusunda kullanılıyor.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kullanıcı adı tekrar kontrolü (diğer managerlar için)
|
|
||||||
const existingUsername = goodsManagers.find(m => m.id !== parseInt(id) && m.username.toLowerCase() === username.toLowerCase());
|
|
||||||
if (existingUsername) {
|
|
||||||
return json({ message: 'Bu kullanıcı adı başka bir mal sorumlusunda kullanılıyor.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kullanıcı adı format kontrolü
|
|
||||||
if (!/^[a-zA-Z0-9]{3,20}$/.test(username)) {
|
|
||||||
return json({ message: 'Kullanıcı adı 3-20 karakter arası olmalı ve sadece harf ve rakam içermelidir.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Şifre güncelleniyor mu kontrol et (boş değilse)
|
|
||||||
if (password && password.trim().length > 0) {
|
|
||||||
if (password.trim().length < 6) {
|
|
||||||
return json({ message: 'Şifre en az 6 karakter olmalıdır.' }, { status: 400 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Manager güncelle
|
|
||||||
goodsManagers[managerIndex] = {
|
|
||||||
...goodsManagers[managerIndex],
|
|
||||||
full_name: full_name.trim(),
|
|
||||||
rank: rank.trim(),
|
|
||||||
registration_number: registration_number.trim().toUpperCase(),
|
|
||||||
tc_kimlik: tc_kimlik.trim(),
|
|
||||||
phone: phone.trim(),
|
|
||||||
email: email.trim().toLowerCase(),
|
|
||||||
username: username.trim().toLowerCase(),
|
|
||||||
is_active: Boolean(is_active)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Eğer yeni şifre verildiyse güncelle
|
|
||||||
if (password && password.trim().length > 0) {
|
|
||||||
goodsManagers[managerIndex].password = password.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
return json({
|
return json({
|
||||||
message: 'Mal sorumlusu başarıyla güncellendi.',
|
message: 'Mal sorumlusu başarıyla güncellendi.',
|
||||||
goodsManager: goodsManagers[managerIndex]
|
goodsManager: updatedManager
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (error.message.includes('zorunludur') ||
|
||||||
|
error.message.includes('bulunamadı') ||
|
||||||
|
error.message.includes('zaten kayıtlı') ||
|
||||||
|
error.message.includes('Geçersiz') ||
|
||||||
|
error.message.includes('karakter')) {
|
||||||
|
return json({ message: error.message }, { status: error.message.includes('bulunamadı') ? 404 : 400 });
|
||||||
|
}
|
||||||
return json({ message: 'Sunucu hatası.' }, { status: 500 });
|
return json({ message: 'Sunucu hatası.' }, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,14 +120,7 @@ export async function DELETE({ request }) {
|
|||||||
return json({ message: 'Mal sorumlusu ID zorunludur.' }, { status: 400 });
|
return json({ message: 'Mal sorumlusu ID zorunludur.' }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manager bul
|
const deletedManager = deleteGoodsManager(id);
|
||||||
const managerIndex = goodsManagers.findIndex(m => m.id === parseInt(id));
|
|
||||||
if (managerIndex === -1) {
|
|
||||||
return json({ message: 'Mal sorumlusu bulunamadı.' }, { status: 404 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Manager sil
|
|
||||||
const deletedManager = goodsManagers.splice(managerIndex, 1)[0];
|
|
||||||
|
|
||||||
return json({
|
return json({
|
||||||
message: 'Mal sorumlusu başarıyla silindi.',
|
message: 'Mal sorumlusu başarıyla silindi.',
|
||||||
@@ -266,6 +128,9 @@ export async function DELETE({ request }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (error.message.includes('bulunamadı')) {
|
||||||
|
return json({ message: error.message }, { status: 404 });
|
||||||
|
}
|
||||||
return json({ message: 'Sunucu hatası.' }, { status: 500 });
|
return json({ message: 'Sunucu hatası.' }, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
|
import { findGoodsManagerByUsername } from '$lib/data/goodsManagers.js';
|
||||||
|
|
||||||
export async function POST({ request }) {
|
export async function POST({ request }) {
|
||||||
const { username, password } = await request.json();
|
const { username, password } = await request.json();
|
||||||
@@ -39,35 +40,22 @@ export async function POST({ request }) {
|
|||||||
|
|
||||||
// Mal sorumluları arasında ara
|
// Mal sorumluları arasında ara
|
||||||
try {
|
try {
|
||||||
const baseUrl = request.url.split('/api/')[0];
|
const goodsManager = findGoodsManagerByUsername(username);
|
||||||
const goodsManagersRes = await fetch(`${baseUrl}/api/goods-managers`).catch(() => null);
|
|
||||||
|
if (goodsManager && goodsManager.password === password) {
|
||||||
if (goodsManagersRes) {
|
return json({
|
||||||
const goodsData = await goodsManagersRes.json().catch(() => ({ goodsManagers: [] }));
|
message: 'Giriş başarılı.',
|
||||||
const goodsManagers = goodsData.goodsManagers || [];
|
user: {
|
||||||
|
id: goodsManager.id,
|
||||||
const goodsManager = goodsManagers.find(gm =>
|
username: goodsManager.username,
|
||||||
gm.username &&
|
role: 'goods_manager',
|
||||||
gm.username.toLowerCase() === username.toLowerCase() &&
|
full_name: goodsManager.full_name,
|
||||||
gm.is_active &&
|
rank: goodsManager.rank
|
||||||
gm.password === password
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
if (goodsManager) {
|
|
||||||
return json({
|
|
||||||
message: 'Giriş başarılı.',
|
|
||||||
user: {
|
|
||||||
id: goodsManager.id,
|
|
||||||
username: goodsManager.username,
|
|
||||||
role: 'goods_manager',
|
|
||||||
full_name: goodsManager.full_name,
|
|
||||||
rank: goodsManager.rank
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Goods managers fetch error:', err);
|
console.error('Goods manager lookup error:', err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kullanıcı bulunamadı
|
// Kullanıcı bulunamadı
|
||||||
|
|||||||
Reference in New Issue
Block a user