sequelize-middleware/test/utils/common.js

50 lines
944 B
JavaScript
Raw Normal View History

import uuid from "uuid/v4";
import models from "../../models";
2020-02-13 22:36:14 +01:00
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;
2020-02-13 22:36:14 +01:00
export const truncate = truncateDefault;