45 lines
822 B
JavaScript
45 lines
822 B
JavaScript
import models from "../../models";
|
|
|
|
const _truncateCars = (tables, done) => {
|
|
if (tables.indexOf("Cars") === -1) {
|
|
done(null);
|
|
return true;
|
|
}
|
|
|
|
models.CarsColors.destroy({
|
|
where: {}
|
|
})
|
|
.then(() => {
|
|
models.Cars.destroy({
|
|
where: {}
|
|
}).then(() => done(null));
|
|
})
|
|
.catch(err => done(err));
|
|
return true;
|
|
};
|
|
|
|
const _truncateBrands = (tables, done) => {
|
|
if (tables.indexOf("Brands") === -1) {
|
|
done(null);
|
|
return true;
|
|
}
|
|
|
|
models.Brands.destroy({
|
|
where: {}
|
|
})
|
|
.then(() => done(null))
|
|
.catch(err => done(err));
|
|
return true;
|
|
};
|
|
|
|
export default (tables, done) => {
|
|
_truncateCars(tables, errCars => {
|
|
if (errCars) {
|
|
done(errCars);
|
|
} else {
|
|
_truncateBrands(tables, errBrands => {
|
|
done(errBrands);
|
|
});
|
|
}
|
|
});
|
|
};
|