Initial commit of Balout Pastry NestJS API.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-08-02 17:21:34 +03:30
co-authored by Cursor
commit f40075fd5e
84 changed files with 15435 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
/**
* Create the first superAdmin (no seed data).
*
* Usage:
* npx ts-node -r tsconfig-paths/register scripts/create-super-admin.ts \
* --phone 09120000000 --password secret123 --first علی --last رضایی
*/
import { PrismaClient, UserRole } from '@prisma/client';
import * as bcrypt from 'bcrypt';
const prisma = new PrismaClient();
function arg(name: string, fallback?: string): string {
const idx = process.argv.indexOf(`--${name}`);
if (idx >= 0 && process.argv[idx + 1]) return process.argv[idx + 1];
if (fallback !== undefined) return fallback;
throw new Error(`Missing --${name}`);
}
async function main() {
const cellNumber = arg('phone');
const password = arg('password');
const firstName = arg('first', 'مدیر');
const lastName = arg('last', 'بلوط');
const title = arg('title', 'جناب آقای');
if (!/^09\d{9}$/.test(cellNumber)) {
throw new Error('phone must match 09xxxxxxxxx');
}
if (password.length < 4) {
throw new Error('password min length 4');
}
const existing = await prisma.user.findUnique({ where: { cellNumber } });
if (existing) {
throw new Error(`User already exists: ${cellNumber}`);
}
const passwordHash = await bcrypt.hash(password, 10);
const user = await prisma.user.create({
data: {
title,
firstName,
lastName,
cellNumber,
passwordHash,
role: UserRole.superAdmin,
},
});
console.log('Created superAdmin:', {
id: user.id,
cellNumber: user.cellNumber,
name: `${user.title} ${user.firstName} ${user.lastName}`,
});
}
main()
.catch((err) => {
console.error(err.message || err);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});