Initial commit: Mana Collection NestJS backend.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-09-07 20:49:55 +03:30
co-authored by Cursor
commit fe78a99b78
87 changed files with 10557 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
/**
* Create the first SUPER_ADMIN.
*
* Usage:
* npx ts-node -r tsconfig-paths/register scripts/create-super-admin.ts \
* --phone 09127004945 --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', 'حسنی');
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: {
firstName,
lastName,
cellNumber,
passwordHash,
role: UserRole.SUPER_ADMIN,
},
});
console.log('Created SUPER_ADMIN:', {
id: user.id,
cellNumber: user.cellNumber,
name: `${user.firstName} ${user.lastName}`,
});
}
main()
.catch((err) => {
console.error(err.message || err);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
+114
View File
@@ -0,0 +1,114 @@
/**
* Seed Mana Collection flagship store + STORE_ADMIN (and optional SUPER_ADMIN).
*
* Usage:
* npm run seed:mana-store -- \
* --phone 09120000000 --password secret123 \
* --first مانا --last ادمین \
* [--super-phone 09127004945 --super-password secret123]
*/
import { PrismaClient, StoreStatus, UserRole } from '@prisma/client';
import * as bcrypt from 'bcrypt';
const prisma = new PrismaClient();
function arg(name: string, fallback?: string): string | undefined {
const idx = process.argv.indexOf(`--${name}`);
if (idx >= 0 && process.argv[idx + 1]) return process.argv[idx + 1];
return fallback;
}
async function main() {
const cellNumber = arg('phone', '09120000000')!;
const password = arg('password', 'mana1234')!;
const firstName = arg('first', 'مانا')!;
const lastName = arg('last', 'ادمین')!;
const superPhone = arg('super-phone');
const superPassword = arg('super-password', 'admin1234');
if (!/^09\d{9}$/.test(cellNumber)) {
throw new Error('phone must match 09xxxxxxxxx');
}
const passwordHash = await bcrypt.hash(password, 10);
const storeAdmin = await prisma.user.upsert({
where: { cellNumber },
update: {
firstName,
lastName,
passwordHash,
role: UserRole.STORE_ADMIN,
disabled: false,
},
create: {
firstName,
lastName,
cellNumber,
passwordHash,
role: UserRole.STORE_ADMIN,
},
});
const store = await prisma.store.upsert({
where: { slug: 'mana-collection' },
update: {
nameFa: 'مانا کالکشن',
nameEn: 'Mana Collection',
status: StoreStatus.active,
ownerId: storeAdmin.id,
rejectionReason: null,
},
create: {
slug: 'mana-collection',
nameFa: 'مانا کالکشن',
nameEn: 'Mana Collection',
description: 'فروشگاه اصلی مانا کالکشن',
status: StoreStatus.active,
ownerId: storeAdmin.id,
},
});
console.log('Seeded STORE_ADMIN + store:', {
userId: storeAdmin.id,
cellNumber: storeAdmin.cellNumber,
storeId: store.id,
slug: store.slug,
status: store.status,
});
if (superPhone) {
if (!/^09\d{9}$/.test(superPhone)) {
throw new Error('super-phone must match 09xxxxxxxxx');
}
const superHash = await bcrypt.hash(superPassword!, 10);
const superAdmin = await prisma.user.upsert({
where: { cellNumber: superPhone },
update: {
role: UserRole.SUPER_ADMIN,
passwordHash: superHash,
disabled: false,
},
create: {
firstName: 'سوپر',
lastName: 'ادمین',
cellNumber: superPhone,
passwordHash: superHash,
role: UserRole.SUPER_ADMIN,
},
});
console.log('Seeded SUPER_ADMIN:', {
id: superAdmin.id,
cellNumber: superAdmin.cellNumber,
});
}
}
main()
.catch((err) => {
console.error(err.message || err);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
+53
View File
@@ -0,0 +1,53 @@
/**
* Send an SMS via Meshkee (backend-only; never call from frontend).
*
* Usage:
* npm run send-sms -- --to 09127004945 --message "متن پیام"
*/
import { config as loadEnv } from 'dotenv';
import { resolve } from 'path';
loadEnv({ path: resolve(__dirname, '../.env') });
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 to = arg('to');
const message = arg('message');
const apiUrl =
process.env.MESHKEE_SMS_URL ??
'https://api.meshkee.com/api/v1/public/sms/send';
const apiKey = process.env.MESHKEE_SMS_API_KEY;
const domain = process.env.MESHKEE_SMS_DOMAIN ?? 'manacollections.ir';
if (!apiKey) throw new Error('MESHKEE_SMS_API_KEY is not set in .env');
if (!/^09\d{9}$/.test(to)) throw new Error('to must match 09xxxxxxxxx');
if (!message.trim()) throw new Error('message is empty');
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Api-Key': apiKey,
},
body: JSON.stringify({ domain, to, message }),
});
const body = await response.json().catch(() => null);
if (!response.ok || !body?.success) {
console.error('SMS send failed', { status: response.status, body });
process.exit(1);
}
console.log('SMS sent', { to, serverId: body.serverId });
}
main().catch((err) => {
console.error(err);
process.exit(1);
});