Alterado end point api/v1/delivery/schedule para mostrar a capacidade e saldo da capacidade com 3 casas decimais e criado peso adicional para mostrar a data de entrega na abertura da venda

This commit is contained in:
eduardoestevao-appsoluti
2025-03-11 17:16:05 -03:00
parent 62f4c767dd
commit 0936c239b9
180 changed files with 18502 additions and 18441 deletions

View File

@@ -1,64 +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);
}
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);
}
}

View File

@@ -1,30 +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],
})
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 {}

View File

@@ -1,84 +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);
}
}
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);
}
}
}

View File

@@ -1,61 +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);
}
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);
}
}

View File

@@ -1,30 +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],
})
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 {}

View File

@@ -1,85 +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);
}
}
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);
}
}
}

View File

@@ -1,15 +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 {}
/*
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 {}

View File

@@ -1,42 +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);
}
}
}
/*
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);
}
}
}

View File

@@ -1,58 +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);
}
}
}
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);
}
}
}