feat: updates api evolution for docker

This commit is contained in:
João Victor Souza 2024-12-27 10:40:04 -03:00
parent 1665654676
commit 2fb6318011
6 changed files with 45 additions and 20 deletions

View File

@ -1,5 +1,7 @@
.git .git
*Dockerfile* *Dockerfile*
*docker-compose* *docker-compose*
package-lock.json
.env
node_modules node_modules
dist dist

View File

@ -1,24 +1,36 @@
#!/bin/bash #!/bin/bash
# Fonte das variáveis de ambiente
source ./Docker/scripts/env_functions.sh source ./Docker/scripts/env_functions.sh
# Carregar variáveis de ambiente se não estiver no ambiente Docker
if [ "$DOCKER_ENV" != "true" ]; then if [ "$DOCKER_ENV" != "true" ]; then
export_env_vars export_env_vars
fi fi
# Verificar se o banco de dados é PostgreSQL ou MySQL
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]; then if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]; then
export DATABASE_URL export DATABASE_URL
echo "Deploying migrations for $DATABASE_PROVIDER" echo "Deploying migrations for $DATABASE_PROVIDER"
echo "Database URL: $DATABASE_URL" echo "Database URL: $DATABASE_URL"
# rm -rf ./prisma/migrations
# cp -r ./prisma/$DATABASE_PROVIDER-migrations ./prisma/migrations # Verificar se há migrações pendentes com Prisma
npm run db:deploy MIGRATION_STATUS=$(npx prisma migrate status)
if [ $? -ne 0 ]; then
echo "Migration failed" if echo "$MIGRATION_STATUS" | grep -q "Pending"; then
exit 1 echo "Migrações pendentes encontradas. Executando deploy..."
npm run db:deploy # Aplica as migrações pendentes
if [ $? -ne 0 ]; then
echo "Migration failed"
exit 1
else
echo "Migration succeeded"
fi
else else
echo "Migration succeeded" echo "Nenhuma migração pendente. Pulando deploy."
fi fi
# Gerar o Prisma Client após o deploy
npm run db:generate npm run db:generate
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Prisma generate failed" echo "Prisma generate failed"
@ -26,6 +38,7 @@ if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]
else else
echo "Prisma generate succeeded" echo "Prisma generate succeeded"
fi fi
else else
echo "Error: Database provider $DATABASE_PROVIDER invalid." echo "Error: Database provider $DATABASE_PROVIDER invalid."
exit 1 exit 1

View File

@ -1,7 +1,7 @@
FROM node:20-alpine AS builder FROM node:20-alpine AS builder
RUN apk update && \ RUN apk update && \
apk add git ffmpeg wget curl bash apk add --no-cache git ffmpeg wget curl bash openssl
LABEL version="2.2.0" description="Api to control whatsapp features through http requests." LABEL version="2.2.0" description="Api to control whatsapp features through http requests."
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes" LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"

View File

@ -14,7 +14,9 @@
"db:generate": "node runWithProvider.js \"npx prisma generate --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"", "db:generate": "node runWithProvider.js \"npx prisma generate --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"",
"db:deploy": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate deploy --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"", "db:deploy": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate deploy --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"",
"db:studio": "node runWithProvider.js \"npx prisma studio --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"", "db:studio": "node runWithProvider.js \"npx prisma studio --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"",
"db:migrate:dev": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate dev --schema ./prisma/DATABASE_PROVIDER-schema.prisma && cp -r ./prisma/migrations/* ./prisma/DATABASE_PROVIDER-migrations\"" "db:migrate:dev": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate dev --schema ./prisma/DATABASE_PROVIDER-schema.prisma && cp -r ./prisma/migrations/* ./prisma/DATABASE_PROVIDER-migrations\"",
"docker:build": "docker build -t joaovictorsouza/evolution-api:latest .",
"docker:push": "docker push joaovictorsouza/evolution-api:latest"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -51,7 +53,7 @@
"@ffmpeg-installer/ffmpeg": "^1.1.0", "@ffmpeg-installer/ffmpeg": "^1.1.0",
"@figuro/chatwoot-sdk": "^1.1.16", "@figuro/chatwoot-sdk": "^1.1.16",
"@hapi/boom": "^10.0.1", "@hapi/boom": "^10.0.1",
"@prisma/client": "^5.15.0", "@prisma/client": "^6.1.0",
"@sentry/node": "^8.28.0", "@sentry/node": "^8.28.0",
"amqplib": "^0.10.3", "amqplib": "^0.10.3",
"axios": "^1.6.5", "axios": "^1.6.5",
@ -82,7 +84,7 @@
"openai": "^4.52.7", "openai": "^4.52.7",
"pg": "^8.11.3", "pg": "^8.11.3",
"pino": "^8.11.0", "pino": "^8.11.0",
"prisma": "^5.15.0", "prisma": "^6.1.0",
"pusher": "^5.2.0", "pusher": "^5.2.0",
"qrcode": "^1.5.1", "qrcode": "^1.5.1",
"qrcode-terminal": "^0.12.0", "qrcode-terminal": "^0.12.0",

View File

@ -72,14 +72,15 @@ export class WAMonitoringService {
const clientName = this.configService.get<Database>('DATABASE').CONNECTION.CLIENT_NAME; const clientName = this.configService.get<Database>('DATABASE').CONNECTION.CLIENT_NAME;
const where = instanceNames && instanceNames.length > 0 const where =
? { instanceNames && instanceNames.length > 0
name: { ? {
in: instanceNames, name: {
}, in: instanceNames,
clientName, },
} clientName,
: { clientName }; }
: { clientName };
const instances = await this.prismaRepository.instance.findMany({ const instances = await this.prismaRepository.instance.findMany({
where, where,

View File

@ -131,7 +131,14 @@ export declare namespace wa {
export type StatusMessage = 'ERROR' | 'PENDING' | 'SERVER_ACK' | 'DELIVERY_ACK' | 'READ' | 'DELETED' | 'PLAYED'; export type StatusMessage = 'ERROR' | 'PENDING' | 'SERVER_ACK' | 'DELIVERY_ACK' | 'READ' | 'DELETED' | 'PLAYED';
} }
export const TypeMediaMessage = ['imageMessage', 'documentMessage', 'audioMessage', 'videoMessage', 'stickerMessage', 'ptvMessage']; export const TypeMediaMessage = [
'imageMessage',
'documentMessage',
'audioMessage',
'videoMessage',
'stickerMessage',
'ptvMessage',
];
export const MessageSubtype = [ export const MessageSubtype = [
'ephemeralMessage', 'ephemeralMessage',