UNPKG

express-typeorm-rest-boilerplate

Version:

Boilerplate code to get started with building RESTful API Services

36 lines 1.48 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); class EntitySeed { constructor(repo, factory) { this.repo = repo; this.factory = factory; } seedOne(data) { return __awaiter(this, void 0, void 0, function* () { const ent = yield this.factory(data); yield this.repo.save(ent); return ent; }); } seedMany(amount, data) { return __awaiter(this, void 0, void 0, function* () { const res = []; for (let i = 0; i < amount; i++) { res[i] = yield this.factory(data); yield this.repo.save(res[i]); } return res; }); } } exports.default = EntitySeed; //# sourceMappingURL=EntitySeed.js.map