49 lines
944 B
JavaScript
49 lines
944 B
JavaScript
import uuid from "uuid/v4";
|
|
import models from "../../models";
|
|
import truncateDefault from "./truncate";
|
|
|
|
const _createCar = (brandId, active, year, done) => {
|
|
models.Cars.create({
|
|
name: uuid(),
|
|
year,
|
|
active,
|
|
brandId
|
|
})
|
|
.then(item => {
|
|
done(null, item);
|
|
})
|
|
.catch(done);
|
|
};
|
|
|
|
const _createBrand = done => {
|
|
models.Brands.create({
|
|
name: uuid()
|
|
})
|
|
.then(item => {
|
|
done(null, item);
|
|
})
|
|
.catch(done);
|
|
};
|
|
|
|
const _createBrands = (total, done) => {
|
|
const created = [];
|
|
const next = () => {
|
|
if (total === created.length) {
|
|
done(null, created);
|
|
}
|
|
};
|
|
|
|
for (let i = 0; i < total; i += 1) {
|
|
_createBrand((err, res) => {
|
|
if (!err) {
|
|
created.push(res);
|
|
next();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
export const createBrand = _createBrand;
|
|
export const createBrands = _createBrands;
|
|
export const createCar = _createCar;
|
|
export const truncate = truncateDefault;
|