Files
filezzy-staging/backend/scripts/check-tool-access.ts
2026-02-04 14:16:04 +01:00

66 lines
2.2 KiB
TypeScript

/**
* Check (and optionally fix) tool accessLevel in DB.
* Run from backend:
* npx ts-node scripts/check-tool-access.ts — list all tools with slug, accessLevel
* npx ts-node scripts/check-tool-access.ts batch-pdf-add-stamp — show one tool
* npx ts-node scripts/check-tool-access.ts --fix-batch-free — set all batch* tools to accessLevel FREE
*/
import { PrismaClient, AccessLevel } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
const args = process.argv.slice(2);
const fixBatchFree = args.includes('--fix-batch-free');
const slugArg = args.find((a) => !a.startsWith('--'));
if (fixBatchFree) {
const result = await prisma.tool.updateMany({
where: { slug: { startsWith: 'batch-' } },
data: { accessLevel: AccessLevel.FREE },
});
console.log(`\n✅ Updated ${result.count} batch tools to accessLevel=FREE.\n`);
await prisma.$disconnect();
return;
}
const tools = slugArg
? await prisma.tool.findMany({
where: { slug: slugArg },
select: { slug: true, accessLevel: true, name: true, isActive: true },
})
: await prisma.tool.findMany({
select: { slug: true, accessLevel: true, name: true, isActive: true },
orderBy: [{ category: 'asc' }, { slug: 'asc' }],
});
if (tools.length === 0) {
console.log(slugArg ? `\nNo tool found with slug: ${slugArg}\n` : '\nNo tools in DB.\n');
await prisma.$disconnect();
return;
}
console.log('\n📋 Tool(s) in DB (slug, accessLevel)\n');
console.log('slug'.padEnd(42) + 'accessLevel'.padEnd(14) + 'name');
console.log('-'.repeat(42) + '-' + '-'.repeat(13) + '-' + '-'.repeat(30));
for (const t of tools) {
const name = (t.name ?? '').slice(0, 28);
console.log(
(t.slug ?? '').padEnd(42) +
(t.accessLevel ?? '').padEnd(14) +
name
);
}
console.log('\nBackend enforces accessLevel (GUEST/FREE/PREMIUM). Frontend badge should use accessLevel.\n');
if (!slugArg) {
console.log('To fix: npx ts-node scripts/check-tool-access.ts --fix-batch-free (sets all batch-* to FREE)\n');
}
await prisma.$disconnect();
}
main().catch((e) => {
console.error(e);
process.exit(1);
});