Admin panel: real data - backend API, users/audit/roles/stats, frontend wired
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
41
backend/scripts/add-admin-permission.ts
Normal file
41
backend/scripts/add-admin-permission.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Add admin permission for GM position.
|
||||
* Run this for existing databases where seed was run before admin module existed:
|
||||
* npx ts-node scripts/add-admin-permission.ts
|
||||
*/
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
const gmPosition = await prisma.position.findFirst({ where: { code: 'GM' } });
|
||||
if (!gmPosition) {
|
||||
console.log('GM position not found. Run full seed first.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const existing = await prisma.positionPermission.findFirst({
|
||||
where: { positionId: gmPosition.id, module: 'admin' },
|
||||
});
|
||||
if (existing) {
|
||||
console.log('Admin permission already exists for GM.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
await prisma.positionPermission.create({
|
||||
data: {
|
||||
positionId: gmPosition.id,
|
||||
module: 'admin',
|
||||
resource: '*',
|
||||
actions: ['*'],
|
||||
},
|
||||
});
|
||||
console.log('Admin permission added for GM position.');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(() => prisma.$disconnect());
|
||||
Reference in New Issue
Block a user