Yakıt Personeli ekranı fixed
This commit is contained in:
210
src/server.js
210
src/server.js
@@ -113,6 +113,32 @@ let vehicles = [
|
||||
|
||||
let nextVehicleId = 4;
|
||||
|
||||
// Fuel Personnel veritabanı
|
||||
let fuelPersonnel = [
|
||||
{
|
||||
id: 1,
|
||||
full_name: 'Ahmet Demir',
|
||||
rank: 'Üsteğmen',
|
||||
registration_number: '111222',
|
||||
tc_kimlik: '11111111111',
|
||||
phone: '05321112233',
|
||||
is_active: true,
|
||||
created_at: new Date().toISOString()
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
full_name: 'Mustafa Çelik',
|
||||
rank: 'Astsubay',
|
||||
registration_number: '333444',
|
||||
tc_kimlik: '22222222222',
|
||||
phone: '05334455566',
|
||||
is_active: true,
|
||||
created_at: new Date().toISOString()
|
||||
}
|
||||
];
|
||||
|
||||
let nextFuelPersonnelId = 3;
|
||||
|
||||
const app = express();
|
||||
const server = createServer(app);
|
||||
const io = new Server(server, {
|
||||
@@ -657,31 +683,171 @@ app.delete('/api/goods-managers', async (req, res) => {
|
||||
// GET - Tüm yakıt personelini listele
|
||||
app.get('/api/fuel-personnel', (req, res) => {
|
||||
// Yetki kontrolü (temporary - will be implemented with proper session)
|
||||
const fuelPersonnel = [
|
||||
{
|
||||
id: 1,
|
||||
full_name: 'Ahmet Demir',
|
||||
rank: 'Üsteğmen',
|
||||
registration_number: '111222',
|
||||
tc_kimlik: '11111111111',
|
||||
phone: '05321112233',
|
||||
is_active: true,
|
||||
created_at: new Date().toISOString()
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
full_name: 'Mustafa Çelik',
|
||||
rank: 'Astsubay',
|
||||
registration_number: '333444',
|
||||
tc_kimlik: '22222222222',
|
||||
phone: '05334455566',
|
||||
is_active: true,
|
||||
created_at: new Date().toISOString()
|
||||
}
|
||||
];
|
||||
res.json({ fuelPersonnel });
|
||||
});
|
||||
|
||||
// POST - Yeni yakıt personeli ekle
|
||||
app.post('/api/fuel-personnel', (req, res) => {
|
||||
// Yetki kontrolü (temporary - will be implemented with proper session)
|
||||
|
||||
try {
|
||||
const {
|
||||
full_name,
|
||||
rank,
|
||||
registration_number,
|
||||
tc_kimlik,
|
||||
phone,
|
||||
is_active = true
|
||||
} = req.body;
|
||||
|
||||
// Validasyon
|
||||
if (!full_name || !rank || !registration_number || !tc_kimlik || !phone) {
|
||||
return res.status(400).json({ message: 'Tüm alanlar zorunludur.' });
|
||||
}
|
||||
|
||||
// TC Kimlik numarası validasyonu
|
||||
if (!/^[0-9]{11}$/.test(tc_kimlik)) {
|
||||
return res.status(400).json({ message: 'TC Kimlik numarası 11 haneli olmalıdır.' });
|
||||
}
|
||||
|
||||
// Sicil numarası tekrar kontrolü
|
||||
const existingPersonnel = fuelPersonnel.find(p =>
|
||||
p.registration_number === registration_number
|
||||
);
|
||||
if (existingPersonnel) {
|
||||
return res.status(400).json({ message: 'Bu sicil numarası zaten kayıtlı.' });
|
||||
}
|
||||
|
||||
// TC Kimlik numarası tekrar kontrolü
|
||||
const existingTc = fuelPersonnel.find(p =>
|
||||
p.tc_kimlik === tc_kimlik
|
||||
);
|
||||
if (existingTc) {
|
||||
return res.status(400).json({ message: 'Bu TC Kimlik numarası zaten kayıtlı.' });
|
||||
}
|
||||
|
||||
// Yeni personel oluştur
|
||||
const newPersonnel = {
|
||||
id: nextFuelPersonnelId++,
|
||||
full_name: full_name.trim(),
|
||||
rank: rank.trim(),
|
||||
registration_number: registration_number.trim(),
|
||||
tc_kimlik: tc_kimlik.trim(),
|
||||
phone: phone.trim(),
|
||||
is_active: Boolean(is_active),
|
||||
created_at: new Date().toISOString()
|
||||
};
|
||||
|
||||
fuelPersonnel.push(newPersonnel);
|
||||
|
||||
res.json({
|
||||
message: 'Personel başarıyla eklendi.',
|
||||
fuelPersonnel: newPersonnel
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'Sunucu hatası.' });
|
||||
}
|
||||
});
|
||||
|
||||
// PUT - Yakıt personeli güncelle
|
||||
app.put('/api/fuel-personnel', (req, res) => {
|
||||
// Yetki kontrolü (temporary - will be implemented with proper session)
|
||||
|
||||
try {
|
||||
const {
|
||||
id,
|
||||
full_name,
|
||||
rank,
|
||||
registration_number,
|
||||
tc_kimlik,
|
||||
phone,
|
||||
is_active
|
||||
} = req.body;
|
||||
|
||||
// Validasyon
|
||||
if (!id || !full_name || !rank || !registration_number || !tc_kimlik || !phone) {
|
||||
return res.status(400).json({ message: 'Tüm alanlar zorunludur.' });
|
||||
}
|
||||
|
||||
// TC Kimlik numarası validasyonu
|
||||
if (!/^[0-9]{11}$/.test(tc_kimlik)) {
|
||||
return res.status(400).json({ message: 'TC Kimlik numarası 11 haneli olmalıdır.' });
|
||||
}
|
||||
|
||||
// Personel bul
|
||||
const personnelIndex = fuelPersonnel.findIndex(p => p.id === parseInt(id));
|
||||
if (personnelIndex === -1) {
|
||||
return res.status(404).json({ message: 'Personel bulunamadı.' });
|
||||
}
|
||||
|
||||
// Sicil numarası tekrar kontrolü (başka personel için)
|
||||
const existingRegNumber = fuelPersonnel.find(p =>
|
||||
p.id !== parseInt(id) && p.registration_number === registration_number
|
||||
);
|
||||
if (existingRegNumber) {
|
||||
return res.status(400).json({ message: 'Bu sicil numarası başka bir personelde kayıtlı.' });
|
||||
}
|
||||
|
||||
// TC Kimlik numarası tekrar kontrolü (başka personel için)
|
||||
const existingTc = fuelPersonnel.find(p =>
|
||||
p.id !== parseInt(id) && p.tc_kimlik === tc_kimlik
|
||||
);
|
||||
if (existingTc) {
|
||||
return res.status(400).json({ message: 'Bu TC Kimlik numarası başka bir personelde kayıtlı.' });
|
||||
}
|
||||
|
||||
// Personeli güncelle
|
||||
fuelPersonnel[personnelIndex] = {
|
||||
...fuelPersonnel[personnelIndex],
|
||||
full_name: full_name.trim(),
|
||||
rank: rank.trim(),
|
||||
registration_number: registration_number.trim(),
|
||||
tc_kimlik: tc_kimlik.trim(),
|
||||
phone: phone.trim(),
|
||||
is_active: Boolean(is_active)
|
||||
};
|
||||
|
||||
res.json({
|
||||
message: 'Personel başarıyla güncellendi.',
|
||||
fuelPersonnel: fuelPersonnel[personnelIndex]
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'Sunucu hatası.' });
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE - Yakıt personeli sil
|
||||
app.delete('/api/fuel-personnel', (req, res) => {
|
||||
// Yetki kontrolü (temporary - will be implemented with proper session)
|
||||
|
||||
try {
|
||||
const { id } = req.body;
|
||||
|
||||
if (!id) {
|
||||
return res.status(400).json({ message: 'Personel ID zorunludur.' });
|
||||
}
|
||||
|
||||
// Personel bul
|
||||
const personnelIndex = fuelPersonnel.findIndex(p => p.id === parseInt(id));
|
||||
if (personnelIndex === -1) {
|
||||
return res.status(404).json({ message: 'Personel bulunamadı.' });
|
||||
}
|
||||
|
||||
// Personel sil
|
||||
const deletedPersonnel = fuelPersonnel.splice(personnelIndex, 1)[0];
|
||||
|
||||
res.json({
|
||||
message: 'Personel başarıyla silindi.',
|
||||
fuelPersonnel: deletedPersonnel
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'Sunucu hatası.' });
|
||||
}
|
||||
});
|
||||
|
||||
// Fuel Slips API endpoint'leri
|
||||
|
||||
// GET - Yakıt fişlerini listele
|
||||
|
||||
Reference in New Issue
Block a user