template and back
This commit is contained in:
commit
07ef7e9b8f
3773 files changed
+422508
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import {syncDatabase, sequelize} from './sequelize.js';
|
||||
import express from 'express';
|
||||
import routes from './routes/index.js';
|
||||
|
||||
const app = express();
|
||||
|
||||
await sequelize.authenticate();
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await syncDatabase();
|
||||
} catch (error) {
|
||||
throw new Error('Ошибка в запуске приложения:', error);
|
||||
}
|
||||
})();
|
||||
|
||||
app.use(express.json());
|
||||
routes(app);
|
||||
|
||||
app.listen(3008, () => {
|
||||
console.log(`Приложение запущено на порту 3008`);
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import DataTypes from 'sequelize';
|
||||
|
||||
export default (sequelize) => {
|
||||
sequelize.define(
|
||||
'bodyTypes',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: DataTypes.INTEGER,
|
||||
},
|
||||
name: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
}
|
||||
},
|
||||
{
|
||||
tableName: 'body_types',
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
import DataTypes from 'sequelize';
|
||||
|
||||
export default (sequelize) => {
|
||||
sequelize.define(
|
||||
'carBrands',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: DataTypes.INTEGER,
|
||||
},
|
||||
name: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
country: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
}
|
||||
},
|
||||
{
|
||||
tableName: 'car_brands',
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
import DataTypes from 'sequelize';
|
||||
|
||||
export default (sequelize) => {
|
||||
sequelize.define(
|
||||
'carColors',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: DataTypes.INTEGER,
|
||||
},
|
||||
name: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
hexCode: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
},
|
||||
{
|
||||
tableName: 'car_colors',
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
import DataTypes from 'sequelize';
|
||||
|
||||
export default (sequelize) => {
|
||||
sequelize.define(
|
||||
'carModels',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: DataTypes.INTEGER,
|
||||
},
|
||||
name: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
yearStart: {
|
||||
allowNull: false,
|
||||
type: DataTypes.INTEGER,
|
||||
},
|
||||
yearEnd: {
|
||||
allowNull: false,
|
||||
type: DataTypes.INTEGER,
|
||||
}
|
||||
},
|
||||
{
|
||||
tableName: 'car_models',
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import DataTypes from 'sequelize';
|
||||
|
||||
export default (sequelize) => {
|
||||
sequelize.define(
|
||||
'cars',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: DataTypes.INTEGER,
|
||||
}
|
||||
},
|
||||
{
|
||||
tableName: 'cars',
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
import DataTypes from 'sequelize';
|
||||
|
||||
export default (sequelize) => {
|
||||
sequelize.define(
|
||||
'customers',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: DataTypes.INTEGER,
|
||||
},
|
||||
name: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
phone: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
email: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
}
|
||||
},
|
||||
{
|
||||
tableName: 'customers',
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
import DataTypes from 'sequelize';
|
||||
|
||||
export default (sequelize) => {
|
||||
sequelize.define(
|
||||
'engines',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: DataTypes.INTEGER,
|
||||
},
|
||||
type: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
powerHR: {
|
||||
allowNull: false,
|
||||
type: DataTypes.INTEGER,
|
||||
},
|
||||
volume: {
|
||||
allowNull: false,
|
||||
type: DataTypes.DECIMAL(3, 1),
|
||||
},
|
||||
},
|
||||
{
|
||||
tableName: 'engines',
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,87 @@
|
||||
import carBrandsInit from "./carBrands.js";
|
||||
import carModelsInit from "./carModels.js";
|
||||
import bodyTypesInit from "./bodyTypes.js";
|
||||
import enginesInit from "./engines.js";
|
||||
import trimsInit from "./trims.js";
|
||||
import carColorsInit from "./carColors.js";
|
||||
import transmissionsInit from "./transmissions.js";
|
||||
import salesInit from "./sales.js";
|
||||
import carsInit from "./cars.js";
|
||||
import customersInit from "./customers.js";
|
||||
|
||||
export default (sequelize) => {
|
||||
carBrandsInit(sequelize);
|
||||
carModelsInit(sequelize);
|
||||
bodyTypesInit(sequelize);
|
||||
enginesInit(sequelize);
|
||||
trimsInit(sequelize);
|
||||
carColorsInit(sequelize);
|
||||
transmissionsInit(sequelize);
|
||||
salesInit(sequelize);
|
||||
carsInit(sequelize);
|
||||
customersInit(sequelize);
|
||||
|
||||
const {
|
||||
carBrands,
|
||||
carModels,
|
||||
engines,
|
||||
bodyTypes,
|
||||
trims,
|
||||
carColors,
|
||||
transmissions,
|
||||
sales,
|
||||
cars,
|
||||
customers
|
||||
} = sequelize.models;
|
||||
|
||||
carModels.belongsTo(carBrands, {
|
||||
foreignKey: 'car_brands_id',
|
||||
as: 'carBrands',
|
||||
});
|
||||
|
||||
trims.belongsTo(carModels, {
|
||||
foreignKey: 'car_models_id',
|
||||
as: 'carModels',
|
||||
});
|
||||
|
||||
sales.belongsTo(cars, {
|
||||
foreignKey: 'cars_id',
|
||||
as: 'cars',
|
||||
});
|
||||
|
||||
sales.belongsTo(customers, {
|
||||
foreignKey: 'customers_id',
|
||||
as: 'customers',
|
||||
});
|
||||
|
||||
cars.belongsTo(carModels, {
|
||||
foreignKey: 'car_models_id',
|
||||
as: 'carModels',
|
||||
});
|
||||
|
||||
cars.belongsTo(bodyTypes, {
|
||||
foreignKey: 'body_types_id',
|
||||
as: 'bodyTypes',
|
||||
});
|
||||
|
||||
cars.belongsTo(engines, {
|
||||
foreignKey: 'engines_id',
|
||||
as: 'engines',
|
||||
});
|
||||
|
||||
cars.belongsTo(trims, {
|
||||
foreignKey: 'trims_id',
|
||||
as: 'trims',
|
||||
});
|
||||
|
||||
cars.belongsTo(carColors, {
|
||||
foreignKey: 'car_colors_id',
|
||||
as: 'carColors',
|
||||
});
|
||||
|
||||
cars.belongsTo(transmissions, {
|
||||
foreignKey: 'transmissions_id',
|
||||
as: 'transmissions',
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import DataTypes from 'sequelize';
|
||||
|
||||
export default (sequelize) => {
|
||||
sequelize.define(
|
||||
'sales',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: DataTypes.INTEGER,
|
||||
},
|
||||
date: {
|
||||
allowNull: false,
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
price: {
|
||||
allowNull: false,
|
||||
type: DataTypes.DECIMAL(10, 2),
|
||||
}
|
||||
},
|
||||
{
|
||||
tableName: 'sales',
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
import DataTypes from 'sequelize';
|
||||
|
||||
export default (sequelize) => {
|
||||
sequelize.define(
|
||||
'transmissions',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: DataTypes.INTEGER,
|
||||
},
|
||||
type: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
},
|
||||
{
|
||||
tableName: 'transmissions',
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
import DataTypes from 'sequelize';
|
||||
|
||||
export default (sequelize) => {
|
||||
sequelize.define(
|
||||
'trims',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: DataTypes.INTEGER,
|
||||
},
|
||||
name: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
price: {
|
||||
allowNull: false,
|
||||
type: DataTypes.DECIMAL(10, 2),
|
||||
},
|
||||
},
|
||||
{
|
||||
tableName: 'trims',
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import { list, remove, create, update } from '../services/bodyTypes.js';
|
||||
|
||||
let router = express.Router();
|
||||
|
||||
router.get('/', async function (req, res) {
|
||||
try {
|
||||
const results = await list(req.query);
|
||||
res.json({ ok: true, results });
|
||||
} catch (error) {
|
||||
console.error('Error fetching car brands:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to fetch car brands' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async function (req, res) {
|
||||
try {
|
||||
const status = await create(req.body);
|
||||
res.json({ ok: true, status });
|
||||
} catch (error) {
|
||||
console.error('Error creating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to create car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/', async function (req, res) {
|
||||
try {
|
||||
const deletedCount = await remove(req.body);
|
||||
res.json({ ok: true, deletedCount });
|
||||
} catch (error) {
|
||||
console.error('Error deleting car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to delete car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/', async function (req, res) {
|
||||
try {
|
||||
const updatedCount = await update(req.body);
|
||||
res.json({ ok: true, updatedCount });
|
||||
} catch (error) {
|
||||
console.error('Error updating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to update car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import { list, remove, create, update } from '../services/carBrands.js';
|
||||
|
||||
let router = express.Router();
|
||||
|
||||
router.get('/', async function (req, res) {
|
||||
try {
|
||||
const results = await list(req.query);
|
||||
res.json({ ok: true, results });
|
||||
} catch (error) {
|
||||
console.error('Error fetching car brands:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to fetch car brands' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async function (req, res) {
|
||||
try {
|
||||
const status = await create(req.body);
|
||||
res.json({ ok: true, status });
|
||||
} catch (error) {
|
||||
console.error('Error creating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to create car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/', async function (req, res) {
|
||||
try {
|
||||
const deletedCount = await remove(req.body);
|
||||
res.json({ ok: true, deletedCount });
|
||||
} catch (error) {
|
||||
console.error('Error deleting car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to delete car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/', async function (req, res) {
|
||||
try {
|
||||
const updatedCount = await update(req.body);
|
||||
res.json({ ok: true, updatedCount });
|
||||
} catch (error) {
|
||||
console.error('Error updating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to update car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import { list, remove, create, update } from '../services/carColors.js';
|
||||
|
||||
let router = express.Router();
|
||||
|
||||
router.get('/', async function (req, res) {
|
||||
try {
|
||||
const results = await list(req.query);
|
||||
res.json({ ok: true, results });
|
||||
} catch (error) {
|
||||
console.error('Error fetching car brands:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to fetch car brands' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async function (req, res) {
|
||||
try {
|
||||
const status = await create(req.body);
|
||||
res.json({ ok: true, status });
|
||||
} catch (error) {
|
||||
console.error('Error creating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to create car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/', async function (req, res) {
|
||||
try {
|
||||
const deletedCount = await remove(req.body);
|
||||
res.json({ ok: true, deletedCount });
|
||||
} catch (error) {
|
||||
console.error('Error deleting car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to delete car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/', async function (req, res) {
|
||||
try {
|
||||
const updatedCount = await update(req.body);
|
||||
res.json({ ok: true, updatedCount });
|
||||
} catch (error) {
|
||||
console.error('Error updating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to update car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import { list, remove, create, update } from '../services/carModels.js';
|
||||
|
||||
let router = express.Router();
|
||||
|
||||
router.get('/', async function (req, res) {
|
||||
try {
|
||||
const results = await list(req.query);
|
||||
res.json({ ok: true, results });
|
||||
} catch (error) {
|
||||
console.error('Error fetching car brands:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to fetch car brands' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async function (req, res) {
|
||||
try {
|
||||
const status = await create(req.body);
|
||||
res.json({ ok: true, status });
|
||||
} catch (error) {
|
||||
console.error('Error creating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to create car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/', async function (req, res) {
|
||||
try {
|
||||
const deletedCount = await remove(req.body);
|
||||
res.json({ ok: true, deletedCount });
|
||||
} catch (error) {
|
||||
console.error('Error deleting car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to delete car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/', async function (req, res) {
|
||||
try {
|
||||
const updatedCount = await update(req.body);
|
||||
res.json({ ok: true, updatedCount });
|
||||
} catch (error) {
|
||||
console.error('Error updating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to update car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import { list, remove, create, update } from '../services/cars.js';
|
||||
|
||||
let router = express.Router();
|
||||
|
||||
router.get('/', async function (req, res) {
|
||||
try {
|
||||
const results = await list(req.query);
|
||||
res.json({ ok: true, results });
|
||||
} catch (error) {
|
||||
console.error('Error fetching car brands:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to fetch car brands' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async function (req, res) {
|
||||
try {
|
||||
const status = await create(req.body);
|
||||
res.json({ ok: true, status });
|
||||
} catch (error) {
|
||||
console.error('Error creating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to create car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/', async function (req, res) {
|
||||
try {
|
||||
const deletedCount = await remove(req.body);
|
||||
res.json({ ok: true, deletedCount });
|
||||
} catch (error) {
|
||||
console.error('Error deleting car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to delete car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/', async function (req, res) {
|
||||
try {
|
||||
const updatedCount = await update(req.body);
|
||||
res.json({ ok: true, updatedCount });
|
||||
} catch (error) {
|
||||
console.error('Error updating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to update car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import { list, remove, create, update } from '../services/customers.js';
|
||||
|
||||
let router = express.Router();
|
||||
|
||||
router.get('/', async function (req, res) {
|
||||
try {
|
||||
const results = await list(req.query);
|
||||
res.json({ ok: true, results });
|
||||
} catch (error) {
|
||||
console.error('Error fetching car brands:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to fetch car brands' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async function (req, res) {
|
||||
try {
|
||||
const status = await create(req.body);
|
||||
res.json({ ok: true, status });
|
||||
} catch (error) {
|
||||
console.error('Error creating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to create car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/', async function (req, res) {
|
||||
try {
|
||||
const deletedCount = await remove(req.body);
|
||||
res.json({ ok: true, deletedCount });
|
||||
} catch (error) {
|
||||
console.error('Error deleting car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to delete car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/', async function (req, res) {
|
||||
try {
|
||||
const updatedCount = await update(req.body);
|
||||
res.json({ ok: true, updatedCount });
|
||||
} catch (error) {
|
||||
console.error('Error updating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to update car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import { list, remove, create, update } from '../services/engines.js';
|
||||
|
||||
let router = express.Router();
|
||||
|
||||
router.get('/', async function (req, res) {
|
||||
try {
|
||||
const results = await list(req.query);
|
||||
res.json({ ok: true, results });
|
||||
} catch (error) {
|
||||
console.error('Error fetching car brands:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to fetch car brands' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async function (req, res) {
|
||||
try {
|
||||
const status = await create(req.body);
|
||||
res.json({ ok: true, status });
|
||||
} catch (error) {
|
||||
console.error('Error creating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to create car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/', async function (req, res) {
|
||||
try {
|
||||
const deletedCount = await remove(req.body);
|
||||
res.json({ ok: true, deletedCount });
|
||||
} catch (error) {
|
||||
console.error('Error deleting car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to delete car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/', async function (req, res) {
|
||||
try {
|
||||
const updatedCount = await update(req.body);
|
||||
res.json({ ok: true, updatedCount });
|
||||
} catch (error) {
|
||||
console.error('Error updating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to update car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,23 @@
|
||||
import carBrands from "./carBrands.js";
|
||||
import carModels from "./carModels.js";
|
||||
import bodyTypes from "./bodyTypes.js";
|
||||
import engines from "./engines.js";
|
||||
import trims from "./trims.js";
|
||||
import carColors from "./carColors.js";
|
||||
import transmissions from "./transmissions.js";
|
||||
import sales from "./sales.js";
|
||||
import cars from './cars.js';
|
||||
import customers from './customers.js';
|
||||
|
||||
export default (app) => {
|
||||
app.use('/api/v1/car-brands', carBrands);
|
||||
app.use('/api/v1/car-models', carModels);
|
||||
app.use('/api/v1/body-types', bodyTypes);
|
||||
app.use('/api/v1/engines', engines);
|
||||
app.use('/api/v1/trims', trims);
|
||||
app.use('/api/v1/car-colors', carColors);
|
||||
app.use('/api/v1/transmissions', transmissions);
|
||||
app.use('/api/v1/sales', sales);
|
||||
app.use('/api/v1/cars', cars);
|
||||
app.use('/api/v1/customers', customers);
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import { list, remove, create, update } from '../services/sales.js';
|
||||
|
||||
let router = express.Router();
|
||||
|
||||
router.get('/', async function (req, res) {
|
||||
try {
|
||||
const results = await list(req.query);
|
||||
res.json({ ok: true, results });
|
||||
} catch (error) {
|
||||
console.error('Error fetching car brands:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to fetch car brands' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async function (req, res) {
|
||||
try {
|
||||
const status = await create(req.body);
|
||||
res.json({ ok: true, status });
|
||||
} catch (error) {
|
||||
console.error('Error creating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to create car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/', async function (req, res) {
|
||||
try {
|
||||
const deletedCount = await remove(req.body);
|
||||
res.json({ ok: true, deletedCount });
|
||||
} catch (error) {
|
||||
console.error('Error deleting car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to delete car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/', async function (req, res) {
|
||||
try {
|
||||
const updatedCount = await update(req.body);
|
||||
res.json({ ok: true, updatedCount });
|
||||
} catch (error) {
|
||||
console.error('Error updating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to update car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import { list, remove, create, update } from '../services/transmissions.js';
|
||||
|
||||
let router = express.Router();
|
||||
|
||||
router.get('/', async function (req, res) {
|
||||
try {
|
||||
const results = await list(req.query);
|
||||
res.json({ ok: true, results });
|
||||
} catch (error) {
|
||||
console.error('Error fetching car brands:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to fetch car brands' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async function (req, res) {
|
||||
try {
|
||||
const status = await create(req.body);
|
||||
res.json({ ok: true, status });
|
||||
} catch (error) {
|
||||
console.error('Error creating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to create car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/', async function (req, res) {
|
||||
try {
|
||||
const deletedCount = await remove(req.body);
|
||||
res.json({ ok: true, deletedCount });
|
||||
} catch (error) {
|
||||
console.error('Error deleting car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to delete car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/', async function (req, res) {
|
||||
try {
|
||||
const updatedCount = await update(req.body);
|
||||
res.json({ ok: true, updatedCount });
|
||||
} catch (error) {
|
||||
console.error('Error updating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to update car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import { list, remove, create, update } from '../services/trims.js';
|
||||
|
||||
let router = express.Router();
|
||||
|
||||
router.get('/', async function (req, res) {
|
||||
try {
|
||||
const results = await list(req.query);
|
||||
res.json({ ok: true, results });
|
||||
} catch (error) {
|
||||
console.error('Error fetching car brands:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to fetch car brands' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async function (req, res) {
|
||||
try {
|
||||
const status = await create(req.body);
|
||||
res.json({ ok: true, status });
|
||||
} catch (error) {
|
||||
console.error('Error creating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to create car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/', async function (req, res) {
|
||||
try {
|
||||
const deletedCount = await remove(req.body);
|
||||
res.json({ ok: true, deletedCount });
|
||||
} catch (error) {
|
||||
console.error('Error deleting car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to delete car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/', async function (req, res) {
|
||||
try {
|
||||
const updatedCount = await update(req.body);
|
||||
res.json({ ok: true, updatedCount });
|
||||
} catch (error) {
|
||||
console.error('Error updating car brand:', error);
|
||||
res.status(500).json({ ok: false, error: 'Failed to update car brand' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,27 @@
|
||||
import Sequelize from 'sequelize';
|
||||
import models from './models/index.js';
|
||||
|
||||
const sequelize = new Sequelize(
|
||||
'keke', 'root', 'Colt7500$admins1N',
|
||||
{
|
||||
logging: false,
|
||||
host: '127.0.0.1',
|
||||
dialect: 'mysql'
|
||||
}
|
||||
);
|
||||
|
||||
models(sequelize);
|
||||
|
||||
const syncDatabase = async () => {
|
||||
try {
|
||||
await sequelize.sync({ alter: true });
|
||||
console.log('База данных успешно синхронизирована.');
|
||||
} catch (error) {
|
||||
console.error('Ошибка при синхронизации базы данных:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export default sequelize;
|
||||
|
||||
export { sequelize, syncDatabase };
|
||||
@@ -0,0 +1,60 @@
|
||||
import sequelize from "../sequelize.js";
|
||||
|
||||
export const list = async (params) => {
|
||||
try {
|
||||
const { offset, limit, search, ...otherParams } = params;
|
||||
|
||||
const numericOffset = offset ? parseInt(offset, 10) : 0;
|
||||
const numericLimit = limit ? parseInt(limit, 10) : 1000;
|
||||
|
||||
const rows = await sequelize.models.bodyTypes.findAll({
|
||||
where: { ...otherParams },
|
||||
offset: numericOffset,
|
||||
limit: numericLimit,
|
||||
});
|
||||
|
||||
return { rows };
|
||||
} catch (error) {
|
||||
console.error('Error fetching:', error);
|
||||
throw new Error('Failed to fetch');
|
||||
}
|
||||
};
|
||||
|
||||
export const create = async (params) => {
|
||||
try {
|
||||
await sequelize.models.bodyTypes.create(params);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating:', error);
|
||||
throw new Error('Failed to create');
|
||||
}
|
||||
};
|
||||
|
||||
export const update = async (params) => {
|
||||
try {
|
||||
const { where, updates } = params;
|
||||
if (!where || !updates) {
|
||||
throw new Error('Missing required parameters: where and updates');
|
||||
}
|
||||
|
||||
return await sequelize.models.bodyTypes.update(updates, {
|
||||
where
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating:', error);
|
||||
throw new Error('Failed to update');
|
||||
}
|
||||
};
|
||||
|
||||
export const remove = async (params) => {
|
||||
try {
|
||||
const { ...otherParams } = params;
|
||||
|
||||
return await sequelize.models.bodyTypes.destroy({
|
||||
where: { ...otherParams },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error deleting:', error);
|
||||
throw new Error('Failed to delete');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
import sequelize from "../sequelize.js";
|
||||
|
||||
export const list = async (params) => {
|
||||
try {
|
||||
const { offset, limit, search, ...otherParams } = params;
|
||||
|
||||
const numericOffset = offset ? parseInt(offset, 10) : 0;
|
||||
const numericLimit = limit ? parseInt(limit, 10) : 1000;
|
||||
|
||||
const rows = await sequelize.models.carBrands.findAll({
|
||||
where: { ...otherParams },
|
||||
offset: numericOffset,
|
||||
limit: numericLimit,
|
||||
});
|
||||
|
||||
return { rows };
|
||||
} catch (error) {
|
||||
console.error('Error fetching:', error);
|
||||
throw new Error('Failed to fetch');
|
||||
}
|
||||
};
|
||||
|
||||
export const create = async (params) => {
|
||||
try {
|
||||
await sequelize.models.carBrands.create(params);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating:', error);
|
||||
throw new Error('Failed to create');
|
||||
}
|
||||
};
|
||||
|
||||
export const update = async (params) => {
|
||||
try {
|
||||
const { where, updates } = params;
|
||||
if (!where || !updates) {
|
||||
throw new Error('Missing required parameters: where and updates');
|
||||
}
|
||||
|
||||
return await sequelize.models.carBrands.update(updates, {
|
||||
where
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating:', error);
|
||||
throw new Error('Failed to update');
|
||||
}
|
||||
};
|
||||
|
||||
export const remove = async (params) => {
|
||||
try {
|
||||
const { ...otherParams } = params;
|
||||
|
||||
return await sequelize.models.carBrands.destroy({
|
||||
where: { ...otherParams },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error deleting:', error);
|
||||
throw new Error('Failed to delete');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
import sequelize from "../sequelize.js";
|
||||
|
||||
export const list = async (params) => {
|
||||
try {
|
||||
const { offset, limit, search, ...otherParams } = params;
|
||||
|
||||
const numericOffset = offset ? parseInt(offset, 10) : 0;
|
||||
const numericLimit = limit ? parseInt(limit, 10) : 1000;
|
||||
|
||||
const rows = await sequelize.models.carColors.findAll({
|
||||
where: { ...otherParams },
|
||||
offset: numericOffset,
|
||||
limit: numericLimit,
|
||||
});
|
||||
|
||||
return { rows };
|
||||
} catch (error) {
|
||||
console.error('Error fetching:', error);
|
||||
throw new Error('Failed to fetch');
|
||||
}
|
||||
};
|
||||
|
||||
export const create = async (params) => {
|
||||
try {
|
||||
await sequelize.models.carColors.create(params);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating:', error);
|
||||
throw new Error('Failed to create');
|
||||
}
|
||||
};
|
||||
|
||||
export const update = async (params) => {
|
||||
try {
|
||||
const { where, updates } = params;
|
||||
if (!where || !updates) {
|
||||
throw new Error('Missing required parameters: where and updates');
|
||||
}
|
||||
|
||||
return await sequelize.models.carColors.update(updates, {
|
||||
where
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating:', error);
|
||||
throw new Error('Failed to update');
|
||||
}
|
||||
};
|
||||
|
||||
export const remove = async (params) => {
|
||||
try {
|
||||
const { ...otherParams } = params;
|
||||
|
||||
return await sequelize.models.carColors.destroy({
|
||||
where: { ...otherParams },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error deleting:', error);
|
||||
throw new Error('Failed to delete');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
import sequelize from "../sequelize.js";
|
||||
|
||||
export const list = async (params) => {
|
||||
try {
|
||||
const { offset, limit, search, ...otherParams } = params;
|
||||
|
||||
const numericOffset = offset ? parseInt(offset, 10) : 0;
|
||||
const numericLimit = limit ? parseInt(limit, 10) : 1000;
|
||||
|
||||
const rows = await sequelize.models.carModels.findAll({
|
||||
where: { ...otherParams },
|
||||
offset: numericOffset,
|
||||
limit: numericLimit,
|
||||
});
|
||||
|
||||
return { rows };
|
||||
} catch (error) {
|
||||
console.error('Error fetching:', error);
|
||||
throw new Error('Failed to fetch');
|
||||
}
|
||||
};
|
||||
|
||||
export const create = async (params) => {
|
||||
try {
|
||||
await sequelize.models.carModels.create(params);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating:', error);
|
||||
throw new Error('Failed to create');
|
||||
}
|
||||
};
|
||||
|
||||
export const update = async (params) => {
|
||||
try {
|
||||
const { where, updates } = params;
|
||||
if (!where || !updates) {
|
||||
throw new Error('Missing required parameters: where and updates');
|
||||
}
|
||||
|
||||
return await sequelize.models.carModels.update(updates, {
|
||||
where
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating:', error);
|
||||
throw new Error('Failed to update');
|
||||
}
|
||||
};
|
||||
|
||||
export const remove = async (params) => {
|
||||
try {
|
||||
const { ...otherParams } = params;
|
||||
|
||||
return await sequelize.models.carModels.destroy({
|
||||
where: { ...otherParams },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error deleting:', error);
|
||||
throw new Error('Failed to delete');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
import sequelize from "../sequelize.js";
|
||||
|
||||
export const list = async (params) => {
|
||||
try {
|
||||
const { offset, limit, search, ...otherParams } = params;
|
||||
|
||||
const numericOffset = offset ? parseInt(offset, 10) : 0;
|
||||
const numericLimit = limit ? parseInt(limit, 10) : 1000;
|
||||
|
||||
const rows = await sequelize.models.cars.findAll({
|
||||
where: { ...otherParams },
|
||||
offset: numericOffset,
|
||||
limit: numericLimit,
|
||||
});
|
||||
|
||||
return { rows };
|
||||
} catch (error) {
|
||||
console.error('Error fetching:', error);
|
||||
throw new Error('Failed to fetch');
|
||||
}
|
||||
};
|
||||
|
||||
export const create = async (params) => {
|
||||
try {
|
||||
await sequelize.models.cars.create(params);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating:', error);
|
||||
throw new Error('Failed to create');
|
||||
}
|
||||
};
|
||||
|
||||
export const update = async (params) => {
|
||||
try {
|
||||
const { where, updates } = params;
|
||||
if (!where || !updates) {
|
||||
throw new Error('Missing required parameters: where and updates');
|
||||
}
|
||||
|
||||
return await sequelize.models.cars.update(updates, {
|
||||
where
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating:', error);
|
||||
throw new Error('Failed to update');
|
||||
}
|
||||
};
|
||||
|
||||
export const remove = async (params) => {
|
||||
try {
|
||||
const { ...otherParams } = params;
|
||||
|
||||
return await sequelize.models.cars.destroy({
|
||||
where: { ...otherParams },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error deleting:', error);
|
||||
throw new Error('Failed to delete');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
import sequelize from "../sequelize.js";
|
||||
|
||||
export const list = async (params) => {
|
||||
try {
|
||||
const { offset, limit, search, ...otherParams } = params;
|
||||
|
||||
const numericOffset = offset ? parseInt(offset, 10) : 0;
|
||||
const numericLimit = limit ? parseInt(limit, 10) : 1000;
|
||||
|
||||
const rows = await sequelize.models.customers.findAll({
|
||||
where: { ...otherParams },
|
||||
offset: numericOffset,
|
||||
limit: numericLimit,
|
||||
});
|
||||
|
||||
return { rows };
|
||||
} catch (error) {
|
||||
console.error('Error fetching:', error);
|
||||
throw new Error('Failed to fetch');
|
||||
}
|
||||
};
|
||||
|
||||
export const create = async (params) => {
|
||||
try {
|
||||
await sequelize.models.customers.create(params);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating:', error);
|
||||
throw new Error('Failed to create');
|
||||
}
|
||||
};
|
||||
|
||||
export const update = async (params) => {
|
||||
try {
|
||||
const { where, updates } = params;
|
||||
if (!where || !updates) {
|
||||
throw new Error('Missing required parameters: where and updates');
|
||||
}
|
||||
|
||||
return await sequelize.models.customers.update(updates, {
|
||||
where
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating:', error);
|
||||
throw new Error('Failed to update');
|
||||
}
|
||||
};
|
||||
|
||||
export const remove = async (params) => {
|
||||
try {
|
||||
const { ...otherParams } = params;
|
||||
|
||||
return await sequelize.models.customers.destroy({
|
||||
where: { ...otherParams },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error deleting:', error);
|
||||
throw new Error('Failed to delete');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
import sequelize from "../sequelize.js";
|
||||
|
||||
export const list = async (params) => {
|
||||
try {
|
||||
const { offset, limit, search, ...otherParams } = params;
|
||||
|
||||
const numericOffset = offset ? parseInt(offset, 10) : 0;
|
||||
const numericLimit = limit ? parseInt(limit, 10) : 1000;
|
||||
|
||||
const rows = await sequelize.models.engines.findAll({
|
||||
where: { ...otherParams },
|
||||
offset: numericOffset,
|
||||
limit: numericLimit,
|
||||
});
|
||||
|
||||
return { rows };
|
||||
} catch (error) {
|
||||
console.error('Error fetching:', error);
|
||||
throw new Error('Failed to fetch');
|
||||
}
|
||||
};
|
||||
|
||||
export const create = async (params) => {
|
||||
try {
|
||||
await sequelize.models.engines.create(params);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating:', error);
|
||||
throw new Error('Failed to create');
|
||||
}
|
||||
};
|
||||
|
||||
export const update = async (params) => {
|
||||
try {
|
||||
const { where, updates } = params;
|
||||
if (!where || !updates) {
|
||||
throw new Error('Missing required parameters: where and updates');
|
||||
}
|
||||
|
||||
return await sequelize.models.engines.update(updates, {
|
||||
where
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating:', error);
|
||||
throw new Error('Failed to update');
|
||||
}
|
||||
};
|
||||
|
||||
export const remove = async (params) => {
|
||||
try {
|
||||
const { ...otherParams } = params;
|
||||
|
||||
return await sequelize.models.engines.destroy({
|
||||
where: { ...otherParams },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error deleting:', error);
|
||||
throw new Error('Failed to delete');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
import sequelize from "../sequelize.js";
|
||||
|
||||
export const list = async (params) => {
|
||||
try {
|
||||
const { offset, limit, search, ...otherParams } = params;
|
||||
|
||||
const numericOffset = offset ? parseInt(offset, 10) : 0;
|
||||
const numericLimit = limit ? parseInt(limit, 10) : 1000;
|
||||
|
||||
const rows = await sequelize.models.sales.findAll({
|
||||
where: { ...otherParams },
|
||||
offset: numericOffset,
|
||||
limit: numericLimit,
|
||||
});
|
||||
|
||||
return { rows };
|
||||
} catch (error) {
|
||||
console.error('Error fetching:', error);
|
||||
throw new Error('Failed to fetch');
|
||||
}
|
||||
};
|
||||
|
||||
export const create = async (params) => {
|
||||
try {
|
||||
await sequelize.models.sales.create(params);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating:', error);
|
||||
throw new Error('Failed to create');
|
||||
}
|
||||
};
|
||||
|
||||
export const update = async (params) => {
|
||||
try {
|
||||
const { where, updates } = params;
|
||||
if (!where || !updates) {
|
||||
throw new Error('Missing required parameters: where and updates');
|
||||
}
|
||||
|
||||
return await sequelize.models.sales.update(updates, {
|
||||
where
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating:', error);
|
||||
throw new Error('Failed to update');
|
||||
}
|
||||
};
|
||||
|
||||
export const remove = async (params) => {
|
||||
try {
|
||||
const { ...otherParams } = params;
|
||||
|
||||
return await sequelize.models.sales.destroy({
|
||||
where: { ...otherParams },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error deleting:', error);
|
||||
throw new Error('Failed to delete');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
import sequelize from "../sequelize.js";
|
||||
|
||||
export const list = async (params) => {
|
||||
try {
|
||||
const { offset, limit, search, ...otherParams } = params;
|
||||
|
||||
const numericOffset = offset ? parseInt(offset, 10) : 0;
|
||||
const numericLimit = limit ? parseInt(limit, 10) : 1000;
|
||||
|
||||
const rows = await sequelize.models.transmissions.findAll({
|
||||
where: { ...otherParams },
|
||||
offset: numericOffset,
|
||||
limit: numericLimit,
|
||||
});
|
||||
|
||||
return { rows };
|
||||
} catch (error) {
|
||||
console.error('Error fetching:', error);
|
||||
throw new Error('Failed to fetch');
|
||||
}
|
||||
};
|
||||
|
||||
export const create = async (params) => {
|
||||
try {
|
||||
await sequelize.models.transmissions.create(params);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating:', error);
|
||||
throw new Error('Failed to create');
|
||||
}
|
||||
};
|
||||
|
||||
export const update = async (params) => {
|
||||
try {
|
||||
const { where, updates } = params;
|
||||
if (!where || !updates) {
|
||||
throw new Error('Missing required parameters: where and updates');
|
||||
}
|
||||
|
||||
return await sequelize.models.transmissions.update(updates, {
|
||||
where
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating:', error);
|
||||
throw new Error('Failed to update');
|
||||
}
|
||||
};
|
||||
|
||||
export const remove = async (params) => {
|
||||
try {
|
||||
const { ...otherParams } = params;
|
||||
|
||||
return await sequelize.models.transmissions.destroy({
|
||||
where: { ...otherParams },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error deleting:', error);
|
||||
throw new Error('Failed to delete');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
import sequelize from "../sequelize.js";
|
||||
|
||||
export const list = async (params) => {
|
||||
try {
|
||||
const { offset, limit, search, ...otherParams } = params;
|
||||
|
||||
const numericOffset = offset ? parseInt(offset, 10) : 0;
|
||||
const numericLimit = limit ? parseInt(limit, 10) : 1000;
|
||||
|
||||
const rows = await sequelize.models.trims.findAll({
|
||||
where: { ...otherParams },
|
||||
offset: numericOffset,
|
||||
limit: numericLimit,
|
||||
});
|
||||
|
||||
return { rows };
|
||||
} catch (error) {
|
||||
console.error('Error fetching:', error);
|
||||
throw new Error('Failed to fetch');
|
||||
}
|
||||
};
|
||||
|
||||
export const create = async (params) => {
|
||||
try {
|
||||
await sequelize.models.trims.create(params);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating:', error);
|
||||
throw new Error('Failed to create');
|
||||
}
|
||||
};
|
||||
|
||||
export const update = async (params) => {
|
||||
try {
|
||||
const { where, updates } = params;
|
||||
if (!where || !updates) {
|
||||
throw new Error('Missing required parameters: where and updates');
|
||||
}
|
||||
|
||||
return await sequelize.models.trims.update(updates, {
|
||||
where
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating:', error);
|
||||
throw new Error('Failed to update');
|
||||
}
|
||||
};
|
||||
|
||||
export const remove = async (params) => {
|
||||
try {
|
||||
const { ...otherParams } = params;
|
||||
|
||||
return await sequelize.models.trims.destroy({
|
||||
where: { ...otherParams },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error deleting:', error);
|
||||
throw new Error('Failed to delete');
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user