обновление от 2025-10-08 для ветки 19SEP
This commit is contained in:
163
server.js
163
server.js
@@ -997,7 +997,10 @@ app.get('/api/cities/:cityId/objects', authenticate, async (req, res) => {
|
||||
COALESCE(scale_y, 1) AS scale_y,
|
||||
COALESCE(scale_z, 1) AS scale_z,
|
||||
organization_id,
|
||||
COALESCE(collidable, true) AS collidable,
|
||||
COALESCE(rent, 0) AS rent,
|
||||
COALESCE(tax, 0) AS tax,
|
||||
COALESCE(collidable, false) AS collidable,
|
||||
COALESCE(interior_id, 101) AS interior_id,
|
||||
COALESCE(textures, '-') AS textures
|
||||
FROM city_objects
|
||||
WHERE city_id = $1
|
||||
@@ -2142,6 +2145,164 @@ app.get('/api/cities', authenticate, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Сохранить/обновить объект города в БД
|
||||
app.post('/api/save-object', authenticate, async (req, res) => {
|
||||
try {
|
||||
const {
|
||||
id,
|
||||
city_id,
|
||||
name,
|
||||
model_url,
|
||||
pos_x,
|
||||
pos_y,
|
||||
pos_z,
|
||||
rot_x,
|
||||
rot_y,
|
||||
rot_z,
|
||||
scale_x,
|
||||
scale_y,
|
||||
scale_z,
|
||||
organization_id = 2,
|
||||
rent = 0,
|
||||
tax = 0,
|
||||
collidable = false,
|
||||
interior_id = 101,
|
||||
textures = '-'
|
||||
} = req.body;
|
||||
|
||||
if (!city_id || !model_url) {
|
||||
return res.status(400).json({ error: 'city_id и model_url обязательны' });
|
||||
}
|
||||
|
||||
let result;
|
||||
if (id && id !== null && id !== undefined) {
|
||||
// Обновление существующего объекта
|
||||
console.log('🔄 Обновляем существующий объект с ID:', id);
|
||||
const { rows } = await db.query(`
|
||||
UPDATE city_objects SET
|
||||
name = $1,
|
||||
model_url = $2,
|
||||
pos_x = $3,
|
||||
pos_y = $4,
|
||||
pos_z = $5,
|
||||
rot_x = $6,
|
||||
rot_y = $7,
|
||||
rot_z = $8,
|
||||
scale_x = $9,
|
||||
scale_y = $10,
|
||||
scale_z = $11,
|
||||
organization_id = $12,
|
||||
rent = $13,
|
||||
tax = $14,
|
||||
collidable = $15,
|
||||
interior_id = $16,
|
||||
textures = $17
|
||||
WHERE id = $18
|
||||
RETURNING id
|
||||
`, [
|
||||
name || '',
|
||||
model_url,
|
||||
pos_x || 0,
|
||||
pos_y || 0,
|
||||
pos_z || 0,
|
||||
rot_x || 0,
|
||||
rot_y || 0,
|
||||
rot_z || 0,
|
||||
scale_x || 1,
|
||||
scale_y || 1,
|
||||
scale_z || 1,
|
||||
organization_id,
|
||||
rent,
|
||||
tax,
|
||||
collidable,
|
||||
interior_id,
|
||||
textures,
|
||||
id
|
||||
]);
|
||||
result = rows[0];
|
||||
console.log('✅ Объект обновлен:', result);
|
||||
} else {
|
||||
// Создание нового объекта
|
||||
console.log('🆕 Создаем новый объект');
|
||||
const { rows } = await db.query(`
|
||||
INSERT INTO city_objects (
|
||||
city_id, name, model_url, pos_x, pos_y, pos_z,
|
||||
rot_x, rot_y, rot_z, scale_x, scale_y, scale_z,
|
||||
organization_id, rent, tax, collidable, interior_id, textures
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)
|
||||
RETURNING id
|
||||
`, [
|
||||
city_id,
|
||||
name || '',
|
||||
model_url,
|
||||
pos_x || 0,
|
||||
pos_y || 0,
|
||||
pos_z || 0,
|
||||
rot_x || 0,
|
||||
rot_y || 0,
|
||||
rot_z || 0,
|
||||
scale_x || 1,
|
||||
scale_y || 1,
|
||||
scale_z || 1,
|
||||
organization_id,
|
||||
rent,
|
||||
tax,
|
||||
collidable,
|
||||
interior_id,
|
||||
textures
|
||||
]);
|
||||
result = rows[0];
|
||||
console.log('✅ Новый объект создан:', result);
|
||||
}
|
||||
|
||||
res.json({ id: result.id, success: true });
|
||||
} catch (error) {
|
||||
console.error('Ошибка сохранения объекта:', error);
|
||||
res.status(500).json({ error: 'Ошибка сохранения объекта' });
|
||||
}
|
||||
});
|
||||
|
||||
// Удалить объект города из БД
|
||||
app.delete('/api/delete-object/:id', authenticate, async (req, res) => {
|
||||
try {
|
||||
const objectId = parseInt(req.params.id, 10);
|
||||
|
||||
if (!objectId) {
|
||||
return res.status(400).json({ error: 'ID объекта обязателен' });
|
||||
}
|
||||
|
||||
const { rowCount } = await db.query(
|
||||
'DELETE FROM city_objects WHERE id = $1',
|
||||
[objectId]
|
||||
);
|
||||
|
||||
if (rowCount === 0) {
|
||||
return res.status(404).json({ error: 'Объект не найден' });
|
||||
}
|
||||
|
||||
res.json({ success: true, message: 'Объект удален' });
|
||||
} catch (error) {
|
||||
console.error('Ошибка удаления объекта:', error);
|
||||
res.status(500).json({ error: 'Ошибка удаления объекта' });
|
||||
}
|
||||
});
|
||||
|
||||
// Тестовый эндпоинт для проверки таблицы city_objects
|
||||
app.get('/api/test-city-objects', authenticate, async (req, res) => {
|
||||
try {
|
||||
const { rows } = await db.query(`
|
||||
SELECT table_name, column_name, data_type
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'city_objects'
|
||||
ORDER BY ordinal_position
|
||||
`);
|
||||
res.json({ tableExists: rows.length > 0, columns: rows });
|
||||
} catch (error) {
|
||||
console.error('Ошибка проверки таблицы:', error);
|
||||
res.status(500).json({ error: 'Ошибка проверки таблицы', details: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// API endpoint для получения коллайдеров города из базы данных
|
||||
app.get('/api/colliders/city/:cityId', authenticate, async (req, res) => {
|
||||
const cityId = parseInt(req.params.cityId, 10);
|
||||
|
||||
Reference in New Issue
Block a user