import { {{ properCase name }} } from './{{ kebabCase name }}.entity'; import { Inject, Injectable, NotFoundException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { {{ properCase name }}Repository } from './{{ kebabCase name }}.repository'; import { } from './{{ kebabCase name }}.constants'; import { {{ properCase name }}Dto } from './{{ kebabCase name }}.dto'; import Optional from 'typescript-optional'; @Injectable() export class {{ properCase name }}Service { constructor( @InjectRepository({{ properCase name }}Repository) private readonly {{ camelCase name }}Repository: {{ properCase name }}Repository, ) { } async getAll(): Promise<{{ properCase name }}[]> { return this.{{ camelCase name }}Repository.find({}); } async getOneById(id: number): Promise> { return this.{{ camelCase name }}Repository.findOneById(id); } async saveNew(body: {{ properCase name }}Dto): Promise<{{ properCase name }}> { let {{ camelCase name }}New = new {{ properCase name }}(); // Complete with the mappings {{ camelCase name }}New = await this.{{ camelCase name }}Repository.save({{ camelCase name }}New); return {{ camelCase name }}New; } async update(id: number, body: {{ properCase name }}Dto): Promise<{{ properCase name }}> { let {{ camelCase name }}Found = (await this.{{ camelCase name }}Repository.findOneById(id)).orElseThrow( () => new NotFoundException(), ); // Complete with the mappings {{ camelCase name }}Found = await this.{{ camelCase name }}Repository.save({{ camelCase name }}Found); return {{ camelCase name }}Found; } async deleteById(id: number): Promise { const {{ camelCase name }}Found = (await this.{{ camelCase name }}Repository.findOneById( id, )).orElseThrow(() => new NotFoundException()); await this.{{ camelCase name }}Repository.remove({{ camelCase name }}Found); } }