commit
This commit is contained in:
10
src/backoffice/backoffice.module.ts
Normal file
10
src/backoffice/backoffice.module.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ProductController } from './product/product.controller';
|
||||
import { ProductService } from './product/product.service';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [ProductController],
|
||||
providers: [ProductService],
|
||||
})
|
||||
export class BackofficeModule {}
|
||||
24
src/backoffice/category/category.controller.ts
Normal file
24
src/backoffice/category/category.controller.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { CategoryService } from './category.service';
|
||||
import { Controller, Get, HttpException, HttpStatus, Param } from '@nestjs/common';
|
||||
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
||||
import { ResultModel } from 'src/domain/models/result.model';
|
||||
|
||||
@ApiTags('BackOffice')
|
||||
@Controller('v1/category')
|
||||
export class CategoryController {
|
||||
|
||||
constructor(private readonly categoryService: CategoryService){}
|
||||
|
||||
@Get(':idSecion')
|
||||
@ApiExcludeEndpoint()
|
||||
async getSection(@Param('idSecion') idSection: number) {
|
||||
try {
|
||||
const result = await this.categoryService.find(idSection);
|
||||
return new ResultModel(true, null, result, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de departamentos', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
15
src/backoffice/category/category.module.ts
Normal file
15
src/backoffice/category/category.module.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Pccategoria } from '../../domain/entity/tables/pccategoria.entity';
|
||||
import { CategoryService } from './category.service';
|
||||
import { CategoryController } from './category.controller';
|
||||
import { CacheModule, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
@Module({
|
||||
imports: [CacheModule.register(),
|
||||
TypeOrmModule.forFeature([Pccategoria])],
|
||||
controllers: [
|
||||
CategoryController,],
|
||||
providers: [
|
||||
CategoryService,],
|
||||
})
|
||||
export class CategoryModule { }
|
||||
22
src/backoffice/category/category.service.ts
Normal file
22
src/backoffice/category/category.service.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Pccategoria } from '../../domain/entity/tables/pccategoria.entity';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class CategoryService {
|
||||
constructor(@InjectRepository(Pccategoria)
|
||||
private categoryRespository: Repository<Pccategoria>) { }
|
||||
|
||||
async find(idSecion: number): Promise<Pccategoria[]> {
|
||||
return await this.categoryRespository
|
||||
.createQueryBuilder('pccategoria')
|
||||
.select('"pccategoria".codcategoria', 'codigoCategoria')
|
||||
.addSelect('concat(concat("pccategoria".codcategoria, \'-\'),"pccategoria".categoria)', 'descricaoCategoria')
|
||||
//.addSelect('concat(concat("pccategoria".codcategoria, \'-\'),"pccategoria".categoria)', 'descricaoCategoria')
|
||||
.where("codsec = :codsec", { codsec: idSecion })
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
38
src/backoffice/cest/cest.controller.ts
Normal file
38
src/backoffice/cest/cest.controller.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
||||
import { ResultModel } from './../../domain/models/result.model';
|
||||
import { CestService } from './cest.service';
|
||||
import { Controller, Get, HttpException, HttpStatus, Param, Req } from '@nestjs/common';
|
||||
|
||||
@ApiTags('BackOffice')
|
||||
@Controller('v1/cest')
|
||||
export class CestController {
|
||||
constructor(private readonly cestService: CestService){}
|
||||
|
||||
@Get()
|
||||
@ApiExcludeEndpoint()
|
||||
async getAll(@Req() req) {
|
||||
try {
|
||||
if (req.query['query'])
|
||||
{
|
||||
const result = await this.cestService.findByDescription(req.query['query']);
|
||||
return new ResultModel(true, null, result, []);
|
||||
}
|
||||
return new ResultModel(false, 'Para pesquisar os Cest é necessário informar pelo menos 3 caracteres.', null, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de dicionários', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get(':ncm')
|
||||
@ApiExcludeEndpoint()
|
||||
async GetbyNcm(@Param('ncm') ncm: string) {
|
||||
try {
|
||||
const result = await this.cestService.findByNcm(ncm);
|
||||
return new ResultModel(true, null, result, null);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de CESTs', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
15
src/backoffice/cest/cest.module.ts
Normal file
15
src/backoffice/cest/cest.module.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Pccest } from '../../domain/entity/tables/pccest.entity';
|
||||
import { CestController } from './cest.controller';
|
||||
import { CestService } from './cest.service';
|
||||
import { CacheModule, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
@Module({
|
||||
imports: [CacheModule.register(),
|
||||
TypeOrmModule.forFeature([Pccest])],
|
||||
controllers: [
|
||||
CestController,],
|
||||
providers: [
|
||||
CestService,],
|
||||
})
|
||||
export class CestModule { }
|
||||
35
src/backoffice/cest/cest.service.ts
Normal file
35
src/backoffice/cest/cest.service.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Pccest } from '../../domain/entity/tables/pccest.entity';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class CestService {
|
||||
constructor(@InjectRepository(Pccest)
|
||||
private cestRepository: Repository<Pccest>) { }
|
||||
|
||||
async find(): Promise<Pccest[]> {
|
||||
return await this.cestRepository
|
||||
.createQueryBuilder('pccest')
|
||||
.getMany()
|
||||
}
|
||||
|
||||
|
||||
async findByDescription(descricaoCest: string): Promise<Pccest[]> {
|
||||
|
||||
return await this.cestRepository
|
||||
.createQueryBuilder('pccest')
|
||||
.select('"pccest".codigo', 'codigo')
|
||||
.addSelect('concat(concat(\"pccest\".codcest, \'-\'), substr(\"pccest\".descricaocest,1,80))', 'descricaoCest')
|
||||
.andWhere("concat(concat(\"pccest\".codcest, \'-\'), substr(\"pccest\".descricaocest,1,80)) like '%'||UPPER(:descricaoCest)||'%'", {descricaoCest})
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
async findByNcm(codigoNcm: string): Promise<Pccest[]> {
|
||||
return await this.cestRepository
|
||||
.createQueryBuilder('pccest')
|
||||
.where('ncm = :codigoncm', { codigoncm: codigoNcm })
|
||||
.getMany()
|
||||
}
|
||||
|
||||
}
|
||||
35
src/backoffice/department/department.controller.ts
Normal file
35
src/backoffice/department/department.controller.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { DepartmentService } from './department.service';
|
||||
import { CacheInterceptor, Controller, Get, HttpException, HttpStatus, UseInterceptors } from '@nestjs/common';
|
||||
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
||||
import { ResultModel } from 'src/domain/models/result.model';
|
||||
|
||||
@ApiTags('BackOffice')
|
||||
@Controller('api/v1/department')
|
||||
export class DepartmentController {
|
||||
|
||||
constructor(private readonly departmentService: DepartmentService){}
|
||||
|
||||
@Get()
|
||||
@UseInterceptors(CacheInterceptor)
|
||||
@ApiExcludeEndpoint()
|
||||
async getAll() {
|
||||
try {
|
||||
const departments = await this.departmentService.findAll();
|
||||
return new ResultModel(true, null, departments, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de departamentos', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('all')
|
||||
@UseInterceptors(CacheInterceptor)
|
||||
async get() {
|
||||
try {
|
||||
const departments = await this.departmentService.findDepartments();
|
||||
return new ResultModel(true, null, departments, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de departamentos', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
14
src/backoffice/department/department.module.ts
Normal file
14
src/backoffice/department/department.module.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Pcdepto } from '../../domain/entity/tables/pcdepto.entity';
|
||||
import { DepartmentService } from './department.service';
|
||||
import { DepartmentController } from './department.controller';
|
||||
import { CacheModule, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
@Module({
|
||||
imports: [ CacheModule.register(),
|
||||
TypeOrmModule.forFeature([Pcdepto])],
|
||||
controllers: [DepartmentController,],
|
||||
providers: [DepartmentService,],
|
||||
|
||||
})
|
||||
export class DepartmentModule { }
|
||||
47
src/backoffice/department/department.service.ts
Normal file
47
src/backoffice/department/department.service.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Pcdepto } from 'src/domain/entity/tables/pcdepto.entity';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { getConnection, Repository } from 'typeorm';
|
||||
import { Esvdepartamento } from 'src/domain/entity/views/esvdepartamento.entity';
|
||||
|
||||
@Injectable()
|
||||
export class DepartmentService {
|
||||
constructor( @InjectRepository(Pcdepto)
|
||||
private departmentRepository: Repository<Pcdepto>){}
|
||||
|
||||
async findAll(): Promise<Pcdepto[]> {
|
||||
return await this.departmentRepository
|
||||
.createQueryBuilder('pcdepto')
|
||||
.leftJoinAndSelect("pcdepto.secoes", "secoes")
|
||||
.leftJoinAndSelect("pcsecao.categoria", "categoria")
|
||||
.select('"pcdepto".codepto', 'codigoDepartamento')
|
||||
.addSelect('concat(concat("pcdepto".codepto, \' - \'),"pcdepto".descricao)', 'descricaoDepartamento')
|
||||
// .addSelect('concat(concat(concat("pcdepto".descricao, \' (\'),"pcdepto".codepto),\')\')', 'descricaoDepartamento')
|
||||
.where('codepto <> 9999')
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
async findDepartments() {
|
||||
|
||||
const connection = getConnection();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const departments = await queryRunner.manager
|
||||
.getRepository(Esvdepartamento)
|
||||
.createQueryBuilder('esvdepartamento')
|
||||
.innerJoinAndSelect('esvdepartamento.secoes', 'secoes')
|
||||
.innerJoinAndSelect('secoes.categorias', 'itens')
|
||||
.where('\"esvdepartamento\".codepto <> 9999')
|
||||
.orderBy("\"esvdepartamento\".DESCRICAO")
|
||||
.getMany();
|
||||
return departments;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
64
src/backoffice/dictionary/dictionary.controller.ts
Normal file
64
src/backoffice/dictionary/dictionary.controller.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { ResultModel } from '../../domain/models/result.model';
|
||||
import { CreateDictionaryContract } from '../../contracts/dictionary.contract';
|
||||
import { ValidadorInterceptor } from '../../Interceptors/validador.interceptor';
|
||||
import { DictionaryModel } from '../../domain/models/dictionary.model';
|
||||
import { DictionaryService } from './dictionary.service';
|
||||
import { Controller, Get, Param, Put, Body, Post, Delete, UseInterceptors, HttpException, HttpStatus, CacheInterceptor, Req } from "@nestjs/common";
|
||||
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('BackOffice')
|
||||
@Controller('v1/dictionary')
|
||||
export class DictionaryController {
|
||||
|
||||
constructor(
|
||||
private readonly dictionaryService: DictionaryService
|
||||
){}
|
||||
|
||||
@Get()
|
||||
@UseInterceptors(CacheInterceptor)
|
||||
@ApiExcludeEndpoint()
|
||||
async getAll(@Req() req) {
|
||||
try {
|
||||
if (req.query['query'])
|
||||
{
|
||||
const result = await this.dictionaryService.findByDescription(req.query['query']);
|
||||
return new ResultModel(true, null, result, []);
|
||||
}
|
||||
const dictionaries = await this.dictionaryService.findAll();
|
||||
return new ResultModel(true, null, dictionaries, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de dicionários', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async get(@Param('id') id: number) {
|
||||
try {
|
||||
const dictionary = await this.dictionaryService.find(id);
|
||||
return new ResultModel(true, null, dictionary, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar dicionário.', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
async put(@Param('id') id: number, @Body() dados: DictionaryModel) {
|
||||
try {
|
||||
await this.dictionaryService.update(id, dados);
|
||||
return new ResultModel(true, null, dados, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível atualizar dicionário.', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Post()
|
||||
@UseInterceptors(new ValidadorInterceptor(new CreateDictionaryContract()))
|
||||
async post(@Body() dados: DictionaryModel) {
|
||||
return await this.dictionaryService.create(dados);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(@Param('id') id: number) {
|
||||
return await this.dictionaryService.delete(id);
|
||||
}
|
||||
}
|
||||
30
src/backoffice/dictionary/dictionary.module.ts
Normal file
30
src/backoffice/dictionary/dictionary.module.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { User } from '../../domain/entity/tables/estusuario.enity';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { DictionaryController } from './dictionary.controller';
|
||||
import { CacheModule, Module } from "@nestjs/common";
|
||||
import { DictionaryService } from './dictionary.service';
|
||||
import { EstAbreviatura } from 'src/domain/entity/tables/estabreviatura.entity';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
|
||||
import { JwtStrategy } from '../../Auth/strategies/jwt-strategy';
|
||||
import { AuthService } from '../../Auth/services/auth.service';
|
||||
import { UserController } from 'src/Auth/controllers/user.controller';
|
||||
import { UserService } from 'src/Auth/services/user.service';
|
||||
|
||||
@Module({
|
||||
imports: [CacheModule.register(),
|
||||
PassportModule.register({
|
||||
defaultStrategy: 'jwt'
|
||||
}),
|
||||
JwtModule.register({
|
||||
secretOrPrivateKey: '4557C0D7-DFB0-40DA-BF83-91A75103F7A9',
|
||||
signOptions: {
|
||||
expiresIn: 3600,
|
||||
}
|
||||
}),TypeOrmModule.forFeature([EstAbreviatura, User])],
|
||||
controllers: [UserController, DictionaryController],
|
||||
providers: [DictionaryService, UserService, AuthService, JwtStrategy],
|
||||
})
|
||||
|
||||
export class DictionaryModule {}
|
||||
84
src/backoffice/dictionary/dictionary.service.ts
Normal file
84
src/backoffice/dictionary/dictionary.service.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { ResultModel } from '../../domain/models/result.model';
|
||||
import { DictionaryModel } from '../../domain/models/dictionary.model';
|
||||
import { EstAbreviatura } from 'src/domain/entity/tables/estabreviatura.entity';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository, getConnection } from 'typeorm';
|
||||
import { NumberUtils } from 'src/utils/number.utils';
|
||||
|
||||
@Injectable()
|
||||
export class DictionaryService {
|
||||
|
||||
constructor(
|
||||
@InjectRepository(EstAbreviatura)
|
||||
private dictionaryRepository: Repository<EstAbreviatura>
|
||||
) { }
|
||||
|
||||
async findAll(): Promise<EstAbreviatura[]> {
|
||||
return await this.dictionaryRepository.find();
|
||||
}
|
||||
|
||||
async findByDescription(description: string): Promise<EstAbreviatura[]> {
|
||||
return await this.dictionaryRepository
|
||||
.createQueryBuilder("estabreviatura")
|
||||
.where("PALAVRA LIKE UPPER(:description)||'%'", { description }
|
||||
).getMany();
|
||||
}
|
||||
|
||||
async find(id: number): Promise<EstAbreviatura> {
|
||||
return await this.dictionaryRepository.createQueryBuilder("estabreviatura").where(
|
||||
"ID = :id", { id: id }
|
||||
).getOne();
|
||||
}
|
||||
|
||||
async update(id: number, dados: DictionaryModel) {
|
||||
|
||||
return await this.dictionaryRepository
|
||||
.createQueryBuilder()
|
||||
.update(EstAbreviatura)
|
||||
.set({ abreviatura: dados.nick, palavra: dados.word })
|
||||
.where("ID = :id", { id })
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
||||
async delete(id: number) {
|
||||
|
||||
return await getConnection()
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(EstAbreviatura)
|
||||
.where("ID = :id", { id })
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
||||
async create(dados: DictionaryModel) {
|
||||
|
||||
try
|
||||
{
|
||||
const id = NumberUtils.getNewId(9999, 1);
|
||||
const newDictionary = new EstAbreviatura();
|
||||
|
||||
newDictionary.id = id;
|
||||
newDictionary.abreviatura = dados.nick;
|
||||
newDictionary.palavra = dados.word;
|
||||
|
||||
await getConnection()
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(EstAbreviatura)
|
||||
.values(newDictionary)
|
||||
.execute();
|
||||
|
||||
return newDictionary;
|
||||
|
||||
} catch ( erro ) {
|
||||
return new ResultModel(true, "Ops! Houve um erro ao criar o Dicionário.", null, erro);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
97
src/backoffice/lists/lists.controller.ts
Normal file
97
src/backoffice/lists/lists.controller.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { ListsService } from './lists.service';
|
||||
import { ApiParam, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('BackOffice')
|
||||
@Controller('api/v1/lists')
|
||||
export class ListsController {
|
||||
|
||||
constructor(private readonly listsServices: ListsService) { }
|
||||
|
||||
/**
|
||||
* Consulta todas filiais cadastradas
|
||||
*/
|
||||
@Get('store')
|
||||
async getAll() {
|
||||
return this.listsServices.GetStoreAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta filiais autorizadas para o usuário
|
||||
*/
|
||||
@Get('store/user/:id')
|
||||
async getByUser(@Param('id') id: number) {
|
||||
return this.listsServices.GetStoreByUser(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta tabela de checkouts da filial informada
|
||||
*/
|
||||
@Get('checkout/:store')
|
||||
@ApiParam({name: 'Código da filial',})
|
||||
async getCheckout(@Param('store') idStore: string) {
|
||||
return this.listsServices.GetCheckout(idStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta lista de funcionários para a filial informada nos parâmetros
|
||||
*/
|
||||
@Get('user/:store')
|
||||
async getUser(@Param('store') idStore: string) {
|
||||
return this.listsServices.GetUser(idStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta tabela de plano de pagamento para pedido de venda
|
||||
*/
|
||||
@Get('paymentplan/:billindid')
|
||||
async getPaymentPlan(@Param('billindid') billingId: string) {
|
||||
return this.listsServices.GetPaymentPlan(billingId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta tabela de cobrança para pedido de venda
|
||||
*/
|
||||
@Get('billing/:customerid')
|
||||
async getBillingByCustomer(@Param('customerid') customerId: number) {
|
||||
return this.listsServices.GetBilling(customerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta cadastro de parceiros
|
||||
*/
|
||||
@Get('partners')
|
||||
async getPartners() {
|
||||
return this.listsServices.GetPartners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta praças para o cadastro de cliente / endereços
|
||||
*/
|
||||
@Get('places')
|
||||
async getPlaces() {
|
||||
return this.listsServices.GetPlaces();
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta praças para o cadastro de cliente / endereços para retira em loja (CODPRINCIPAL = 1004)
|
||||
*/
|
||||
@Get('store-places')
|
||||
async getStorePlaces() {
|
||||
return this.listsServices.GetStorePlaces();
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta ramos de atividade do cliente
|
||||
*/
|
||||
@Get('ramo')
|
||||
async getRamo() {
|
||||
return this.listsServices.GetRamo();
|
||||
}
|
||||
|
||||
@Get('supervisores')
|
||||
async getSupervisores() {
|
||||
return this.listsServices.getSupervisores();
|
||||
}
|
||||
|
||||
}
|
||||
12
src/backoffice/lists/lists.module.ts
Normal file
12
src/backoffice/lists/lists.module.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ListsService } from './lists.service';
|
||||
import { ListsController } from './lists.controller';
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [
|
||||
ListsController,],
|
||||
providers: [
|
||||
ListsService,],
|
||||
})
|
||||
export class ListsModule { }
|
||||
302
src/backoffice/lists/lists.service.ts
Normal file
302
src/backoffice/lists/lists.service.ts
Normal file
@@ -0,0 +1,302 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Checkout } from 'src/domain/entity/tables/pccaixa.entity';
|
||||
import { Connection } from 'typeorm';
|
||||
import { Store } from '../../domain/entity/tables/pcfilial.entity';
|
||||
import { Pcempr } from '../../domain/entity/tables/pcempr.entity';
|
||||
import { connectionOptions } from 'src/configs/typeorm.config';
|
||||
|
||||
@Injectable()
|
||||
export class ListsService {
|
||||
|
||||
async GetStoreAll(): Promise<Store[]> {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = `SELECT PCFILIAL.CODIGO as "id", ` +
|
||||
` PCFILIAL.RAZAOSOCIAL as "name", ` +
|
||||
` PCFILIAL.CODIGO|| ' - '|| PCFILIAL.FANTASIA as "shortName" ` +
|
||||
` FROM PCFILIAL ` +
|
||||
` WHERE PCFILIAL.CODIGO <> '99' ` +
|
||||
` ORDER BY PCFILIAL.CODIGO `;
|
||||
const stores = await queryRunner.query(sql);
|
||||
return stores as Store[];
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetStoreByUser(idUser: number): Promise<Store[]> {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
const sql = `SELECT PCFILIAL.CODIGO as "id", ` +
|
||||
` PCFILIAL.RAZAOSOCIAL as "name", ` +
|
||||
` PCFILIAL.CODIGO|| ' - '|| PCFILIAL.FANTASIA as "shortName" ` +
|
||||
` FROM PCFILIAL `;
|
||||
const whereByUser = " WHERE PCFILIAL.CODIGO <> '99' AND " +
|
||||
" ((PCFILIAL.CODIGO IN ( SELECT PCLIB.CODIGOA FROM PCLIB WHERE PCLIB.CODTABELA = 1 AND PCLIB.CODFUNC = :iduser )) OR " +
|
||||
" (EXISTS(SELECT PCLIB.CODIGOA FROM PCLIB WHERE PCLIB.CODTABELA = 1 AND PCLIB.CODFUNC = :iduser AND PCLIB.CODIGOA = '99')) ) ";
|
||||
|
||||
const orderBy = ` ORDER BY PCFILIAL.CODIGO`
|
||||
try {
|
||||
const stores = await queryRunner.query(sql + whereByUser + orderBy, [idUser]);
|
||||
return stores as Store[];
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetCheckout(idStore: string): Promise<Checkout[]> {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const checkouts = await queryRunner.manager
|
||||
.getRepository(Checkout)
|
||||
.createQueryBuilder('pccaixa')
|
||||
.where("\"pccaixa\".CODFILIAL = :idStore", {idStore: idStore})
|
||||
.orderBy("\"pccaixa\".NUMCAIXA")
|
||||
.getMany();
|
||||
return checkouts;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetUser(idStore: string): Promise<Pcempr[]> {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const checkouts = await queryRunner.manager
|
||||
.getRepository(Pcempr)
|
||||
.createQueryBuilder('pcempr')
|
||||
.select("\"pcempr\".matricula as \"id\", \"pcempr\".nome as \"name\", \"pcempr\".email as \"email\", \"pcempr\".usuariobd as \"smallName\"")
|
||||
.where("\"pcempr\".CODFILIAL = :idStore", {idStore: idStore})
|
||||
.orderBy("\"pcempr\".NOME")
|
||||
.getRawMany();
|
||||
return checkouts;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetPaymentPlan(billingId: string){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT PCPLPAG.CODPLPAG as "codplpag", PCPLPAG.DESCRICAO as "descricao", ' +
|
||||
' NVL(PCPLPAG.NUMDIAS,0) as "numdias" ' +
|
||||
' FROM PCPLPAG ' +
|
||||
' WHERE EXISTS(SELECT PCCOBPLPAG.CODCOB FROM PCCOBPLPAG ' +
|
||||
' WHERE PCCOBPLPAG.CODPLPAG = PCPLPAG.CODPLPAG ' +
|
||||
' AND PCCOBPLPAG.CODCOB = :CODCOB ) '
|
||||
' ORDER BY PCPAG.DESCRICAO ';
|
||||
const paymentPlans = await queryRunner.query(sql, [billingId]);
|
||||
return paymentPlans;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetBilling(clienteId: number){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT PCCOB.CODCOB as "codcob", PCCOB.CODCOB ||\' - \'||PCCOB.COBRANCA as "cobranca" ' +
|
||||
' FROM PCCOB ' +
|
||||
' WHERE NVL(PCCOB.enviacobrancafv, \'N\') = \'S\' ' +
|
||||
' AND ( ( NOT EXISTS(SELECT PCCOBCLI.CODCOB FROM PCCOBCLI WHERE PCCOBCLI.CODCLI = :CODCLI ) AND ' +
|
||||
' ( PCCOB.NIVELVENDA <= ( SELECT C.NIVELVENDA FROM PCCLIENT, PCCOB C ' +
|
||||
' WHERE PCCLIENT.CODCLI = :CODCLI AND PCCLIENT.CODCOB = C.CODCOB ) ) ) OR ' +
|
||||
' EXISTS(SELECT PCCOBCLI.CODCOB FROM PCCOBCLI WHERE PCCOBCLI.CODCLI = :CODCLI AND PCCOBCLI.CODCOB = PCCOB.CODCOB ) ) ' +
|
||||
' ORDER BY PCCOB.CODCOB';
|
||||
const billings = await queryRunner.query(sql, [clienteId]);
|
||||
return billings;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetPartners(){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT ESTPARCEIRO.ID as "id" ' +
|
||||
' ,REGEXP_REPLACE(ESTPARCEIRO.CPF, \'[^0-9]\',\'\') || \' - \' ||ESTPARCEIRO.NOME as "name" ' +
|
||||
' FROM ESTPARCEIRO ' +
|
||||
' WHERE 1 = 1 ';
|
||||
const partners = await queryRunner.manager
|
||||
.query(sql);
|
||||
return partners;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetPreCustomer(idCart: string){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' select CPF as "document" '+
|
||||
' ,NOME as "name" ' +
|
||||
' ,TELEFONE as "phone" ' +
|
||||
' ,IDCART as "idCart" ' +
|
||||
' from estvendaprecliente ' +
|
||||
' where IDCART = :idcart ';
|
||||
console.log(idCart);
|
||||
const preCustomer = await queryRunner
|
||||
.query(sql, [idCart]);
|
||||
console.log(JSON.stringify(preCustomer));
|
||||
return preCustomer[0];
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetPlaces(){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT PCPRACA.CODPRACA as "id" ' +
|
||||
' ,PCPRACA.PRACA as "name" ' +
|
||||
' FROM PCPRACA ' +
|
||||
' WHERE 1 = 1';
|
||||
const places = await queryRunner.manager
|
||||
.query(sql);
|
||||
return places;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetStorePlaces(){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT PCPRACA.CODPRACA as "id" ' +
|
||||
' ,PCPRACA.PRACA as "name" ' +
|
||||
' FROM PCPRACA ' +
|
||||
' WHERE PCPRACA.CODPRACAPRINCIPAL = 1004';
|
||||
const places = await queryRunner.manager
|
||||
.query(sql);
|
||||
return places;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetRamo(){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT PCATIVI.CODATIV as "id" ' +
|
||||
' ,PCATIVI.RAMO as "name" ' +
|
||||
' FROM PCATIVI ' +
|
||||
' WHERE 1 = 1 ' +
|
||||
' ORDER BY PCATIVI.RAMO';
|
||||
const ramos = await queryRunner.manager
|
||||
.query(sql);
|
||||
return ramos;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetStates(state: string){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT PCESTADO.ESTADO as "name" FROM PCESTADO' +
|
||||
' WHERE PCESTADO.UF = :1';
|
||||
const states = await queryRunner.manager
|
||||
.query(sql, [state]);
|
||||
return states[0].name;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async getSupervisores(){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = `SELECT PCSUPERV.CODSUPERVISOR as "supervisorId"
|
||||
,PCSUPERV.NOME as "name"
|
||||
FROM PCSUPERV
|
||||
WHERE PCSUPERV.dtdemissao IS NULL`;
|
||||
const supervisores = await queryRunner.manager
|
||||
.query(sql);
|
||||
return supervisores;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
61
src/backoffice/measureproduct/measureproduct.controller.ts
Normal file
61
src/backoffice/measureproduct/measureproduct.controller.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { MeasureProductModel } from '../../domain/models/measureproduct.model';
|
||||
import { Controller, Get, Param, Put, Body, Post, Delete, HttpException, HttpStatus, Req } from "@nestjs/common";
|
||||
import { MeasureProductService } from './measureproduct.service';
|
||||
import { ResultModel } from 'src/domain/models/result.model';
|
||||
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('BackOffice')
|
||||
@Controller('v1/measure')
|
||||
export class MeasureProductController {
|
||||
|
||||
constructor(
|
||||
private measureProductService: MeasureProductService
|
||||
){}
|
||||
|
||||
@Get()
|
||||
@ApiExcludeEndpoint()
|
||||
async getAll(@Req() req) {
|
||||
try {
|
||||
if (req.query['query'] || req.query['query'] !== '')
|
||||
{
|
||||
const result = await this.measureProductService.findByDescription(req.query['query']);
|
||||
return new ResultModel(true, null, result, []);
|
||||
}
|
||||
const result = await this.measureProductService.findAll();
|
||||
return new ResultModel(true, null, result, []);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de medidas de produto.', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiExcludeEndpoint()
|
||||
async get(@Param('id') id) {
|
||||
try {
|
||||
const result =await this.measureProductService.find(id);
|
||||
return new ResultModel(true, null, result, []);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de medidas de produto.', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@ApiExcludeEndpoint()
|
||||
async put(@Param('id') id: number, @Body() body: MeasureProductModel) {
|
||||
return await this.measureProductService.update(id, body);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiExcludeEndpoint()
|
||||
async post(@Body() body: MeasureProductModel) {
|
||||
return await this.measureProductService.create(body);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiExcludeEndpoint()
|
||||
async delete(@Param('id') id: number) {
|
||||
return await this.measureProductService.delete(id);
|
||||
}
|
||||
}
|
||||
30
src/backoffice/measureproduct/measureproduct.module.ts
Normal file
30
src/backoffice/measureproduct/measureproduct.module.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Module } from "@nestjs/common";
|
||||
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
|
||||
import { MeasureProductController } from './measureproduct.controller';
|
||||
import { MeasureProductService } from './measureproduct.service';
|
||||
import { Estmedidaproduto } from 'src/domain/entity/tables/estmedidaproduto.entity';
|
||||
import { AuthService } from 'src/Auth/services/auth.service';
|
||||
import { JwtStrategy } from 'src/Auth/strategies/jwt-strategy';
|
||||
import { UserService } from 'src/Auth/services/user.service';
|
||||
import { User } from 'src/domain/entity/tables/estusuario.enity';
|
||||
|
||||
@Module({
|
||||
imports: [PassportModule.register({
|
||||
defaultStrategy: 'jwt'
|
||||
}),
|
||||
JwtModule.register({
|
||||
secretOrPrivateKey: '4557C0D7-DFB0-40DA-BF83-91A75103F7A9',
|
||||
signOptions: {
|
||||
expiresIn: 3600,
|
||||
}
|
||||
}),
|
||||
TypeOrmModule.forFeature([Estmedidaproduto, User])],
|
||||
controllers: [MeasureProductController],
|
||||
providers: [MeasureProductService, UserService, AuthService, JwtStrategy],
|
||||
})
|
||||
|
||||
export class MeasureProductModule {}
|
||||
85
src/backoffice/measureproduct/measureproduct.service.ts
Normal file
85
src/backoffice/measureproduct/measureproduct.service.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { NumberUtils } from '../../utils/number.utils';
|
||||
import { MeasureProductModel } from '../../domain/models/measureproduct.model';
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Estmedidaproduto } from 'src/domain/entity/tables/estmedidaproduto.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class MeasureProductService {
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Estmedidaproduto)
|
||||
private measureProductRepository: Repository<Estmedidaproduto>
|
||||
) { }
|
||||
|
||||
async findAll(): Promise<Estmedidaproduto[]> {
|
||||
return await this.measureProductRepository.find();
|
||||
}
|
||||
|
||||
async findByDescription(description: string): Promise<Estmedidaproduto[]> {
|
||||
return await this.measureProductRepository.createQueryBuilder("ESTMEDIDAPRODUTO").where(
|
||||
"DESCRICAO LIKE :description||'%'", { description }
|
||||
).getMany();
|
||||
}
|
||||
|
||||
async find(id: number): Promise<Estmedidaproduto> {
|
||||
return await this.measureProductRepository.createQueryBuilder("ESTMEDIDAPRODUTO").where(
|
||||
"IDMEDIDAPRODUTO = :IDMEDIDAPRODUTO", { IDMEDIDAPRODUTO: id }
|
||||
).getOne();
|
||||
}
|
||||
|
||||
async update(id: number, dados: MeasureProductModel): Promise<boolean> {
|
||||
await this.measureProductRepository
|
||||
.createQueryBuilder()
|
||||
.update('Estmedidaproduto')
|
||||
.set({ descricao: dados.descricao, abreviatura: dados.abreviatura, quantidade: dados.quantidade, nivel: dados.nivel })
|
||||
.where("IDMEDIDAPRODUTO = :IDMEDIDAPRODUTO", { IDMEDIDAPRODUTO: id })
|
||||
.execute();
|
||||
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
|
||||
async delete(id: number): Promise<boolean> {
|
||||
|
||||
await this.measureProductRepository
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from('Estmedidaproduto')
|
||||
.where("IDMEDIDAPRODUTO = :IDMEDIDAPRODUTO", { IDMEDIDAPRODUTO: id })
|
||||
.execute();
|
||||
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
|
||||
async create(dados: MeasureProductModel) {
|
||||
|
||||
try
|
||||
{
|
||||
const id = NumberUtils.getNewId(999999, 1);
|
||||
const newEstmedidaproduto = new Estmedidaproduto();
|
||||
newEstmedidaproduto.idmedidaproduto = id;
|
||||
newEstmedidaproduto.abreviatura = dados.abreviatura;
|
||||
newEstmedidaproduto.descricao = dados.descricao;
|
||||
newEstmedidaproduto.nivel = dados.nivel;
|
||||
newEstmedidaproduto.quantidade = dados.quantidade;
|
||||
await this.measureProductRepository
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into('Estmedidaproduto')
|
||||
.values(newEstmedidaproduto)
|
||||
.execute();
|
||||
return Promise.resolve(true);
|
||||
} catch( error ) {
|
||||
console.log(error);
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
15
src/backoffice/messages/messages.module.ts
Normal file
15
src/backoffice/messages/messages.module.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
https://docs.nestjs.com/modules
|
||||
*/
|
||||
|
||||
import { HttpModule, Module } from '@nestjs/common';
|
||||
import { WhatsappController } from './whatsapp/whatsapp.controller';
|
||||
import { WhatsappService } from './whatsapp/whatsapp.service';
|
||||
|
||||
@Module({
|
||||
imports: [HttpModule],
|
||||
controllers: [WhatsappController],
|
||||
providers: [WhatsappService,
|
||||
],
|
||||
})
|
||||
export class MessagesModule {}
|
||||
42
src/backoffice/messages/whatsapp/whatsapp.controller.ts
Normal file
42
src/backoffice/messages/whatsapp/whatsapp.controller.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
https://docs.nestjs.com/controllers#controllers
|
||||
*/
|
||||
|
||||
import { Body, Controller, HttpException, HttpStatus, Post } from '@nestjs/common';
|
||||
import { IndexActions } from 'src/domain/models/index-action.model';
|
||||
import { ResultModel } from 'src/domain/models/result.model';
|
||||
import { MessageWhatsApp } from '../../../domain/models/message-whatsapp.model';
|
||||
import { WhatsappService } from './whatsapp.service';
|
||||
import { ApiExcludeEndpoint } from '@nestjs/swagger';
|
||||
|
||||
@Controller('api/v1/message/whatsapp')
|
||||
export class WhatsappController {
|
||||
|
||||
constructor(private readonly whatsappService: WhatsappService){}
|
||||
|
||||
@Post('send')
|
||||
@ApiExcludeEndpoint()
|
||||
async sendMessage(@Body() message: MessageWhatsApp){
|
||||
try{
|
||||
const result = await this.whatsappService.sendMessage(message);
|
||||
console.log(result);
|
||||
return result;
|
||||
} catch(err){
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível enviar mensagem para o clientes.', {}, err),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Post('action')
|
||||
@ApiExcludeEndpoint()
|
||||
async createActionIndex(@Body() action: IndexActions){
|
||||
try{
|
||||
const result = await this.whatsappService.createActionIndex(action);
|
||||
console.log(result);
|
||||
return result;
|
||||
} catch(err){
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível criar pesquisa no INDEX para este cliente.', {}, err),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
58
src/backoffice/messages/whatsapp/whatsapp.service.ts
Normal file
58
src/backoffice/messages/whatsapp/whatsapp.service.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { HttpException, HttpService, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { IndexActions, } from 'src/domain/models/index-action.model';
|
||||
import { MessageWhatsApp } from '../../../domain/models/message-whatsapp.model';
|
||||
|
||||
@Injectable()
|
||||
export class WhatsappService {
|
||||
|
||||
constructor(private readonly httpService: HttpService) {}
|
||||
|
||||
async sendMessage(message: MessageWhatsApp ) {
|
||||
|
||||
// var fs = require('fs');
|
||||
//'Key ' + 'emFwanVydTppY0NtdXlFc3NvYmpqTkVLSFEwbw=='
|
||||
|
||||
const url = `https://takebroadcast.cs.blip.ai/api/v1/Notification`;
|
||||
try {
|
||||
const response = await this.httpService
|
||||
.post(url,
|
||||
JSON.stringify(message),
|
||||
{
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
'content-type': 'application/json',
|
||||
'accesskey': 'aWNDbXV5RXNzb2Jqak5FS0hRMG8=',
|
||||
'identifier': 'zapjuru'
|
||||
}
|
||||
})
|
||||
.toPromise();
|
||||
return response.data;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
throw new HttpException(e.message, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async createActionIndex(action: IndexActions) {
|
||||
const url = `https://indecx.com/v2/actions/185E2H/invites`;
|
||||
try {
|
||||
const response = await this.httpService
|
||||
.post(url,
|
||||
JSON.stringify(action),
|
||||
{
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
'content-type': 'application/json',
|
||||
'company-key': '$2b$10$rlMclOiWPwGgKavwPDFvCOYlDWujMi.h7BGizTxHPVjkn62VCgreO',
|
||||
}
|
||||
})
|
||||
.toPromise();
|
||||
return response.data;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
throw new HttpException(e.message, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
52
src/backoffice/ncm/ncm.controller.ts
Normal file
52
src/backoffice/ncm/ncm.controller.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { NcmService } from './ncm.service';
|
||||
import { Controller, Get, HttpException, HttpStatus, Param, Req } from '@nestjs/common';
|
||||
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
||||
import { ResultModel } from 'src/domain/models/result.model';
|
||||
|
||||
@ApiTags('BackOffice')
|
||||
@Controller('v1/ncm')
|
||||
export class NcmController {
|
||||
|
||||
constructor(private readonly ncmService: NcmService ){}
|
||||
|
||||
@Get()
|
||||
@ApiExcludeEndpoint()
|
||||
async getAll(@Req() req) {
|
||||
try {
|
||||
if (req.query['query'])
|
||||
{
|
||||
const result = await this.ncmService.findByDescription(req.query['query']);
|
||||
return new ResultModel(true, null, result, []);
|
||||
}
|
||||
return new ResultModel(false, 'Para pesquisar os NCMs é necessário informar pelo menos 3 caracteres.', null, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de dicionários', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@Get()
|
||||
async findAll() {
|
||||
try {
|
||||
const ncms = await this.ncmService.findAll();
|
||||
return new ResultModel(true, null, ncms, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de NCMs', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
@Get(":ncm")
|
||||
@ApiExcludeEndpoint()
|
||||
async findByNcm(@Param("ncm") ncm: string, @Req() req) {
|
||||
console.log(req.query);
|
||||
try {
|
||||
const result = await this.ncmService.find(ncm);
|
||||
return new ResultModel(true, null, result, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de NCMs', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
15
src/backoffice/ncm/ncm.module.ts
Normal file
15
src/backoffice/ncm/ncm.module.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Pcncm } from '../../domain/entity/tables/pcncm.entity';
|
||||
import { NcmController } from './ncm.controller';
|
||||
import { NcmService } from './ncm.service';
|
||||
import { CacheModule, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
@Module({
|
||||
imports: [CacheModule.register(),
|
||||
TypeOrmModule.forFeature([Pcncm])],
|
||||
controllers: [
|
||||
NcmController,],
|
||||
providers: [
|
||||
NcmService,],
|
||||
})
|
||||
export class NcmModule { }
|
||||
39
src/backoffice/ncm/ncm.service.ts
Normal file
39
src/backoffice/ncm/ncm.service.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
81
src/backoffice/product-type/product-type.controller.ts
Normal file
81
src/backoffice/product-type/product-type.controller.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { ProductTypeModel } from './../../domain/models/product-type.model';
|
||||
import { Body, Delete, Param, Post } from '@nestjs/common';
|
||||
import { ResultModel } from './../../domain/models/result.model';
|
||||
import { ProductTypeService } from './product-type.service';
|
||||
import { CacheInterceptor, Controller, Get, HttpException, HttpStatus, Put, Req, UseInterceptors } from '@nestjs/common';
|
||||
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('BackOffice')
|
||||
@Controller('v1/product-type')
|
||||
export class ProductTypeController {
|
||||
|
||||
constructor( private readonly productTypeService: ProductTypeService){}
|
||||
|
||||
@Get()
|
||||
@UseInterceptors(CacheInterceptor)
|
||||
@ApiExcludeEndpoint()
|
||||
async getAll(@Req() req) {
|
||||
try {
|
||||
if (req.query['query'])
|
||||
{
|
||||
const result = await this.productTypeService.findByType(req.query['query']);
|
||||
return new ResultModel(true, null, result, []);
|
||||
}
|
||||
const typeProducts = await this.productTypeService.findAll();
|
||||
return new ResultModel(true, null, typeProducts, []);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de tipos de produto.', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@UseInterceptors(CacheInterceptor)
|
||||
@ApiExcludeEndpoint()
|
||||
async getOne(@Param('id') id: number ) {
|
||||
try {
|
||||
const data = await this.productTypeService.findById(id);
|
||||
console.log(data);
|
||||
return new ResultModel(true, null, data, []);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar tipo de produto.', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
async update(@Param('id') id: number, @Body() dados: ProductTypeModel) {
|
||||
try {
|
||||
await this.productTypeService.update(id, dados);
|
||||
return new ResultModel(true, null, dados, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível atualizar tipo do produto.', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiExcludeEndpoint()
|
||||
//TODO: @UseInterceptors(new ValidadorInterceptor(new CreateDictionaryContract()))
|
||||
async post(@Body() dados: ProductTypeModel) {
|
||||
try {
|
||||
const newProductType = await await this.productTypeService.create(dados);
|
||||
return new ResultModel(true, null, newProductType, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível incluir tipo do produto.', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiExcludeEndpoint()
|
||||
async delete(@Param('id') id: number) {
|
||||
try {
|
||||
const result = await this.productTypeService.delete(id);
|
||||
return new ResultModel(true, 'Tipo do produto excluído com sucesso!', null, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível excluir tipo do produto.', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
15
src/backoffice/product-type/product-type.module.ts
Normal file
15
src/backoffice/product-type/product-type.module.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Esttipoproduto } from '../../domain/entity/tables/esttipoproduto.entity';
|
||||
import { ProductTypeController } from './product-type.controller';
|
||||
import { ProductTypeService } from './product-type.service';
|
||||
import { CacheModule, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
@Module({
|
||||
imports: [CacheModule.register(),
|
||||
TypeOrmModule.forFeature([Esttipoproduto])],
|
||||
controllers: [
|
||||
ProductTypeController,],
|
||||
providers: [
|
||||
ProductTypeService,],
|
||||
})
|
||||
export class ProductTypeModule { }
|
||||
165
src/backoffice/product-type/product-type.service.ts
Normal file
165
src/backoffice/product-type/product-type.service.ts
Normal file
@@ -0,0 +1,165 @@
|
||||
import { ProductTypeModel } from './../../domain/models/product-type.model';
|
||||
import { Esttipoproduto } from '../../domain/entity/tables/esttipoproduto.entity';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { getConnection, Repository } from 'typeorm';
|
||||
import { NumberUtils } from 'src/utils/number.utils';
|
||||
import { ResultModel } from 'src/domain/models/result.model';
|
||||
|
||||
@Injectable()
|
||||
export class ProductTypeService {
|
||||
constructor(
|
||||
@InjectRepository(Esttipoproduto)
|
||||
private productTypeRepository: Repository<Esttipoproduto>
|
||||
) { }
|
||||
|
||||
async findAll(): Promise<Esttipoproduto[]> {
|
||||
|
||||
const connection = getConnection();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
|
||||
return await queryRunner.manager
|
||||
.getRepository(Esttipoproduto)
|
||||
.createQueryBuilder('esttipoproduto')
|
||||
.select(['"esttipoproduto".idtipoproduto as "id"'
|
||||
, '"esttipoproduto".tipoproduto as "tipoProduto"'
|
||||
, '"esttipoproduto".siglaproduto as "siglaProduto"'
|
||||
, '"esttipoproduto".ncm as "ncm"'
|
||||
, '"esttipoproduto".codepto as "codigoDepartamento"'
|
||||
, '"esttipoproduto".codsec as "codigoSecao"'
|
||||
, '"esttipoproduto".codcategoria as "codigoCategoria"'
|
||||
, '"esttipoproduto".cest as "codigoCest"'
|
||||
, 'concat(concat("departamento".codepto, \'-\'),"departamento".descricao) as "departamentoDescricao"'
|
||||
, 'concat(concat("secao".codsec, \'-\'),"secao".descricao) as "secaoDescricao"'
|
||||
, 'concat(concat("categoria".codcategoria, \'-\'),"categoria".categoria) as "categoriaDescricao"'
|
||||
, '"registrocest".descricaocest as "cestDescricao"'])
|
||||
.innerJoin("esttipoproduto.departamento", "departamento")
|
||||
.innerJoin("esttipoproduto.secao", "secao")
|
||||
.innerJoin("esttipoproduto.categoria", "categoria", '"esttipoproduto".codsec = "categoria".codsec')
|
||||
.innerJoin("esttipoproduto.registrocest", "registrocest")
|
||||
.getRawMany();
|
||||
|
||||
}
|
||||
|
||||
async findByType(description: string): Promise<Esttipoproduto[]> {
|
||||
|
||||
const connection = getConnection();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
|
||||
const descriptionType = description + '%';
|
||||
|
||||
return await queryRunner.manager
|
||||
.getRepository(Esttipoproduto)
|
||||
.createQueryBuilder('esttipoproduto')
|
||||
.select(['"esttipoproduto".idtipoproduto as "id"'
|
||||
, '"esttipoproduto".tipoproduto as "tipoProduto"'
|
||||
, '"esttipoproduto".siglaproduto as "siglaProduto"'
|
||||
, '"esttipoproduto".ncm as "ncm"'
|
||||
, '"esttipoproduto".codepto as "codigoDepartamento"'
|
||||
, '"esttipoproduto".codsec as "codigoSecao"'
|
||||
, '"esttipoproduto".codcategoria as "codigoCategoria"'
|
||||
, '"esttipoproduto".cest as "codigoCest"'
|
||||
, 'concat(concat("departamento".codepto, \'-\'),"departamento".descricao) as "departamentoDescricao"'
|
||||
, 'concat(concat("secao".codsec, \'-\'),"secao".descricao) as "secaoDescricao"'
|
||||
, 'concat(concat("categoria".codcategoria, \'-\'),"categoria".categoria) as "categoriaDescricao"'
|
||||
, '"registrocest".descricaocest as "cestDescricao"'])
|
||||
.innerJoin("esttipoproduto.departamento", "departamento")
|
||||
.innerJoin("esttipoproduto.secao", "secao")
|
||||
.innerJoin("esttipoproduto.categoria", "categoria", '"esttipoproduto".codsec = "categoria".codsec')
|
||||
.innerJoin("esttipoproduto.registrocest", "registrocest")
|
||||
.where('"esttipoproduto".tipoproduto like :type', { type: descriptionType })
|
||||
.getRawMany();
|
||||
|
||||
}
|
||||
|
||||
async findById(id: number): Promise<Esttipoproduto> {
|
||||
|
||||
const connection = getConnection();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
try{
|
||||
return await queryRunner.manager
|
||||
.getRepository(Esttipoproduto)
|
||||
.createQueryBuilder('esttipoproduto')
|
||||
.select(['"esttipoproduto".idtipoproduto as "id"'
|
||||
, '"esttipoproduto".tipoproduto as "tipoProduto"'
|
||||
, '"esttipoproduto".siglaproduto as "siglaProduto"'
|
||||
, '"esttipoproduto".ncm as "ncm"'
|
||||
, '"esttipoproduto".codepto as "codigoDepartamento"'
|
||||
, '"esttipoproduto".codsec as "codigoSecao"'
|
||||
, '"esttipoproduto".codcategoria as "codigoCategoria"'
|
||||
, '"esttipoproduto".cest as "codigoCest"'
|
||||
, 'concat(concat("departamento".codepto, \'-\'),"departamento".descricao) as "departamentoDescricao"'
|
||||
, 'concat(concat("secao".codsec, \'-\'),"secao".descricao) as "secaoDescricao"'
|
||||
, 'concat(concat("categoria".codcategoria, \'-\'),"categoria".categoria) as "categoriaDescricao"'
|
||||
, 'concat(concat(\"registrocest\".codcest, \'-\'), substr(\"registrocest\".descricaocest,1,80)) as "cestDescricao"'
|
||||
, 'concat(concat("registroNcm".codncmex, \' - \'),SUBSTR("registroNcm".descricao,1,100)) as "ncmDescricao"'])
|
||||
.innerJoin("esttipoproduto.departamento", "departamento")
|
||||
.innerJoin("esttipoproduto.secao", "secao")
|
||||
.innerJoin("esttipoproduto.categoria", "categoria", '"esttipoproduto".codsec = "categoria".codsec')
|
||||
.innerJoin("esttipoproduto.registrocest", "registrocest")
|
||||
.innerJoin("esttipoproduto.registroNcm", "registroNcm")
|
||||
.where('"esttipoproduto".idtipoproduto = :id', { id })
|
||||
.getRawOne();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async update(id: number, dados: ProductTypeModel) {
|
||||
|
||||
return await this.productTypeRepository
|
||||
.createQueryBuilder()
|
||||
.update(Esttipoproduto)
|
||||
.set({ tipoProduto: dados.type, ncm: dados.ncm, codigoDepartamento: dados.idDepartment, codigoSecao: dados.idSection,
|
||||
codigoCategoria: dados.idCategory, sigla: dados.sigla, cest: dados.idCest })
|
||||
.where("ID = :id", { id })
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
||||
async delete(id: number) {
|
||||
|
||||
return await getConnection()
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(Esttipoproduto)
|
||||
.where("ID = :id", { id })
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
||||
async create(dados: ProductTypeModel) {
|
||||
|
||||
try
|
||||
{
|
||||
const id = NumberUtils.getNewId(9999, 1);
|
||||
const newProductType = new Esttipoproduto();
|
||||
|
||||
newProductType.idTipoProduto = id;
|
||||
newProductType.tipoProduto = dados.type;
|
||||
newProductType.ncm = dados.ncm;
|
||||
newProductType.sigla = dados.sigla;
|
||||
newProductType.codigoDepartamento = dados.idDepartment;
|
||||
newProductType.codigoSecao = dados.idSection;
|
||||
newProductType.codigoCategoria = dados.idCategory;
|
||||
newProductType.cest = dados.idCest;
|
||||
|
||||
await getConnection()
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(Esttipoproduto)
|
||||
.values(newProductType)
|
||||
.execute();
|
||||
|
||||
return newProductType;
|
||||
|
||||
} catch ( erro ) {
|
||||
console.log(erro);
|
||||
return new ResultModel(true, "Ops! Houve um erro ao criar o Dicionário.", null, erro);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
34
src/backoffice/product/product.controller.ts
Normal file
34
src/backoffice/product/product.controller.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Body, Controller, Get, HttpException, HttpStatus, Param, Post } from '@nestjs/common';
|
||||
import { ProductService } from './product.service';
|
||||
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('BackOffice')
|
||||
@Controller('api/v1/product')
|
||||
export class ProductController {
|
||||
|
||||
constructor (private readonly productService: ProductService){}
|
||||
|
||||
@Get(':id')
|
||||
@ApiExcludeEndpoint()
|
||||
getProduct(@Param('id') id: number){
|
||||
try {
|
||||
return this.productService.getProduct(id);
|
||||
}
|
||||
catch(error){
|
||||
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@Post('exposeded')
|
||||
@ApiExcludeEndpoint()
|
||||
createExposedProduct(@Body() data: any){
|
||||
try {
|
||||
return this.productService.createExposededProduct(data);
|
||||
}
|
||||
catch(error){
|
||||
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
48
src/backoffice/product/product.service.ts
Normal file
48
src/backoffice/product/product.service.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { connectionOptions } from 'src/configs/typeorm.config';
|
||||
import { Product } from 'src/domain/entity/tables/pcprodut.entity';
|
||||
import { Connection, getConnection } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class ProductService {
|
||||
|
||||
async getProduct(id: number) {
|
||||
const connection = getConnection();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const product = await queryRunner.manager
|
||||
.getRepository(Product)
|
||||
.createQueryBuilder('pcprodut')
|
||||
.innerJoinAndSelect('pcprodut.brand', 'brand')
|
||||
.where("\"pcprodut\".codprod = :id", { id: id })
|
||||
.getOne();
|
||||
return product;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
async createExposededProduct(data: any) {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
try {
|
||||
const sqlInsert = `INSERT INTO ESTPRODUTOEXPOSICAO ( CODFILIAL, DATA, CODAUXILIAR )
|
||||
VALUES ( '4', TRUNC(SYSDATE), ${data.codigoean})`;
|
||||
await queryRunner.query(sqlInsert);
|
||||
await queryRunner.commitTransaction();
|
||||
} catch (err) {
|
||||
await queryRunner.commitTransaction();
|
||||
console.log(err);
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
24
src/backoffice/section/section.controller.ts
Normal file
24
src/backoffice/section/section.controller.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { SectionService } from './section.service';
|
||||
import { CacheInterceptor, Controller, Get, HttpException, HttpStatus, Param, UseInterceptors } from '@nestjs/common';
|
||||
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
||||
import { ResultModel } from 'src/domain/models/result.model';
|
||||
|
||||
@ApiTags('BackOffice')
|
||||
@Controller('v1/section')
|
||||
export class SectionController {
|
||||
|
||||
constructor(private readonly sectionService: SectionService){}
|
||||
|
||||
@Get(':idDepartment')
|
||||
@UseInterceptors(CacheInterceptor)
|
||||
@ApiExcludeEndpoint()
|
||||
async getAll(@Param('idDepartment') idDepartment: number) {
|
||||
try {
|
||||
const sections = await this.sectionService.find(idDepartment);
|
||||
return new ResultModel(true, null, sections, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de seções', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
14
src/backoffice/section/section.module.ts
Normal file
14
src/backoffice/section/section.module.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { CacheModule, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Pcsecao } from 'src/domain/entity/tables/pcsecao.entity';
|
||||
import { SectionController } from './section.controller';
|
||||
import { SectionService } from './section.service';
|
||||
|
||||
@Module({
|
||||
imports: [ CacheModule.register(),
|
||||
TypeOrmModule.forFeature([Pcsecao])],
|
||||
controllers: [SectionController,],
|
||||
providers: [SectionService,],
|
||||
|
||||
})
|
||||
export class SectionModule { }
|
||||
22
src/backoffice/section/section.service.ts
Normal file
22
src/backoffice/section/section.service.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Pcsecao } from 'src/domain/entity/tables/pcsecao.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class SectionService {
|
||||
constructor( @InjectRepository(Pcsecao)
|
||||
private sectionRepository: Repository<Pcsecao>){}
|
||||
|
||||
async find(idDepartment: number): Promise<Pcsecao[]> {
|
||||
return await this.sectionRepository
|
||||
.createQueryBuilder('pcsecao')
|
||||
.select('"pcsecao".codsec', 'codigoSecao')
|
||||
.addSelect('concat(concat("pcsecao".codsec, \'-\'),"pcsecao".descricao)', 'descricaoSecao')
|
||||
//.addSelect('concat(concat(concat("pcsecao".descricao, \' (\'),"pcsecao".codsec),\')\')', 'descricaoSecao')
|
||||
.where("codepto = :codepto", {codepto: idDepartment})
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user