40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { Pcncm } from '../../domain/entity/tables/pcncm.entity';
|
|
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
|
|
@Injectable()
|
|
export class NcmService {
|
|
constructor(@InjectRepository(Pcncm)
|
|
private ncmRepository: Repository<Pcncm>){}
|
|
|
|
async findAll(): Promise<Pcncm[]> {
|
|
return await this.ncmRepository
|
|
.createQueryBuilder('pcncm')
|
|
.select('"pcncm".codncmex', 'codigoNcmEx')
|
|
.addSelect('concat(concat("pcncm".codncmex, \' - \'),SUBSTR("pcncm".descricao,1,100))', 'descricaoNcm')
|
|
.where('dtexclusao is null')
|
|
.getRawMany();
|
|
}
|
|
|
|
async findByDescription(description: string): Promise<Pcncm[]> {
|
|
|
|
return await this.ncmRepository
|
|
.createQueryBuilder('pcncm')
|
|
.select('"pcncm".codncmex', 'codigoNcmEx')
|
|
.addSelect('concat(concat("pcncm".codncmex, \' - \'),SUBSTR("pcncm".descricao,1,100))', 'descricaoNcm')
|
|
.where('dtexclusao is null')
|
|
.andWhere("descricao like UPPER(:description)||'%'", {description})
|
|
.getRawMany();
|
|
}
|
|
|
|
async find(ncm: string): Promise<Pcncm[]> {
|
|
return await this.ncmRepository
|
|
.createQueryBuilder('pcncm')
|
|
.where("dtexclusao is null and codncm like :ncm||'%'", { ncm })
|
|
.getRawMany();
|
|
}
|
|
|
|
|
|
}
|