UNPKG

crud-generator-ts

Version:

CRUD generator for TypeScript Express applications

32 lines (31 loc) 1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LucasTestRepository = void 0; const lucas_test_1 = require("../infra/entity/lucas-test"); class LucasTestRepository { constructor(dataSource) { this.repository = dataSource.getRepository(lucas_test_1.LucasTest); } async findAll() { return await this.repository.find(); } async findById(id) { return await this.repository.findOne({ where: { id } }); } async create(entity) { const newEntity = this.repository.create(entity); return await this.repository.save(newEntity); } async update(id, updatedData) { const entity = await this.findById(id); if (!entity) { return null; } Object.assign(entity, updatedData); return await this.repository.save(entity); } async deleteById(id) { await this.repository.delete(id); } } exports.LucasTestRepository = LucasTestRepository;