fix: corregir tipado para typecheck en nueva.ts, ver.ts y group-sync.ts

Co-authored-by: aider (openrouter/openai/gpt-5) <aider@aider.chat>
main
brobert 1 month ago
parent 16e35c6827
commit 97624ad923

@ -222,7 +222,7 @@ export async function handleNueva(context: Ctx, deps: { db: Database }): Promise
responses.push({
recipient: createdBy,
message: [ackLines.join('\n'), '', CTA_HELP].join('\n'),
mentions: mentionsForSending.length > 0 ? mentionsForSending : undefined
...(mentionsForSending.length > 0 ? { mentions: mentionsForSending } : {})
});
// 2) DM a cada asignado (excluyendo al creador para evitar duplicados)

@ -64,7 +64,8 @@ export async function handleVer(context: Ctx): Promise<Msg[]> {
: `${t.assignees!.length > 1 ? '👥' : '👤'} ${names.join(', ')}`;
const isOverdue = t.due_date ? t.due_date < today : false;
const datePart = t.due_date ? `${isOverdue ? `${ICONS.warn} ` : ''}${ICONS.date} ${formatDDMM(t.due_date)}` : '';
return `- ${codeId(t.id, t.display_code)} ${t.description || '(sin descripción)'}${datePart}${owner}`;
const dc = (t as any)?.display_code as number | undefined;
return `- ${codeId(t.id, dc)} ${t.description || '(sin descripción)'}${datePart}${owner}`;
}));
sections.push(...rendered);
sections.push('');
@ -157,7 +158,8 @@ export async function handleVer(context: Ctx): Promise<Msg[]> {
: `${t.assignees!.length > 1 ? '👥' : '👤'} ${names.join(', ')}`;
const isOverdue = t.due_date ? t.due_date < today : false;
const datePart = t.due_date ? `${isOverdue ? `${ICONS.warn} ` : ''}${ICONS.date} ${formatDDMM(t.due_date)}` : '';
return `- ${codeId(t.id, t.display_code)} ${t.description || '(sin descripción)'}${datePart}${owner}`;
const dc = (t as any)?.display_code as number | undefined;
return `- ${codeId(t.id, dc)} ${t.description || '(sin descripción)'}${datePart}${owner}`;
}));
sections.push(...rendered);
sections.push('');

@ -229,7 +229,7 @@ export class GroupSyncService {
const response = await fetch(url, {
method: 'GET',
headers: {
apikey: process.env.EVOLUTION_API_KEY,
apikey: String(process.env.EVOLUTION_API_KEY || ''),
},
httpVersion: '2',
timeout: 320000 // 120 second timeout
@ -252,19 +252,19 @@ export class GroupSyncService {
// Parse response which could be either:
// 1. Direct array of groups: [{group1}, {group2}]
// 2. Or wrapped response: {status, message, response}
let groups;
let groups: EvolutionGroup[] = [];
try {
const parsed = JSON.parse(rawResponse);
if (Array.isArray(parsed)) {
// Case 1: Direct array response
groups = parsed;
groups = parsed as EvolutionGroup[];
console.log(' Received direct array of', groups.length, 'groups');
} else if (parsed.response && Array.isArray(parsed.response)) {
// Case 2: Wrapped response
if (parsed.status !== 'success') {
throw new Error(`API error: ${parsed.message || 'Unknown error'}`);
}
groups = parsed.response;
groups = parsed.response as EvolutionGroup[];
console.log(' Received wrapped response with', groups.length, 'groups');
} else {
throw new Error('Invalid API response format - expected array or wrapped response');
@ -344,8 +344,8 @@ export class GroupSyncService {
}
private static getActiveGroupsCount(): number {
const result = this.dbInstance.prepare('SELECT COUNT(*) as count FROM groups WHERE active = TRUE AND COALESCE(is_community,0) = 0 AND COALESCE(archived,0) = 0').get();
return result?.count || 0;
const result = this.dbInstance.prepare('SELECT COUNT(*) as count FROM groups WHERE active = TRUE AND COALESCE(is_community,0) = 0 AND COALESCE(archived,0) = 0').get() as { count?: number } | undefined;
return Number(result?.count || 0);
}
static async checkInitialGroups(): Promise<void> {
@ -429,7 +429,7 @@ export class GroupSyncService {
});
for (const group of groups) {
const existing = this.dbInstance.prepare('SELECT 1 FROM groups WHERE id = ?').get(group.id);
const existing = this.dbInstance.prepare('SELECT 1 FROM groups WHERE id = ?').get((group as EvolutionGroup).id);
console.log('Checking group:', group.id, 'exists:', !!existing);
const isCommunityFlag = !!(((group as any)?.isCommunity) || ((group as any)?.is_community) || ((group as any)?.isCommunityAnnounce) || ((group as any)?.is_community_announce));
@ -437,13 +437,13 @@ export class GroupSyncService {
if (existing) {
const updateResult = this.dbInstance.prepare(
'UPDATE groups SET name = ?, community_id = COALESCE(?, community_id), is_community = ?, active = TRUE, last_verified = CURRENT_TIMESTAMP WHERE id = ?'
).run(group.subject, group.linkedParent || null, isCommunityFlag ? 1 : 0, group.id);
).run((group as EvolutionGroup).subject, (group as EvolutionGroup).linkedParent || null, isCommunityFlag ? 1 : 0, (group as EvolutionGroup).id);
console.log('Updated group:', group.id, 'result:', updateResult);
updated++;
} else {
const insertResult = this.dbInstance.prepare(
'INSERT INTO groups (id, community_id, name, active, is_community) VALUES (?, ?, ?, TRUE, ?)'
).run(group.id, (group.linkedParent ?? ''), group.subject, isCommunityFlag ? 1 : 0);
).run((group as EvolutionGroup).id, (((group as EvolutionGroup).linkedParent ?? '')), (group as EvolutionGroup).subject, isCommunityFlag ? 1 : 0);
console.log('Added group:', group.id, 'result:', insertResult);
added++;
}
@ -520,7 +520,7 @@ export class GroupSyncService {
const r1 = await fetch(url1, {
method: 'GET',
headers: { apikey: process.env.EVOLUTION_API_KEY },
headers: { apikey: String(process.env.EVOLUTION_API_KEY || '') },
httpVersion: '2',
timeout: 320000
});
@ -601,7 +601,7 @@ export class GroupSyncService {
const response = await fetch(url, {
method: 'GET',
headers: { apikey: process.env.EVOLUTION_API_KEY },
headers: { apikey: String(process.env.EVOLUTION_API_KEY || '') },
httpVersion: '2',
timeout: 320000
});

@ -138,7 +138,7 @@ export class MaintenanceService {
const stateUrl = `${url}/instance/connectionState/${instance}`;
const restartUrl = `${url}/instance/restart/${instance}`;
const headers = { apikey: apiKey };
const headers: HeadersInit = { apikey: String(apiKey || '') };
try {
const response = await fetch(stateUrl, { method: 'GET', headers });

Loading…
Cancel
Save