corrigir erro na edição do beneficiário
This commit is contained in:
+3
-3
@@ -267,8 +267,8 @@ sudo -u refood DATABASE_URL=local.db npm run db:push
|
||||
# 5. Compilar o projeto novamente
|
||||
sudo -u refood npm run build
|
||||
|
||||
# 6. Recarregar o PM2 de forma segura (Zero Downtime)
|
||||
sudo -u refood pm2 reload refood-one
|
||||
# 6. Recarregar o PM2 de forma segura (Zero Downtime) e atualizar variáveis de ambiente
|
||||
sudo -u refood pm2 reload refood-one --update-env
|
||||
```
|
||||
*Dica: O comando `pm2 reload` reinicia os processos de forma faseada, garantindo que o seu site não fica fora do ar (zero downtime) enquanto a atualização é aplicada.*
|
||||
*Dica: O comando `pm2 reload` com a flag `--update-env` reinicia os processos de forma faseada, garantindo que o seu site não fica fora do ar (zero downtime) ao mesmo tempo que carrega as novas alterações feitas no ficheiro `.env`.*
|
||||
|
||||
|
||||
@@ -148,6 +148,7 @@ export async function syncBeneficiaries(): Promise<{ success: boolean; count: nu
|
||||
const parentOdooId = Array.isArray(result.parent_id) ? result.parent_id[0] : null;
|
||||
const isParent = parentOdooId === null;
|
||||
const activeStatus = result.active !== false ? 'ativo' : 'inativo';
|
||||
const beneficiaryNumber = isParent ? parsedNumber : null;
|
||||
|
||||
// Check if beneficiary with odooId already exists
|
||||
const existingById = db
|
||||
@@ -162,7 +163,7 @@ export async function syncBeneficiaries(): Promise<{ success: boolean; count: nu
|
||||
.set({
|
||||
name,
|
||||
contact,
|
||||
number: parsedNumber !== null ? parsedNumber : existingById.number,
|
||||
number: beneficiaryNumber,
|
||||
odooNumber,
|
||||
parentOdooId,
|
||||
isParent,
|
||||
@@ -175,7 +176,7 @@ export async function syncBeneficiaries(): Promise<{ success: boolean; count: nu
|
||||
// Insert new
|
||||
db.insert(schema.beneficiaries)
|
||||
.values({
|
||||
number: parsedNumber,
|
||||
number: beneficiaryNumber,
|
||||
name,
|
||||
contact,
|
||||
odooId,
|
||||
|
||||
@@ -74,14 +74,15 @@ export const actions: Actions = {
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if new number conflicts with another beneficiary (excluding self)
|
||||
// Check if new number conflicts with another beneficiary (excluding self and dependents)
|
||||
const existingConflict = db
|
||||
.select()
|
||||
.from(schema.beneficiaries)
|
||||
.where(
|
||||
and(
|
||||
eq(schema.beneficiaries.number, number),
|
||||
ne(schema.beneficiaries.id, id)
|
||||
ne(schema.beneficiaries.id, id),
|
||||
eq(schema.beneficiaries.isParent, true)
|
||||
)
|
||||
)
|
||||
.get();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { db } from '$lib/server/db';
|
||||
import * as schema from '$lib/server/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { eq, and } from 'drizzle-orm';
|
||||
import { fail, redirect } from '@sveltejs/kit';
|
||||
import type { Actions } from './$types';
|
||||
|
||||
@@ -39,11 +39,16 @@ export const actions: Actions = {
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if number is unique
|
||||
// Check if number is unique among parent/main beneficiaries
|
||||
const existing = db
|
||||
.select()
|
||||
.from(schema.beneficiaries)
|
||||
.where(eq(schema.beneficiaries.number, number))
|
||||
.where(
|
||||
and(
|
||||
eq(schema.beneficiaries.number, number),
|
||||
eq(schema.beneficiaries.isParent, true)
|
||||
)
|
||||
)
|
||||
.get();
|
||||
|
||||
if (existing) {
|
||||
|
||||
Reference in New Issue
Block a user