forked from CSI-KJSCE/Travel-policy-
Add Dark Mode, Password Hashing for better security , Settings Page, Policy PDF in Policy section,UI Changes
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// Generator to create Prisma Client
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
binaryTargets = ["native", "darwin-arm64", "linux-musl-arm64-openssl-3.0.x"]
|
||||
@@ -40,7 +39,7 @@ enum Designation {
|
||||
model User {
|
||||
profileId String @id @default(uuid())
|
||||
userName String
|
||||
email String @unique @db.Text
|
||||
email String @unique
|
||||
password String
|
||||
|
||||
institute Institute?
|
||||
@@ -54,9 +53,9 @@ model User {
|
||||
}
|
||||
|
||||
model Application {
|
||||
applicationId String @id @default(uuid())
|
||||
applicationId String @id @default(uuid())
|
||||
applicantId String
|
||||
applicant User @relation("AppliedApplications", fields: [applicantId], references: [profileId])
|
||||
applicant User @relation("AppliedApplications", fields: [applicantId], references: [profileId])
|
||||
institute Institute
|
||||
department String
|
||||
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import prisma from "../src/config/prismaConfig.js";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import bcrypt from "bcryptjs";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
// Common password for all users
|
||||
// Use a common password for all development users to make testing easier
|
||||
const commonPassword = "securePassword123";
|
||||
|
||||
// Applicant and Validator data
|
||||
// Secure the password with hashing even for seed data!
|
||||
const salt = await bcrypt.genSalt(10);
|
||||
const hashedPassword = await bcrypt.hash(commonPassword, salt);
|
||||
|
||||
const institutes = [
|
||||
"KJSIDS",
|
||||
"SKSC",
|
||||
@@ -28,96 +34,116 @@ async function main() {
|
||||
"Library",
|
||||
];
|
||||
|
||||
// Create VC (single, no department or institute)
|
||||
console.log("Seeding VC...");
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
userName: "Validator_VC",
|
||||
email: "vc@example.com",
|
||||
password: commonPassword,
|
||||
console.log("Seeding started...");
|
||||
|
||||
// VC is usually global
|
||||
// We use 'upsert' here. It means "Update if exists, Insert if not".
|
||||
// This prevents errors if we run the seed script multiple times.
|
||||
await prisma.user.upsert({
|
||||
where: { email: "vc@somaiya.edu" },
|
||||
update: {},
|
||||
create: {
|
||||
userName: "Vice Chancellor",
|
||||
email: "vc@somaiya.edu",
|
||||
password: hashedPassword,
|
||||
institute: "KJSCE",
|
||||
department: "Management",
|
||||
designation: "VC",
|
||||
},
|
||||
});
|
||||
|
||||
for (const institute of institutes) {
|
||||
// Create HOI for each institute
|
||||
// 1. Create HOI for this institute
|
||||
console.log(`Seeding HOI for ${institute}...`);
|
||||
const hoiEmail = `hoi.${institute.toLowerCase()}@example.com`;
|
||||
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
const hoiEmail = `hoi@${institute.toLowerCase()}.edu`;
|
||||
await prisma.user.upsert({
|
||||
where: { email: hoiEmail },
|
||||
update: {},
|
||||
create: {
|
||||
userName: `HOI_${institute}`,
|
||||
email: hoiEmail,
|
||||
password: commonPassword,
|
||||
password: hashedPassword,
|
||||
institute,
|
||||
department: "Administration",
|
||||
designation: "HOI",
|
||||
},
|
||||
});
|
||||
|
||||
// Create Accounts for each institute
|
||||
// 2. Create Accounts for this institute
|
||||
console.log(`Seeding Accounts for ${institute}...`);
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
const accountsEmail = `accounts.${institute.toLowerCase()}@example.com`;
|
||||
await prisma.user.upsert({
|
||||
where: { email: accountsEmail },
|
||||
update: {},
|
||||
create: {
|
||||
userName: `Validator_Accounts_${institute}`,
|
||||
email: `accounts.${institute.toLowerCase()}@example.com`,
|
||||
password: commonPassword,
|
||||
email: accountsEmail,
|
||||
password: hashedPassword,
|
||||
institute,
|
||||
designation: "ACCOUNTS",
|
||||
},
|
||||
});
|
||||
|
||||
for (const department of departments) {
|
||||
// Create HOD for each department of each institute
|
||||
// 3. Create HOD for each department of each institute
|
||||
console.log(`Seeding HOD for ${department} in ${institute}...`);
|
||||
const hodEmail = `hod.${department.toLowerCase()}.${institute.toLowerCase()}@example.com`;
|
||||
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
await prisma.user.upsert({
|
||||
where: { email: hodEmail },
|
||||
update: {},
|
||||
create: {
|
||||
userName: `HOD_${department}_${institute}`,
|
||||
email: hodEmail,
|
||||
password: commonPassword,
|
||||
password: hashedPassword,
|
||||
institute,
|
||||
department,
|
||||
designation: "HOD",
|
||||
},
|
||||
});
|
||||
|
||||
// Create Faculty for each department of each institute
|
||||
// 4. Create Faculty for each department of each institute
|
||||
console.log(`Seeding Faculty for ${department} in ${institute}...`);
|
||||
const facultyEmail = `faculty.${department.toLowerCase()}.${institute.toLowerCase()}@example.com`;
|
||||
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
await prisma.user.upsert({
|
||||
where: { email: facultyEmail },
|
||||
update: {},
|
||||
create: {
|
||||
userName: `Faculty_${department}_${institute}`,
|
||||
email: facultyEmail,
|
||||
password: commonPassword,
|
||||
password: hashedPassword,
|
||||
institute,
|
||||
department,
|
||||
designation: "FACULTY",
|
||||
},
|
||||
});
|
||||
// Create Student for each department of each institute
|
||||
|
||||
// 5. Create Student for each department of each institute
|
||||
console.log(`Seeding Student for ${department} in ${institute}...`);
|
||||
const studentEmail = `student.${department.toLowerCase()}.${institute.toLowerCase()}@example.com`;
|
||||
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
await prisma.user.upsert({
|
||||
where: { email: studentEmail },
|
||||
update: {},
|
||||
create: {
|
||||
userName: `Student_${department}_${institute}`,
|
||||
email: studentEmail,
|
||||
password: commonPassword,
|
||||
password: hashedPassword,
|
||||
institute,
|
||||
department,
|
||||
designation: "STUDENT",
|
||||
},
|
||||
});
|
||||
}
|
||||
console.log("Seeding completed!");
|
||||
}
|
||||
|
||||
console.log("Seeding completed successfully.");
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}).finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
main()
|
||||
.then(async () => {
|
||||
await prisma.$disconnect();
|
||||
})
|
||||
.catch(async (e) => {
|
||||
console.error(e);
|
||||
await prisma.$disconnect();
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user