Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions apps/core-api/src/controllers/admin.controllers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Request, Response, NextFunction } from "express";
import type { Request, Response, NextFunction } from "express";

import { approveSignupService, rejectSignupService } from "../services/verification.service.js";
import { approveSignupService, getAllPendingSignupService, rejectSignupService } from "../services/verification.service.js";

export const approveSignupController = async (
req: Request,
Expand Down Expand Up @@ -33,3 +33,16 @@ export const rejectSignupController = async (
next(error);
}
};

export const getAllpendingSignupController = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const requests = await getAllPendingSignupService(req.query);
res.status(200).json({ success: true, data: requests });
} catch (error) {
next(error);
}
};
1 change: 1 addition & 0 deletions apps/core-api/src/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const signupController = async (
next: NextFunction
) => {
try {

const { email, password, role, documents: businessInfo } = req.body;

if (!email || !password || !role) {
Expand Down
33 changes: 19 additions & 14 deletions apps/core-api/src/models/pendingSignup.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@ import { Schema, model } from "mongoose";

const PendingSignupSchema = new Schema(
{
email: {
type: String,
required: true,
unique: true
email: {
type: String,
required: true,
unique: true
},

passwordHash: {
type: String,
required: true
passwordHash: {
type: String,
required: true
},

role: {
type: String,
enum: ["INFLUENCER", "BRAND"],
enum: ["INFLUENCER", "BRAND", "ADMIN"],
required: true,
},
adminLevel: {
type: String,
enum: ["SUPER", "NORMAL"],
default: null,
},
documents: { type: String },


Expand All @@ -29,12 +34,12 @@ const PendingSignupSchema = new Schema(

// OTP FIELDS START HERE

emailOtpHash: {
type: String,
select: false,
default: null,
emailOtpHash: {
type: String,
select: false,
default: null,

},
},


emailOtpExpiresAt: {
Expand All @@ -59,7 +64,7 @@ const PendingSignupSchema = new Schema(

otpLockedUntil: {
type: Date,
default: null,
default: null,
},

isEmailVerified: {
Expand Down
28 changes: 18 additions & 10 deletions apps/core-api/src/repositories/Signup.repository.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { PendingSignup } from "../models/pendingSignup.models.js";

import type { PendingSignupFilter } from "../types/pendingSignup.types.js";

interface CreatePendingSignupInput {
email: string;
passwordHash: string;
documents: string;
role: "INFLUENCER" | "BRAND";
role: "INFLUENCER" | "BRAND" | "ADMIN";
adminLevel?: "SUPER" | "NORMAL";

status: "PENDING" | "APPROVED" | "REJECTED";

Expand All @@ -19,18 +20,25 @@ interface CreatePendingSignupInput {
isEmailVerified?: boolean;
}



class PendingSignupRepository {
// ================= CREATE =================
create(data: CreatePendingSignupInput) {
return PendingSignup.create(data);
}

//==================GET ALL PENDING SIGNUPS==================
getAllPendingSignups(filter:PendingSignupFilter={}) {
return PendingSignup.find(filter).sort({ createdAt: -1 });
}

// ================= FIND =================
findByEmail(email: string) {
return PendingSignup
.findOne({ email })
.select("+emailOtpHash");
}
findByEmail(email: string) {
return PendingSignup
.findOne({ email })
.select("+emailOtpHash");
}


// ================= UPDATE STATUS =================
Expand All @@ -48,9 +56,9 @@ class PendingSignupRepository {
}

// ================= DELETE MANY (FOR CLEANUP) =================
deleteMany(filter: Record<string, unknown>): Promise<unknown> {
return PendingSignup.deleteMany(filter);
}
deleteMany(filter: Record<string, unknown>): Promise<unknown> {
return PendingSignup.deleteMany(filter);
}

}

Expand Down
41 changes: 21 additions & 20 deletions apps/core-api/src/repositories/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,53 @@ import { User } from "../models/user.model.js";

class UserRepository {


// FIND USER WITH PASSWORD

async findEmailWithPassword(email: string) {
const normalizedEmail = email.trim().toLowerCase();
return User.findOne({ email: normalizedEmail }).select("+password");
}


// FIND USER WITH RESET FIELDS

async findByEmailWithResetFields(email: string) {
const normalizedEmail = email.trim().toLowerCase();

return User.findOne({ email: normalizedEmail })
.select("+password +resetOtp +resetOtpExpiry +resetSessionExpiry +resetSessionToken");
}


// NORMAL FIND BY EMAIL

async findByEmail(email: string) {
const normalizedEmail = email.trim().toLowerCase();
return User.findOne({ email: normalizedEmail });
}

// FIND BY ID

async findById(userId: string) {
return User.findById(userId).select("+refreshToken");
}


// SAVE REFRESH TOKEN

async saveRefreshToken(userId: string, refreshToken: string) {

return User.findByIdAndUpdate(
userId,
{ refreshToken },
{ new: true }
);
}


// SAVE RESET OTP

async saveResetOtp(
userId: string,
hashedOtp: string,
Expand All @@ -64,9 +64,9 @@ class UserRepository {
);
}


// SAVE RESET SESSION TOKEN

async saveResetSession(
userId: string,
token: string,
Expand All @@ -82,9 +82,9 @@ class UserRepository {
);
}


// UPDATE PASSWORD (Production-Safe)

async updatePassword(userId: string, hashedPassword: string) {
return User.findByIdAndUpdate(
userId,
Expand All @@ -99,9 +99,9 @@ class UserRepository {
);
}


// CLEAR RESET SESSION

async clearResetSession(userId: string) {
return User.findByIdAndUpdate(
userId,
Expand All @@ -112,13 +112,14 @@ class UserRepository {
);
}


// CREATE USER

async create(data: {
email: string;
password: string;
role: string;
adminLevel?: string;
isEmailVerified: boolean;
status: string;
}) {
Expand Down
9 changes: 6 additions & 3 deletions apps/core-api/src/routes/admin.route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Router } from "express";
import { Router } from "express";

import { authenticate } from "../middlewares/auth.middleware.js";
import { approveSignupController, rejectSignupController } from "../controllers/admin.controllers.js";
import { approveSignupController, getAllpendingSignupController, rejectSignupController } from "../controllers/admin.controllers.js";

const router: Router = Router();

router.post("/signup/approve", authenticate, approveSignupController);
router.get("/signup/", authenticate, getAllpendingSignupController);
router.post("/signup/approve",
// authenticate,
approveSignupController);
router.post("/signup/reject", authenticate, rejectSignupController);

export default router;
Loading
Loading