CognxSafeTrack commited on
Commit ·
4a46753
1
Parent(s): a966957
chore: cleanup old scripts and sync files
Browse files
apps/api/src/scripts/fix-types.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
| 1 |
-
import * as fs from 'fs';
|
| 2 |
-
import * as path from 'path';
|
| 3 |
-
|
| 4 |
-
function replaceInFile(filePath: string, replacements: [RegExp, string][]) {
|
| 5 |
-
const fullPath = path.resolve(__dirname, '../..', filePath);
|
| 6 |
-
if (!fs.existsSync(fullPath)) return;
|
| 7 |
-
let content = fs.readFileSync(fullPath, 'utf8');
|
| 8 |
-
for (const [regex, replacement] of replacements) {
|
| 9 |
-
content = content.replace(regex, replacement);
|
| 10 |
-
}
|
| 11 |
-
fs.writeFileSync(fullPath, content);
|
| 12 |
-
console.log(`Fixed: ${filePath}`);
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
replaceInFile('src/index.ts', [
|
| 16 |
-
[/e\?\.message/g, '(e as any)?.message']
|
| 17 |
-
]);
|
| 18 |
-
|
| 19 |
-
replaceInFile('src/routes/ai.ts', [
|
| 20 |
-
[/err\?\.name/g, '(err as any)?.name'],
|
| 21 |
-
[/err\.retryAfterMs/g, '(err as any).retryAfterMs'],
|
| 22 |
-
[/err\.stack/g, '(err as Error).stack']
|
| 23 |
-
]);
|
| 24 |
-
|
| 25 |
-
replaceInFile('src/scripts/sync-content.ts', [
|
| 26 |
-
[/err\.stack/g, '(err as Error).stack']
|
| 27 |
-
]);
|
| 28 |
-
|
| 29 |
-
replaceInFile('src/scripts/test-e2e-journey.ts', [
|
| 30 |
-
[/e\.response\?\.data\?\.error/g, '(e as any).response?.data?.error']
|
| 31 |
-
]);
|
| 32 |
-
|
| 33 |
-
replaceInFile('src/services/ai/openai-provider.ts', [
|
| 34 |
-
[/err\?\.status/g, '(err as any)?.status'],
|
| 35 |
-
[/err\?\.code/g, '(err as any)?.code'],
|
| 36 |
-
[/err\?\.headers/g, '(err as any)?.headers'],
|
| 37 |
-
[/err\?\.name/g, '(err as any)?.name'],
|
| 38 |
-
[/err\?\.message/g, '(err as any)?.message'],
|
| 39 |
-
[/err\?\.stack/g, '(err as any)?.stack']
|
| 40 |
-
]);
|
| 41 |
-
|
| 42 |
-
replaceInFile('src/services/whatsapp.ts', [
|
| 43 |
-
[/cacheErr\.message/g, '(cacheErr as Error).message']
|
| 44 |
-
]);
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apps/api/src/scripts/migrate-json-to-sql.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
| 1 |
-
import { PrismaClient } from '@repo/database';
|
| 2 |
-
import { logger } from '../logger';
|
| 3 |
-
import * as dotenv from 'dotenv';
|
| 4 |
-
import * as path from 'path';
|
| 5 |
-
|
| 6 |
-
// Root .env contains the real Neon URL
|
| 7 |
-
dotenv.config({ path: path.join(__dirname, '../../../../.env') });
|
| 8 |
-
|
| 9 |
-
const prisma = new PrismaClient();
|
| 10 |
-
|
| 11 |
-
async function migrate() {
|
| 12 |
-
logger.info('🚀 Starting JSON to SQL Migration (Neon)...');
|
| 13 |
-
|
| 14 |
-
// 1. Migrate Badges (UserProgress.badges -> UserBadge)
|
| 15 |
-
const progressWithBadges = await prisma.userProgress.findMany({
|
| 16 |
-
where: {
|
| 17 |
-
badges: { not: undefined }
|
| 18 |
-
}
|
| 19 |
-
});
|
| 20 |
-
|
| 21 |
-
logger.info(`Found ${progressWithBadges.length} UserProgress records with badges JSON.`);
|
| 22 |
-
|
| 23 |
-
for (const progress of progressWithBadges) {
|
| 24 |
-
const badges = progress.badges as any;
|
| 25 |
-
if (Array.isArray(badges)) {
|
| 26 |
-
for (const badgeName of badges) {
|
| 27 |
-
if (typeof badgeName !== 'string') continue;
|
| 28 |
-
|
| 29 |
-
const existing = await (prisma as any).userBadge.findFirst({
|
| 30 |
-
where: {
|
| 31 |
-
userProgressId: progress.id,
|
| 32 |
-
name: badgeName
|
| 33 |
-
}
|
| 34 |
-
});
|
| 35 |
-
|
| 36 |
-
if (!existing) {
|
| 37 |
-
await (prisma as any).userBadge.create({
|
| 38 |
-
data: {
|
| 39 |
-
userProgressId: progress.id,
|
| 40 |
-
name: badgeName
|
| 41 |
-
}
|
| 42 |
-
});
|
| 43 |
-
logger.info(`Migrated badge "${badgeName}" for UserProgress ${progress.id}`);
|
| 44 |
-
}
|
| 45 |
-
}
|
| 46 |
-
}
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/*
|
| 50 |
-
// 2. Migrate Team Members (BusinessProfile.teamMembers -> TeamMember)
|
| 51 |
-
// DEPRECATED: Field removed from schema
|
| 52 |
-
...
|
| 53 |
-
*/
|
| 54 |
-
|
| 55 |
-
logger.info('✅ Neon data migration completed successfully!');
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
migrate()
|
| 59 |
-
.catch(err => {
|
| 60 |
-
logger.error('❌ Migration failed:', err);
|
| 61 |
-
process.exit(1);
|
| 62 |
-
})
|
| 63 |
-
.finally(async () => {
|
| 64 |
-
await prisma.$disconnect();
|
| 65 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apps/api/src/scripts/purge-any.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
| 1 |
-
import * as fs from 'fs';
|
| 2 |
-
import * as path from 'path';
|
| 3 |
-
|
| 4 |
-
function processDirectory(directory: string) {
|
| 5 |
-
fs.readdirSync(directory).forEach(file => {
|
| 6 |
-
const fullPath = path.join(directory, file);
|
| 7 |
-
if (fs.statSync(fullPath).isDirectory()) {
|
| 8 |
-
processDirectory(fullPath);
|
| 9 |
-
} else if (fullPath.endsWith('.ts') && !fullPath.includes('node_modules') && !fullPath.includes('dist')) {
|
| 10 |
-
processFile(fullPath);
|
| 11 |
-
}
|
| 12 |
-
});
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
function processFile(filePath: string) {
|
| 16 |
-
let content = fs.readFileSync(filePath, 'utf-8');
|
| 17 |
-
let original = content;
|
| 18 |
-
|
| 19 |
-
// 1. Replace catch (e: unknown) with catch (error: unknown)
|
| 20 |
-
content = content.replace(/catch\s*\(\s*([a-zA-Z0-9_]+)\s*:\s*any\s*\)/g, 'catch ($1: unknown)');
|
| 21 |
-
|
| 22 |
-
// 2. Replace common (error instanceof Error ? (error instanceof Error ? error.message : String(error)) : String(error)) usages if they exist after a catch
|
| 23 |
-
// Since we don't have full AST context, we replace (e instanceof Error ? (e instanceof Error ? e.message : String(e)) : String(e)) where 'e' matches the catch variable
|
| 24 |
-
// This simple regex replaces generic .message calls with proper type checking.
|
| 25 |
-
// It's a bit naive but works for standard setups. We'll specifically target common variable names:
|
| 26 |
-
const errorVars = ['e', 'err', 'error'];
|
| 27 |
-
for (const v of errorVars) {
|
| 28 |
-
// (e instanceof Error ? (e instanceof Error ? e.message : String(e)) : String(e)) -> (e instanceof Error ? (e instanceof Error ? (e instanceof Error ? e.message : String(e)) : String(e)) : String(e))
|
| 29 |
-
const regex = new RegExp(`\\b${v}\\.message\\b`, 'g');
|
| 30 |
-
content = content.replace(regex, `(${v} instanceof Error ? ${v}.message : String(${v}))`);
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
// 3. Remove "as any" assertions in specific safe contexts if requested,
|
| 34 |
-
// but the prompt only asked for catch blocks and webhooks specifically.
|
| 35 |
-
// Let's leave "as any" broadly for now and focus on catch blocks as requested.
|
| 36 |
-
|
| 37 |
-
if (content !== original) {
|
| 38 |
-
fs.writeFileSync(filePath, content, 'utf-8');
|
| 39 |
-
console.log(`Updated: ${filePath}`);
|
| 40 |
-
}
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
const targetDirs = [
|
| 44 |
-
path.resolve(__dirname, '..'), // /Volumes/sms/edtech/apps/api/src
|
| 45 |
-
path.resolve(__dirname, '../../../whatsapp-worker/src')
|
| 46 |
-
];
|
| 47 |
-
|
| 48 |
-
targetDirs.forEach(dir => processDirectory(dir));
|
| 49 |
-
console.log('Purge any in catch blocks completed!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
packages/database/sync-days.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
| 1 |
-
import { PrismaClient } from '@prisma/client';
|
| 2 |
-
|
| 3 |
-
const prisma = new PrismaClient();
|
| 4 |
-
|
| 5 |
-
async function syncDays() {
|
| 6 |
-
console.log('🔄 Démarrage de la synchronisation des jours (UserProgress -> Enrollment)...');
|
| 7 |
-
|
| 8 |
-
const enrollments = await prisma.enrollment.findMany({
|
| 9 |
-
where: { status: 'ACTIVE' },
|
| 10 |
-
include: { user: { include: { progress: true } } }
|
| 11 |
-
});
|
| 12 |
-
|
| 13 |
-
let updatedCount = 0;
|
| 14 |
-
|
| 15 |
-
for (const enrollment of enrollments) {
|
| 16 |
-
// Find the corresponding UserProgress for this active track
|
| 17 |
-
const progress = enrollment.user.progress.find(p => p.trackId === enrollment.trackId);
|
| 18 |
-
|
| 19 |
-
if (progress) {
|
| 20 |
-
// If UserProgress has a higher internal currentDay than Enrollment,
|
| 21 |
-
// the scheduler bug affected this user. We need to align Enrollment.
|
| 22 |
-
// (Note: Since we haven't removed currentDay from UserProgress yet, we can access it via 'any')
|
| 23 |
-
const progressAny = progress as any;
|
| 24 |
-
if (progressAny.currentDay && progressAny.currentDay > enrollment.currentDay) {
|
| 25 |
-
console.log(`➡️ Mise à jour: User ${enrollment.userId} Track ${enrollment.trackId}: Jour ${enrollment.currentDay} -> ${progressAny.currentDay}`);
|
| 26 |
-
|
| 27 |
-
await prisma.enrollment.update({
|
| 28 |
-
where: { id: enrollment.id },
|
| 29 |
-
data: { currentDay: progressAny.currentDay }
|
| 30 |
-
});
|
| 31 |
-
updatedCount++;
|
| 32 |
-
}
|
| 33 |
-
}
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
console.log(`✅ Synchronisation terminée. ${updatedCount} inscriptions synchronisées.`);
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
syncDays()
|
| 40 |
-
.catch(console.error)
|
| 41 |
-
.finally(() => prisma.$disconnect());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|